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

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://junie.jetbrains.com/docs/environment-variables.html"),
ManagementURL: sdk.URL("https://junie.jetbrains.com/cli"),
Fields: []schema.CredentialField{
{
Name: fieldname.APIKey,
MarkdownDescription: "Junie API key used to authenticate to JetBrains Junie CLI.",
Secret: true,
},
},
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Junie have specific env vars to authenticate against providers via BYOK. See https://junie.jetbrains.com/docs/environment-variables.html#provider-api-keys
Is there any way to implement it in the shell plugins? I have been also looking into support OpenCode which relies on env vars from providers as well.

Importer: importer.TryEnvVarPair(defaultEnvVarMapping),
}
}

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

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{
"junie api key": {
ItemFields: map[sdk.FieldName]string{
fieldname.APIKey: "perm-yEyY18xzH5IiiORdCDzstp1h2xrxCydfh9tjFveUyEXAMPLE",
},
ExpectedOutput: sdk.ProvisionOutput{
Environment: map[string]string{
"JUNIE_API_KEY": "perm-yEyY18xzH5IiiORdCDzstp1h2xrxCydfh9tjFveUyEXAMPLE",
},
},
},
"does not provision provider api keys": {
ItemFields: map[sdk.FieldName]string{
sdk.FieldName("Anthropic API Key"): "sk-ant-api03-yEyY18xzH5IiiORdCDzstp1h2xrxCydfh9tjFveUyEXAMPLE",
sdk.FieldName("OpenAI API Key"): "sk-yEyY18xzH5IiiORdCDzstp1h2xrxCydfh9tjFveUyEXAMPLE",
sdk.FieldName("Google API Key"): "AI-yEyY18xzH5IiiORdCDzstp1h2xrxCydfh9tjFveUyEXAMPLE",
sdk.FieldName("Grok API Key"): "xai-yEyY18xzH5IiiORdCDzstp1h2xrxCydfh9tjFveUyEXAMPLE",
sdk.FieldName("OpenRouter API Key"): "sk-or-yEyY18xzH5IiiORdCDzstp1h2xrxCydfh9tjFveUyEXAMPLE",
},
ExpectedOutput: sdk.ProvisionOutput{
Environment: map[string]string{},
},
},
"does not provision project or task runtime inputs": {
ItemFields: map[sdk.FieldName]string{
fieldname.Project: "/tmp/example-project",
sdk.FieldName("Task"): "Review and fix any code quality issues in the latest commit",
},
ExpectedOutput: sdk.ProvisionOutput{
Environment: map[string]string{},
},
},
})
}

func TestAPIKeyImporter(t *testing.T) {
plugintest.TestImporter(t, APIKey().Importer, map[string]plugintest.ImportCase{
"junie api key environment": {
Environment: map[string]string{
"JUNIE_API_KEY": "perm-yEyY18xzH5IiiORdCDzstp1h2xrxCydfh9tjFveUyEXAMPLE",
},
ExpectedCandidates: []sdk.ImportCandidate{
{
Fields: map[sdk.FieldName]string{
fieldname.APIKey: "perm-yEyY18xzH5IiiORdCDzstp1h2xrxCydfh9tjFveUyEXAMPLE",
},
},
},
},
"provider api key environment": {
Environment: map[string]string{
"JUNIE_ANTHROPIC_API_KEY": "sk-ant-api03-yEyY18xzH5IiiORdCDzstp1h2xrxCydfh9tjFveUyEXAMPLE",
"JUNIE_OPENAI_API_KEY": "sk-yEyY18xzH5IiiORdCDzstp1h2xrxCydfh9tjFveUyEXAMPLE",
"JUNIE_GOOGLE_API_KEY": "AI-yEyY18xzH5IiiORdCDzstp1h2xrxCydfh9tjFveUyEXAMPLE",
"JUNIE_GROK_API_KEY": "xai-yEyY18xzH5IiiORdCDzstp1h2xrxCydfh9tjFveUyEXAMPLE",
"JUNIE_OPENROUTER_API_KEY": "sk-or-yEyY18xzH5IiiORdCDzstp1h2xrxCydfh9tjFveUyEXAMPLE",
},
ExpectedCandidates: []sdk.ImportCandidate{},
},
})
}
22 changes: 22 additions & 0 deletions plugins/junie/junie.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package junie

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 JunieCLI() schema.Executable {
return schema.Executable{
Name: "JetBrains Junie CLI",
Runs: []string{"junie"},
DocsURL: sdk.URL("https://junie.jetbrains.com/docs/junie-cli-usage.html"),
NeedsAuth: needsauth.NotForHelpOrVersion(),
Uses: []schema.CredentialUsage{
{
Name: credname.APIKey,
},
},
}
}
22 changes: 22 additions & 0 deletions plugins/junie/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package junie

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

func New() schema.Plugin {
return schema.Plugin{
Name: "junie",
Platform: schema.PlatformInfo{
Name: "JetBrains Junie",
Homepage: sdk.URL("https://junie.jetbrains.com"),
},
Credentials: []schema.CredentialType{
APIKey(),
},
Executables: []schema.Executable{
JunieCLI(),
},
}
}
Comment on lines +8 to +22