Skip to content

Commit

Permalink
Add support for Axiom CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
rajapri28613 committed Jul 1, 2023
1 parent 1e4048c commit b423b94
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
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.com/docs/cli"),
NeedsAuth: needsauth.IfAll(
needsauth.NotForHelpOrVersion(),
needsauth.NotWithoutArgs(),
),
Uses: []schema.CredentialUsage{
{
Name: credname.PersonalAccessToken,
},
},
}
}
40 changes: 40 additions & 0 deletions plugins/axiom/personal_access_token.go
Original file line number Diff line number Diff line change
@@ -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,
}
41 changes: 41 additions & 0 deletions plugins/axiom/personal_access_token_test.go
Original file line number Diff line number Diff line change
@@ -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",
},
},
},
},
})
}
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(),
},
}
}

0 comments on commit b423b94

Please sign in to comment.