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/gemini/api_key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package gemini

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://github.com/google-gemini/gemini-cli/blob/main/docs/cli/authentication.md"),
ManagementURL: sdk.URL("https://aistudio.google.com/app/apikey"),
Fields: []schema.CredentialField{
{
Name: fieldname.APIKey,
MarkdownDescription: "API Key used to authenticate to Google Gemini.",
Secret: true,
Composition: &schema.ValueComposition{
Length: 100,
Charset: schema.Charset{
Uppercase: true,
},
},
},
},
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
Importer: importer.TryAll(
importer.TryEnvVarPair(defaultEnvVarMapping),
),
}
}

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

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{ // TODO: Check if this is correct
fieldname.APIKey: "UIYISUJNXTDEEXAMPLE",
},
ExpectedOutput: sdk.ProvisionOutput{
Environment: map[string]string{
"GEMINI_API_KEY": "UIYISUJNXTDEEXAMPLE",
},
},
},
})
}

func TestAPIKeyImporter(t *testing.T) {
plugintest.TestImporter(t, APIKey().Importer, map[string]plugintest.ImportCase{
"environment": {
Environment: map[string]string{ // TODO: Check if this is correct
"GEMINI_API_KEY": "UIYISUJNXTDEEXAMPLE",
},
ExpectedCandidates: []sdk.ImportCandidate{
{
Fields: map[sdk.FieldName]string{
fieldname.APIKey: "UIYISUJNXTDEEXAMPLE",
},
},
},
},
// TODO: If you implemented a config file importer, add a test file example in gemini/test-fixtures
// and fill the necessary details in the test template below.
"config file": {
Files: map[string]string{
// "~/path/to/config.yml": plugintest.LoadFixture(t, "config.yml"),
},
ExpectedCandidates: []sdk.ImportCandidate{
// {
// Fields: map[sdk.FieldName]string{
// fieldname.Token: "UIYISUJNXTDEEXAMPLE",
// },
// },
},
},
})
}
25 changes: 25 additions & 0 deletions plugins/gemini/gemini.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package gemini

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 GoogleGeminiCLI() schema.Executable {
return schema.Executable{
Name: "Google Gemini CLI",
Runs: []string{"gemini"},
DocsURL: sdk.URL("https://github.com/google-gemini/gemini-cli/blob/main/docs/cli/index.md"),
NeedsAuth: needsauth.IfAll(
needsauth.NotForHelpOrVersion(),
needsauth.NotWithoutArgs(),
),
Uses: []schema.CredentialUsage{
{
Name: credname.APIKey,
},
},
}
}
22 changes: 22 additions & 0 deletions plugins/gemini/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package gemini

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

func New() schema.Plugin {
return schema.Plugin{
Name: "gemini",
Platform: schema.PlatformInfo{
Name: "Google Gemini",
Homepage: sdk.URL("https://gemini.google.com"),
},
Credentials: []schema.CredentialType{
APIKey(),
},
Executables: []schema.Executable{
GoogleGeminiCLI(),
},
}
}