Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions plugins/anthropic/api_key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package anthropic

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"
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
)

func APIKey() schema.CredentialType {
return schema.CredentialType{
Name: credname.APIKey,
DocsURL: sdk.URL("https://docs.anthropic.com/en/home"),
ManagementURL: sdk.URL("https://console.anthropic.com/settings/keys"),
Fields: []schema.CredentialField{
{
Name: fieldname.APIKey,
MarkdownDescription: "API Key used to authenticate to the Anthropic API.",
Secret: true,
Composition: &schema.ValueComposition{
Prefix: "sk-ant-",
Charset: schema.Charset{
Uppercase: true,
Lowercase: true,
Digits: true,
Symbols: true,
},
},
},
},
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
Importer: importer.TryEnvVarPair(defaultEnvVarMapping),
}
}

var defaultEnvVarMapping = map[string]sdk.FieldName{
"ANTHROPIC_API_KEY": fieldname.APIKey,
}
41 changes: 41 additions & 0 deletions plugins/anthropic/api_key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package anthropic

import (
"testing"

"github.com/1Password/shell-plugins/sdk"
"github.com/1Password/shell-plugins/sdk/plugintest"
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
)

func TestAPIKeyProvisioner(t *testing.T) {
plugintest.TestProvisioner(t, APIKey().DefaultProvisioner, map[string]plugintest.ProvisionCase{
"default": {
ItemFields: map[sdk.FieldName]string{
fieldname.APIKey: "sk-ant-api03-6ZuKEYkQUs5tduCvwiQ7YmfDlx2h13q3ovHLfHX2NAXiUA81ixbluqFo4CfUqmodkho4HvYAmlYk0wuIFTLV5w-EXAMPLE",
},
ExpectedOutput: sdk.ProvisionOutput{
Environment: map[string]string{
"ANTHROPIC_API_KEY": "sk-ant-api03-6ZuKEYkQUs5tduCvwiQ7YmfDlx2h13q3ovHLfHX2NAXiUA81ixbluqFo4CfUqmodkho4HvYAmlYk0wuIFTLV5w-EXAMPLE",
},
},
},
})
}

func TestAPIKeyImporter(t *testing.T) {
plugintest.TestImporter(t, APIKey().Importer, map[string]plugintest.ImportCase{
"environment": {
Environment: map[string]string{
"ANTHROPIC_API_KEY": "sk-ant-api03-6ZuKEYkQUs5tduCvwiQ7YmfDlx2h13q3ovHLfHX2NAXiUA81ixbluqFo4CfUqmodkho4HvYAmlYk0wuIFTLV5w-EXAMPLE",
},
ExpectedCandidates: []sdk.ImportCandidate{
{
Fields: map[sdk.FieldName]string{
fieldname.APIKey: "sk-ant-api03-6ZuKEYkQUs5tduCvwiQ7YmfDlx2h13q3ovHLfHX2NAXiUA81ixbluqFo4CfUqmodkho4HvYAmlYk0wuIFTLV5w-EXAMPLE",
},
},
},
},
})
}
22 changes: 22 additions & 0 deletions plugins/anthropic/claude_code.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package anthropic

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"
)

func ClaudeCodeCLI() schema.Executable {
return schema.Executable{
Name: "Claude Code",
Runs: []string{"claude"},
DocsURL: sdk.URL("https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview"),
NeedsAuth: needsauth.NotForHelpOrVersion(),
Uses: []schema.CredentialUsage{
{
Name: credname.APIKey,
},
},
}
Comment on lines +18 to +21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let run gofmt -w . in this directory, to make sure the code passes the linter.

Happy to reapprove and merge afterwards!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~/C/s/plugins/anthropic on add-anthropic
❯ gofmt -w .

~/C/s/plugins/anthropic on add-anthropic
❯ git s
On branch add-anthropic
Your branch is up to date with 'origin/add-anthropic'.

nothing to commit, working tree clean

}
22 changes: 22 additions & 0 deletions plugins/anthropic/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package anthropic

import (
"github.com/1Password/shell-plugins/sdk"
"github.com/1Password/shell-plugins/sdk/schema"
)

func New() schema.Plugin {
return schema.Plugin{
Name: "anthropic",
Platform: schema.PlatformInfo{
Name: "Anthropic",
Homepage: sdk.URL("https://anthropic.com"),
},
Credentials: []schema.CredentialType{
APIKey(),
},
Executables: []schema.Executable{
ClaudeCodeCLI(),
},
}
}