-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add local 1Password shell plugin support #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| *.exe | ||
| *.test | ||
| *.out | ||
| contrib/1password-plugin/1password-plugin | ||
|
|
||
| # Build artifacts | ||
| dist/ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "github.com/1Password/shell-plugins/sdk" | ||
| "github.com/1Password/shell-plugins/sdk/importer" | ||
| "github.com/1Password/shell-plugins/sdk/provision" | ||
| "github.com/1Password/shell-plugins/sdk/schema" | ||
| "github.com/1Password/shell-plugins/sdk/schema/credname" | ||
| ) | ||
|
|
||
| const ( | ||
| fieldToken = sdk.FieldName("Token") | ||
| fieldGraph = sdk.FieldName("Graph") | ||
| fieldAPIURL = sdk.FieldName("API URL") | ||
| fieldTimeoutSeconds = sdk.FieldName("Timeout Seconds") | ||
| ) | ||
|
|
||
| var envVarMapping = map[string]sdk.FieldName{ | ||
| "ROAM_API_TOKEN": fieldToken, | ||
| "ROAM_API_GRAPH": fieldGraph, | ||
| "ROAM_API_BASE_URL": fieldAPIURL, | ||
| "ROAM_TIMEOUT_SECONDS": fieldTimeoutSeconds, | ||
| } | ||
|
|
||
| // APIToken returns the credential type for Roam Research API Token. | ||
| func APIToken() schema.CredentialType { | ||
| return schema.CredentialType{ | ||
| Name: credname.APIToken, | ||
| DocsURL: sdk.URL("https://github.com/Leechael/roam-cli"), | ||
| ManagementURL: sdk.URL("https://roamresearch.com/#/app/roam-cli-settings"), | ||
|
|
||
| Fields: []schema.CredentialField{ | ||
| { | ||
| Name: fieldToken, | ||
| MarkdownDescription: "Roam Research API token used to authenticate requests.", | ||
| Secret: true, | ||
| }, | ||
| { | ||
| Name: fieldGraph, | ||
| MarkdownDescription: "Roam Research graph name.", | ||
| Secret: false, | ||
| }, | ||
| { | ||
| Name: fieldAPIURL, | ||
| MarkdownDescription: "Optional custom API base URL.", | ||
| Secret: false, | ||
| Optional: true, | ||
| }, | ||
| { | ||
| Name: fieldTimeoutSeconds, | ||
| MarkdownDescription: "Optional request timeout in seconds.", | ||
| Secret: false, | ||
| Optional: true, | ||
| }, | ||
| }, | ||
|
|
||
| DefaultProvisioner: provision.EnvVars(envVarMapping), | ||
|
|
||
| Importer: importer.TryEnvVarPair(envVarMapping), | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/1Password/shell-plugins/sdk" | ||
| ) | ||
|
|
||
| func TestCredentialTypeName(t *testing.T) { | ||
| ct := APIToken() | ||
| if string(ct.Name) != "API Token" { | ||
| t.Errorf("expected %q, got %q", "API Token", ct.Name) | ||
| } | ||
| } | ||
|
|
||
| func TestCredentialFields(t *testing.T) { | ||
| ct := APIToken() | ||
|
|
||
| if len(ct.Fields) != 4 { | ||
| t.Fatalf("expected 4 fields, got %d", len(ct.Fields)) | ||
| } | ||
|
|
||
| tests := []struct { | ||
| name sdk.FieldName | ||
| secret bool | ||
| optional bool | ||
| }{ | ||
| {fieldToken, true, false}, | ||
| {fieldGraph, false, false}, | ||
| {fieldAPIURL, false, true}, | ||
| {fieldTimeoutSeconds, false, true}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| found := false | ||
| for _, f := range ct.Fields { | ||
| if f.Name == tt.name { | ||
| found = true | ||
| if f.Secret != tt.secret { | ||
| t.Errorf("field %q: secret = %v, want %v", tt.name, f.Secret, tt.secret) | ||
| } | ||
| if f.Optional != tt.optional { | ||
| t.Errorf("field %q: optional = %v, want %v", tt.name, f.Optional, tt.optional) | ||
| } | ||
| break | ||
| } | ||
| } | ||
| if !found { | ||
| t.Errorf("field %q not found", tt.name) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestDefaultProvisionerProducesEnvVars(t *testing.T) { | ||
| ct := APIToken() | ||
|
|
||
| if ct.DefaultProvisioner == nil { | ||
| t.Fatal("DefaultProvisioner is nil") | ||
| } | ||
|
|
||
| in := sdk.ProvisionInput{ | ||
| ItemFields: map[sdk.FieldName]string{ | ||
| fieldToken: "tok_abc", | ||
| fieldGraph: "my-graph", | ||
| fieldAPIURL: "https://custom.api/graph", | ||
| fieldTimeoutSeconds: "15", | ||
| }, | ||
| } | ||
|
|
||
| out := sdk.ProvisionOutput{Environment: make(map[string]string)} | ||
| ct.DefaultProvisioner.Provision(context.Background(), in, &out) | ||
|
|
||
| env := out.Environment | ||
| if env["ROAM_API_TOKEN"] != "tok_abc" { | ||
| t.Errorf("ROAM_API_TOKEN = %q, want %q", env["ROAM_API_TOKEN"], "tok_abc") | ||
| } | ||
| if env["ROAM_API_GRAPH"] != "my-graph" { | ||
| t.Errorf("ROAM_API_GRAPH = %q, want %q", env["ROAM_API_GRAPH"], "my-graph") | ||
| } | ||
| if env["ROAM_API_BASE_URL"] != "https://custom.api/graph" { | ||
| t.Errorf("ROAM_API_BASE_URL = %q, want %q", env["ROAM_API_BASE_URL"], "https://custom.api/graph") | ||
| } | ||
| if env["ROAM_TIMEOUT_SECONDS"] != "15" { | ||
| t.Errorf("ROAM_TIMEOUT_SECONDS = %q, want %q", env["ROAM_TIMEOUT_SECONDS"], "15") | ||
| } | ||
| } | ||
|
|
||
| func TestDefaultProvisionerIsEnvVars(t *testing.T) { | ||
| ct := APIToken() | ||
| if ct.DefaultProvisioner == nil { | ||
| t.Fatal("DefaultProvisioner is nil") | ||
| } | ||
| desc := ct.DefaultProvisioner.Description() | ||
| if desc == "" { | ||
| t.Error("DefaultProvisioner description is empty") | ||
| } | ||
| } | ||
|
|
||
| func TestImporterImportsEnvVars(t *testing.T) { | ||
| ct := APIToken() | ||
|
|
||
| t.Setenv("ROAM_API_TOKEN", "tok_imported") | ||
| t.Setenv("ROAM_API_GRAPH", "imported-graph") | ||
| t.Setenv("ROAM_API_BASE_URL", "https://imported.api/graph") | ||
| t.Setenv("ROAM_TIMEOUT_SECONDS", "42") | ||
|
|
||
| out := sdk.ImportOutput{} | ||
| ct.Importer(context.Background(), sdk.ImportInput{}, &out) | ||
|
|
||
| candidates := out.AllCandidates() | ||
| if len(candidates) == 0 { | ||
| t.Fatal("expected at least 1 import candidate") | ||
| } | ||
|
|
||
| cand := candidates[0] | ||
| if cand.Fields[fieldToken] != "tok_imported" { | ||
| t.Errorf("Token = %q, want %q", cand.Fields[fieldToken], "tok_imported") | ||
| } | ||
| if cand.Fields[fieldGraph] != "imported-graph" { | ||
| t.Errorf("Graph = %q, want %q", cand.Fields[fieldGraph], "imported-graph") | ||
| } | ||
| if cand.Fields[fieldAPIURL] != "https://imported.api/graph" { | ||
| t.Errorf("API URL = %q, want %q", cand.Fields[fieldAPIURL], "https://imported.api/graph") | ||
| } | ||
| if cand.Fields[fieldTimeoutSeconds] != "42" { | ||
| t.Errorf("Timeout Seconds = %q, want %q", cand.Fields[fieldTimeoutSeconds], "42") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "github.com/1Password/shell-plugins/sdk" | ||
| "github.com/1Password/shell-plugins/sdk/needsauth" | ||
| "github.com/1Password/shell-plugins/sdk/schema" | ||
| "github.com/1Password/shell-plugins/sdk/schema/credname" | ||
| ) | ||
|
|
||
| // RoamCLI returns the executable schema for the roam-cli binary. | ||
| func RoamCLI() schema.Executable { | ||
| return schema.Executable{ | ||
| Name: "Roam Research CLI", | ||
| Runs: []string{"roam-cli"}, | ||
| DocsURL: sdk.URL("https://github.com/Leechael/roam-cli"), | ||
| NeedsAuth: needsauth.IfAll( | ||
| needsauth.NotForHelpOrVersion(), | ||
| needsauth.NotWithoutArgs(), | ||
| ), | ||
| Uses: []schema.CredentialUsage{ | ||
| {Name: credname.APIToken}, | ||
| }, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| module github.com/Leechael/roam-cli/contrib/1password-plugin | ||
|
|
||
| go 1.25.7 | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| require ( | ||
| github.com/1Password/shell-plugins v0.0.0-20260604224627-af9327a7375e | ||
| github.com/hashicorp/go-plugin v1.8.0 | ||
| ) | ||
|
|
||
| require ( | ||
| github.com/BurntSushi/toml v1.2.1 // indirect | ||
| github.com/fatih/color v1.13.0 // indirect | ||
| github.com/golang/protobuf v1.5.4 // indirect | ||
| github.com/hashicorp/go-hclog v1.6.3 // indirect | ||
| github.com/hashicorp/yamux v0.1.2 // indirect | ||
| github.com/mattn/go-colorable v0.1.12 // indirect | ||
| github.com/mattn/go-isatty v0.0.17 // indirect | ||
| github.com/oklog/run v1.1.0 // indirect | ||
| golang.org/x/net v0.38.0 // indirect | ||
| golang.org/x/sys v0.31.0 // indirect | ||
| golang.org/x/text v0.23.0 // indirect | ||
| google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect | ||
| google.golang.org/grpc v1.61.0 // indirect | ||
| google.golang.org/protobuf v1.36.6 // indirect | ||
| gopkg.in/ini.v1 v1.67.0 // indirect | ||
| gopkg.in/yaml.v2 v2.4.0 // indirect | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.