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
39 changes: 39 additions & 0 deletions plugins/cursor/api_key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package cursor

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://cursor.com/docs/cli/reference/authentication"),
ManagementURL: sdk.URL("https://cursor.com/dashboard"),
Fields: []schema.CredentialField{
{
Name: fieldname.APIKey,
MarkdownDescription: "API Key used to authenticate to Cursor CLI.",
Secret: true,
Composition: &schema.ValueComposition{
Prefix: "crsr_",
Charset: schema.Charset{
Uppercase: true,
Lowercase: true,
Digits: true,
},
},
},
},
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
Importer: importer.TryEnvVarPair(defaultEnvVarMapping),
}
}

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

import (
"testing"

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

const exampleAPIKey = "crsr_12345678"

func TestAPIKeyProvisioner(t *testing.T) {
plugintest.TestProvisioner(t, APIKey().DefaultProvisioner, map[string]plugintest.ProvisionCase{
"default": {
ItemFields: map[sdk.FieldName]string{
fieldname.APIKey: exampleAPIKey,
},
ExpectedOutput: sdk.ProvisionOutput{
Environment: map[string]string{
"CURSOR_API_KEY": exampleAPIKey,
},
},
},
})
}

func TestAPIKeyImporter(t *testing.T) {
plugintest.TestImporter(t, APIKey().Importer, map[string]plugintest.ImportCase{
"environment": {
Environment: map[string]string{
"CURSOR_API_KEY": exampleAPIKey,
},
ExpectedCandidates: []sdk.ImportCandidate{
{
Fields: map[sdk.FieldName]string{
fieldname.APIKey: exampleAPIKey,
},
},
},
},
})
}
29 changes: 29 additions & 0 deletions plugins/cursor/cursor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cursor

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 CursorCLI() schema.Executable {
return schema.Executable{
Name: "Cursor CLI",
Runs: []string{"agent"},
DocsURL: sdk.URL("https://cursor.com/docs/cli/overview"),
NeedsAuth: needsauth.IfAll(
needsauth.NotForHelpOrVersion(),
needsauth.NotWithoutArgs(),
needsauth.NotForExactArgs("login"),
needsauth.NotForExactArgs("logout"),
needsauth.NotForExactArgs("status"),
needsauth.NotWhenContainsArgs("--api-key"),
),
Uses: []schema.CredentialUsage{
{
Name: credname.APIKey,
},
},
}
}
22 changes: 22 additions & 0 deletions plugins/cursor/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cursor

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

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