diff --git a/plugins/axiom/axiom.go b/plugins/axiom/axiom.go new file mode 100644 index 000000000..5881e77a5 --- /dev/null +++ b/plugins/axiom/axiom.go @@ -0,0 +1,25 @@ +package axiom + +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 AxiomCLI() schema.Executable { + return schema.Executable{ + Name: "Axiom CLI", + Runs: []string{"axiom"}, + DocsURL: sdk.URL("https://axiom.com/docs/cli"), + NeedsAuth: needsauth.IfAll( + needsauth.NotForHelpOrVersion(), + needsauth.NotWithoutArgs(), + ), + Uses: []schema.CredentialUsage{ + { + Name: credname.PersonalAccessToken, + }, + }, + } +} diff --git a/plugins/axiom/personal_access_token.go b/plugins/axiom/personal_access_token.go new file mode 100644 index 000000000..433a9e8be --- /dev/null +++ b/plugins/axiom/personal_access_token.go @@ -0,0 +1,40 @@ +package axiom + +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 PersonalAccessToken() schema.CredentialType { + return schema.CredentialType{ + Name: credname.PersonalAccessToken, + DocsURL: sdk.URL("https://axiom.co/docs/restapi/token#creating-personal-token"), + ManagementURL: sdk.URL("https://app.axiom.co/settings/profile"), + Fields: []schema.CredentialField{ + { + Name: fieldname.Token, + MarkdownDescription: "Token used to authenticate to Axiom.", + Secret: true, + Composition: &schema.ValueComposition{ + Length: 41, + Prefix: "xapt-", + Charset: schema.Charset{ + Lowercase: true, + Digits: true, + }, + }, + }, + }, + DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), + Importer: importer.TryAll( + importer.TryEnvVarPair(defaultEnvVarMapping), + )} +} + +var defaultEnvVarMapping = map[string]sdk.FieldName{ + "AXIOM_TOKEN": fieldname.Token, +} diff --git a/plugins/axiom/personal_access_token_test.go b/plugins/axiom/personal_access_token_test.go new file mode 100644 index 000000000..cc597adf6 --- /dev/null +++ b/plugins/axiom/personal_access_token_test.go @@ -0,0 +1,41 @@ +package axiom + +import ( + "testing" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/plugintest" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +func TestPersonalAccessTokenProvisioner(t *testing.T) { + plugintest.TestProvisioner(t, PersonalAccessToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{ + "default": { + ItemFields: map[sdk.FieldName]string{ + fieldname.Token: "xapt-wovexreez0qf7zvkn935na41cudk2example", + }, + ExpectedOutput: sdk.ProvisionOutput{ + Environment: map[string]string{ + "AXIOM_TOKEN": "xapt-wovexreez0qf7zvkn935na41cudk2example", + }, + }, + }, + }) +} + +func TestPersonalAccessTokenImporter(t *testing.T) { + plugintest.TestImporter(t, PersonalAccessToken().Importer, map[string]plugintest.ImportCase{ + "environment": { + Environment: map[string]string{ + "AXIOM_TOKEN": "xapt-wovexreez0qf7zvkn935na41cudk2example", + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.Token: "xapt-wovexreez0qf7zvkn935na41cudk2example", + }, + }, + }, + }, + }) +} diff --git a/plugins/axiom/plugin.go b/plugins/axiom/plugin.go new file mode 100644 index 000000000..7320d7dd2 --- /dev/null +++ b/plugins/axiom/plugin.go @@ -0,0 +1,22 @@ +package axiom + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/schema" +) + +func New() schema.Plugin { + return schema.Plugin{ + Name: "axiom", + Platform: schema.PlatformInfo{ + Name: "Axiom", + Homepage: sdk.URL("https://axiom.co"), + }, + Credentials: []schema.CredentialType{ + PersonalAccessToken(), + }, + Executables: []schema.Executable{ + AxiomCLI(), + }, + } +}