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
23 changes: 23 additions & 0 deletions plugins/firectl/api_key.go
Original file line number Diff line number Diff line change
@@ -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(),
}
}
37 changes: 37 additions & 0 deletions plugins/firectl/api_key_test.go
Original file line number Diff line number Diff line change
@@ -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",
},
},
},
},
},
})
}
25 changes: 25 additions & 0 deletions plugins/firectl/firectl.go
Original file line number Diff line number Diff line change
@@ -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,
},
},
}
}
22 changes: 22 additions & 0 deletions plugins/firectl/plugin.go
Original file line number Diff line number Diff line change
@@ -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(),
},
}
}
37 changes: 37 additions & 0 deletions plugins/firectl/provisioner.go
Original file line number Diff line number Diff line change
@@ -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"
}