Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Axiom CLI #342

Merged
merged 4 commits into from
Sep 21, 2023
Merged
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
25 changes: 25 additions & 0 deletions plugins/axiom/axiom.go
Original file line number Diff line number Diff line change
@@ -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.co/docs/reference/cli"),
NeedsAuth: needsauth.IfAll(
needsauth.NotForHelpOrVersion(),
needsauth.NotWithoutArgs(),
),
Uses: []schema.CredentialUsage{
{
Name: credname.PersonalAccessToken,
},
},
}
}
64 changes: 64 additions & 0 deletions plugins/axiom/personal_access_token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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,
Charset: schema.Charset{
Lowercase: true,
Digits: true,
},
},
},
{
Name: fieldname.Organization,
arunsathiya marked this conversation as resolved.
Show resolved Hide resolved
MarkdownDescription: "The organization ID of the organization the access token is valid for. Only valid for Axiom Cloud.",
Secret: false,
Composition: &schema.ValueComposition{
Charset: schema.Charset{
Lowercase: true,
Digits: true,
Specific: []rune{'-'},
},
},
},
{
Name: fieldname.Deployment,
MarkdownDescription: "Deployment to use.",
Secret: false,
Optional: true,
Composition: &schema.ValueComposition{
Charset: schema.Charset{
Lowercase: true,
Digits: true,
},
},
},
},
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
Importer: importer.TryEnvVarPair(defaultEnvVarMapping),
}
}

var defaultEnvVarMapping = map[string]sdk.FieldName{
"AXIOM_TOKEN": fieldname.Token,
"AXIOM_ORG_ID": fieldname.Organization,
"AXIOM_DEPLOYMENT": fieldname.Deployment,
}
49 changes: 49 additions & 0 deletions plugins/axiom/personal_access_token_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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",
fieldname.Organization: "example",
fieldname.Deployment: "cloud",
},
ExpectedOutput: sdk.ProvisionOutput{
Environment: map[string]string{
"AXIOM_TOKEN": "xapt-wovexreez0qf7zvkn935na41cudk2example",
"AXIOM_ORG_ID": "example",
"AXIOM_DEPLOYMENT": "cloud",
},
},
},
})
}

func TestPersonalAccessTokenImporter(t *testing.T) {
plugintest.TestImporter(t, PersonalAccessToken().Importer, map[string]plugintest.ImportCase{
"environment": {
Environment: map[string]string{
"AXIOM_TOKEN": "xapt-wovexreez0qf7zvkn935na41cudk2example",
"AXIOM_ORG_ID": "example",
"AXIOM_DEPLOYMENT": "cloud",
},
ExpectedCandidates: []sdk.ImportCandidate{
{
Fields: map[sdk.FieldName]string{
fieldname.Token: "xapt-wovexreez0qf7zvkn935na41cudk2example",
fieldname.Organization: "example",
fieldname.Deployment: "cloud",
},
},
},
},
})
}
22 changes: 22 additions & 0 deletions plugins/axiom/plugin.go
Original file line number Diff line number Diff line change
@@ -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(),
},
}
}
2 changes: 2 additions & 0 deletions sdk/schema/fieldname/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
Credentials = sdk.FieldName("Credentials")
Database = sdk.FieldName("Database")
DefaultRegion = sdk.FieldName("Default Region")
Deployment = sdk.FieldName("Deployment")
Email = sdk.FieldName("Email")
Endpoint = sdk.FieldName("Endpoint")
Host = sdk.FieldName("Host")
Expand Down Expand Up @@ -78,6 +79,7 @@ func ListAll() []sdk.FieldName {
Credentials,
Database,
DefaultRegion,
Deployment,
Endpoint,
Host,
HostAddress,
Expand Down