diff --git a/plugins/firectl/api_key.go b/plugins/firectl/api_key.go new file mode 100644 index 00000000..e9e8dab6 --- /dev/null +++ b/plugins/firectl/api_key.go @@ -0,0 +1,23 @@ +package firectl + +import ( + "github.com/1Password/shell-plugins/sdk" + "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, + ManagementURL: sdk.URL("https://app.fireworks.ai/settings/users/api-keys"), + Fields: []schema.CredentialField{ + { + Name: fieldname.APIKey, + MarkdownDescription: "API Key used to authenticate to Firectl.", + Secret: true, + }, + }, + DefaultProvisioner: FirectlCLIArgProvisioner(), + } +} diff --git a/plugins/firectl/api_key_test.go b/plugins/firectl/api_key_test.go new file mode 100644 index 00000000..6ece0fa4 --- /dev/null +++ b/plugins/firectl/api_key_test.go @@ -0,0 +1,37 @@ +package firectl + +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": { + CommandLine: []string{"firectl", "users", "list"}, + ItemFields: map[sdk.FieldName]string{ + fieldname.APIKey: "fw_G2bznICSywu0kUNkfqX4xpz7ECaTjrZd9EXAMPLE", + }, + ExpectedOutput: sdk.ProvisionOutput{ + CommandLine: []string{"firectl", "users", "list", "--api-key", "fw_G2bznICSywu0kUNkfqX4xpz7ECaTjrZd9EXAMPLE"}, + }, + }, + "missing API key": { + CommandLine: []string{"firectl", "users", "list"}, + ItemFields: map[sdk.FieldName]string{}, + ExpectedOutput: sdk.ProvisionOutput{ + CommandLine: []string{"firectl", "users", "list"}, + Diagnostics: sdk.Diagnostics{ + Errors: []sdk.Error{ + { + Message: "missing API key field", + }, + }, + }, + }, + }, + }) +} diff --git a/plugins/firectl/firectl.go b/plugins/firectl/firectl.go new file mode 100644 index 00000000..4d2e162e --- /dev/null +++ b/plugins/firectl/firectl.go @@ -0,0 +1,25 @@ +package firectl + +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 FirectlCLI() schema.Executable { + return schema.Executable{ + Name: "Firectl CLI", + Runs: []string{"firectl"}, + DocsURL: sdk.URL("https://docs.fireworks.ai/tools-sdks/firectl/firectl"), + NeedsAuth: needsauth.IfAll( + needsauth.NotForHelpOrVersion(), + needsauth.NotWithoutArgs(), + ), + Uses: []schema.CredentialUsage{ + { + Name: credname.APIKey, + }, + }, + } +} diff --git a/plugins/firectl/plugin.go b/plugins/firectl/plugin.go new file mode 100644 index 00000000..54dc7f80 --- /dev/null +++ b/plugins/firectl/plugin.go @@ -0,0 +1,22 @@ +package firectl + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/schema" +) + +func New() schema.Plugin { + return schema.Plugin{ + Name: "firectl", + Platform: schema.PlatformInfo{ + Name: "Fireworks AI", + Homepage: sdk.URL("https://fireworks.ai"), + }, + Credentials: []schema.CredentialType{ + APIKey(), + }, + Executables: []schema.Executable{ + FirectlCLI(), + }, + } +} diff --git a/plugins/firectl/provisioner.go b/plugins/firectl/provisioner.go new file mode 100644 index 00000000..f9876465 --- /dev/null +++ b/plugins/firectl/provisioner.go @@ -0,0 +1,37 @@ +package firectl + +import ( + "context" + "errors" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +type firectlCLIArgProvisioner struct { + sdk.Provisioner +} + +func FirectlCLIArgProvisioner() sdk.Provisioner { + return firectlCLIArgProvisioner{} +} + +const firectlApiKeyFlag = "--api-key" + +func (p firectlCLIArgProvisioner) Provision(ctx context.Context, in sdk.ProvisionInput, out *sdk.ProvisionOutput) { + apiKey, ok := in.ItemFields[fieldname.APIKey] + if !ok { + out.AddError(errors.New("missing API key field")) + return + } + + out.AddArgs(firectlApiKeyFlag, apiKey) +} + +func (p firectlCLIArgProvisioner) Deprovision(ctx context.Context, in sdk.DeprovisionInput, out *sdk.DeprovisionOutput) { + // No op +} + +func (p firectlCLIArgProvisioner) Description() string { + return "Firectl CLI API Key argument provisioner" +}