jscarle / OnePassword.NET

A 1Password CLI Wrapper for .NET.
https://jscarle.github.io/OnePassword.NET/
MIT License
23 stars 8 forks source link

Support for document API? #41

Closed VictorioBerra closed 1 year ago

VictorioBerra commented 1 year ago

https://developer.1password.com/docs/cli/reference/management-commands/document

Does this package support the above CLI subcommand for documents?

jscarle commented 1 year ago

No at the moment. Shouldn't be too much effort to add support for it.

VictorioBerra commented 1 year ago

Looking at maybe contributing, when I try and build I get tons of Code Analysis errors, do you have your settings in VS different than I do?

image

VS 2019, 17.6.5, mostly default settings.

jscarle commented 1 year ago

Maybe that they've added new Roslyn analyzers since the last build.

jscarle commented 1 year ago

You can try lowering the analysis level in the csproj: https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#analysislevel

VictorioBerra commented 1 year ago

Setting <CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors> in Build.props let the project compile.

Toggling the various analysislevels had no effect.

VictorioBerra commented 1 year ago

Started work in this branch:

https://github.com/VictorioBerra/OnePassword.NET/tree/VictorioBerra/feat/documents

Just got the op.exe document list command working, not much work done on tests yet or other commands.

Some sample output I am working from is here:

PS C:\Program Files\1Password CLI> .\op.exe document create "C:\Users\me\Downloads\HelloWorld.txt" --vault OnePasswordNET --title Test1  --format json
{
    "uuid":"ABCD123",
    "createdAt":"2023-08-05T13:21:37.7611269-05:00",
    "updatedAt":"2023-08-05T13:21:37.7611269-05:00",
    "vaultUuid":"ikfkfwx2efxsdkqvcwiz666mgi"
}

PS C:\Program Files\1Password CLI> ./op.exe document list --vault OnePasswordNET --format json
[
  {
    "id": "ABCD123",
    "title": "Test1",
    "version": 1,
    "vault": {
      "id": "ikfkfwx2efxsdkqvcwiz666mgi",
      "name": ""
    },
    "last_edited_by": "ABCD123",
    "created_at": "2023-08-05T18:21:38Z",
    "updated_at": "2023-08-05T18:21:38Z"
  }
]

./op.exe document get Test1 --vault OnePasswordNET --format json
No output

.\op.exe document edit Test1 "C:\Users\me\Downloads\HelloWorld.txt" --vault OnePasswordNET --title Test2  --format json
No output

./op.exe document delete Test1 --vault OnePasswordNET  --format json
No output

Some things to note, creating a document returns a smaller JSON object where id is called uuid, and created_at is instead createdAt so making use of a base class becomes a lot harder. Do I need to worry about that with ResultBase<TInterface>? That only has id.

VictorioBerra commented 1 year ago

All command complete. https://github.com/VictorioBerra/OnePassword.NET/blob/VictorioBerra/feat/documents/OnePassword.NET/OnePasswordManager.Documents.cs

I just need help with the tests now. When I run them, they all say skipped...

jscarle commented 1 year ago

You have to set the environment variables for the tests: https://github.com/jscarle/OnePassword.NET#running-tests

jscarle commented 1 year ago

I'll take a closer look when I'm in the office on Monday.

VictorioBerra commented 1 year ago

Ah the testing stuff is all at the bottom of the README my bad.

VictorioBerra commented 1 year ago

PR ready for initial review 🎉

VictorioBerra commented 1 year ago

@jscarle Have you had a chance to peek at this yet?

jscarle commented 1 year ago

I took a look at the PR, I'll need to do a refactor of certain parts. I understand the challenge that the 1Password team decided to be inconsistent in their property names, so I'll have to work around that. The main issue is that the API should be consistent, and in there is a different in the way that documents and items are managed. So I'll want to rework it a bit to make it consistent. Also, I'm not sure why there's a DocumentVault class...

VictorioBerra commented 1 year ago

@jscarle Please re-work as needed. This should get you started.

There is a DocumentVault object due to this nested object:

PS C:\Program Files\1Password CLI> ./op.exe document list --vault OnePasswordNET --format json

[
  {
    "id": "ABCD123",
    "title": "Test1",
    "version": 1,
    "vault": { // <--------------------------------------- Document vault object
      "id": "ikfkfwx2efxsdkqvcwiz666mgi",
      "name": ""
    },
    "last_edited_by": "ABCD123",
    "created_at": "2023-08-05T18:21:38Z",
    "updated_at": "2023-08-05T18:21:38Z"
  }
]

You can see above that listing documents will return an object with a nested Vault object.

VictorioBerra commented 1 year ago

@jscarle Is there anything I can do to help nudge this along?

jscarle commented 1 year ago

I finally had the time to work through it, it's been merged with some changes.

VictorioBerra commented 1 year ago

Thank you!