File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package opencode
2+
3+ import (
4+ "github.com/1Password/shell-plugins/sdk"
5+ "github.com/1Password/shell-plugins/sdk/importer"
6+ "github.com/1Password/shell-plugins/sdk/provision"
7+ "github.com/1Password/shell-plugins/sdk/schema"
8+ "github.com/1Password/shell-plugins/sdk/schema/credname"
9+ "github.com/1Password/shell-plugins/sdk/schema/fieldname"
10+ )
11+
12+ func APIKey () schema.CredentialType {
13+ return schema.CredentialType {
14+ Name : credname .APIKey ,
15+ DocsURL : sdk .URL ("https://opencode.ai/docs/" ),
16+ ManagementURL : sdk .URL ("https://opencode.ai/auth" ),
17+ Fields : []schema.CredentialField {
18+ {
19+ Name : fieldname .APIKey ,
20+ MarkdownDescription : "API Key used to authenticate to opencode." ,
21+ Secret : true ,
22+ },
23+ },
24+ DefaultProvisioner : provision .EnvVars (defaultEnvVarMapping ),
25+ Importer : importer .TryEnvVarPair (defaultEnvVarMapping ),
26+ }
27+ }
28+
29+ var defaultEnvVarMapping = map [string ]sdk.FieldName {
30+ "OPENCODE_API_KEY" : fieldname .APIKey ,
31+ }
Original file line number Diff line number Diff line change 1+ package opencode
2+
3+ import (
4+ "testing"
5+
6+ "github.com/1Password/shell-plugins/sdk"
7+ "github.com/1Password/shell-plugins/sdk/plugintest"
8+ "github.com/1Password/shell-plugins/sdk/schema/fieldname"
9+ )
10+
11+ const exampleAPIKey = "sk-0123456789abcdefghijEXAMPLE"
12+
13+ func TestAPIKeyProvisioner (t * testing.T ) {
14+ plugintest .TestProvisioner (t , APIKey ().DefaultProvisioner , map [string ]plugintest.ProvisionCase {
15+ "default" : {
16+ ItemFields : map [sdk.FieldName ]string {
17+ fieldname .APIKey : exampleAPIKey ,
18+ },
19+ ExpectedOutput : sdk.ProvisionOutput {
20+ Environment : map [string ]string {
21+ "OPENCODE_API_KEY" : exampleAPIKey ,
22+ },
23+ },
24+ },
25+ })
26+ }
27+
28+ func TestAPIKeyImporter (t * testing.T ) {
29+ plugintest .TestImporter (t , APIKey ().Importer , map [string ]plugintest.ImportCase {
30+ "environment" : {
31+ Environment : map [string ]string {
32+ "OPENCODE_API_KEY" : exampleAPIKey ,
33+ },
34+ ExpectedCandidates : []sdk.ImportCandidate {
35+ {
36+ Fields : map [sdk.FieldName ]string {
37+ fieldname .APIKey : exampleAPIKey ,
38+ },
39+ },
40+ },
41+ },
42+ })
43+ }
Original file line number Diff line number Diff line change 1+ package opencode
2+
3+ import (
4+ "github.com/1Password/shell-plugins/sdk"
5+ "github.com/1Password/shell-plugins/sdk/needsauth"
6+ "github.com/1Password/shell-plugins/sdk/schema"
7+ "github.com/1Password/shell-plugins/sdk/schema/credname"
8+ )
9+
10+ func OpencodeCLI () schema.Executable {
11+ return schema.Executable {
12+ Name : "opencode CLI" ,
13+ Runs : []string {"opencode" },
14+ DocsURL : sdk .URL ("https://opencode.ai/docs/" ),
15+ NeedsAuth : needsauth .IfAll (
16+ needsauth .NotForHelpOrVersion (),
17+ needsauth .NotWithoutArgs (),
18+ ),
19+ Uses : []schema.CredentialUsage {
20+ {
21+ Name : credname .APIKey ,
22+ },
23+ },
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ package opencode
2+
3+ import (
4+ "github.com/1Password/shell-plugins/sdk"
5+ "github.com/1Password/shell-plugins/sdk/schema"
6+ )
7+
8+ func New () schema.Plugin {
9+ return schema.Plugin {
10+ Name : "opencode" ,
11+ Platform : schema.PlatformInfo {
12+ Name : "opencode" ,
13+ Homepage : sdk .URL ("https://opencode.ai" ),
14+ },
15+ Credentials : []schema.CredentialType {
16+ APIKey (),
17+ },
18+ Executables : []schema.Executable {
19+ OpencodeCLI (),
20+ },
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments