Skip to content

Commit 54ec59d

Browse files
Merge pull request #342 from rajapri28613/axiom
Add support for Axiom CLI
2 parents 07c75e7 + 2b6f1af commit 54ec59d

File tree

5 files changed

+162
-0
lines changed

5 files changed

+162
-0
lines changed

plugins/axiom/axiom.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package axiom
2+
3+
import (
4+
"github.com/1Password/shell-plugins/sdk"
5+
"github.com/1Password/shell-plugins/sdk/needsauth"
6+
"github.com/1Password/shell-plugins/sdk/schema"
7+
"github.com/1Password/shell-plugins/sdk/schema/credname"
8+
)
9+
10+
func AxiomCLI() schema.Executable {
11+
return schema.Executable{
12+
Name: "Axiom CLI",
13+
Runs: []string{"axiom"},
14+
DocsURL: sdk.URL("https://axiom.co/docs/reference/cli"),
15+
NeedsAuth: needsauth.IfAll(
16+
needsauth.NotForHelpOrVersion(),
17+
needsauth.NotWithoutArgs(),
18+
),
19+
Uses: []schema.CredentialUsage{
20+
{
21+
Name: credname.PersonalAccessToken,
22+
},
23+
},
24+
}
25+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package axiom
2+
3+
import (
4+
"github.com/1Password/shell-plugins/sdk"
5+
"github.com/1Password/shell-plugins/sdk/importer"
6+
"github.com/1Password/shell-plugins/sdk/provision"
7+
"github.com/1Password/shell-plugins/sdk/schema"
8+
"github.com/1Password/shell-plugins/sdk/schema/credname"
9+
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
10+
)
11+
12+
func PersonalAccessToken() schema.CredentialType {
13+
return schema.CredentialType{
14+
Name: credname.PersonalAccessToken,
15+
DocsURL: sdk.URL("https://axiom.co/docs/restapi/token#creating-personal-token"),
16+
ManagementURL: sdk.URL("https://app.axiom.co/settings/profile"),
17+
Fields: []schema.CredentialField{
18+
{
19+
Name: fieldname.Token,
20+
MarkdownDescription: "Token used to authenticate to Axiom.",
21+
Secret: true,
22+
Composition: &schema.ValueComposition{
23+
Length: 41,
24+
Charset: schema.Charset{
25+
Lowercase: true,
26+
Digits: true,
27+
},
28+
},
29+
},
30+
{
31+
Name: fieldname.Organization,
32+
MarkdownDescription: "The organization ID of the organization the access token is valid for. Only valid for Axiom Cloud.",
33+
Secret: false,
34+
Composition: &schema.ValueComposition{
35+
Charset: schema.Charset{
36+
Lowercase: true,
37+
Digits: true,
38+
Specific: []rune{'-'},
39+
},
40+
},
41+
},
42+
{
43+
Name: fieldname.Deployment,
44+
MarkdownDescription: "Deployment to use.",
45+
Secret: false,
46+
Optional: true,
47+
Composition: &schema.ValueComposition{
48+
Charset: schema.Charset{
49+
Lowercase: true,
50+
Digits: true,
51+
},
52+
},
53+
},
54+
},
55+
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
56+
Importer: importer.TryEnvVarPair(defaultEnvVarMapping),
57+
}
58+
}
59+
60+
var defaultEnvVarMapping = map[string]sdk.FieldName{
61+
"AXIOM_TOKEN": fieldname.Token,
62+
"AXIOM_ORG_ID": fieldname.Organization,
63+
"AXIOM_DEPLOYMENT": fieldname.Deployment,
64+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package axiom
2+
3+
import (
4+
"testing"
5+
6+
"github.com/1Password/shell-plugins/sdk"
7+
"github.com/1Password/shell-plugins/sdk/plugintest"
8+
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
9+
)
10+
11+
func TestPersonalAccessTokenProvisioner(t *testing.T) {
12+
plugintest.TestProvisioner(t, PersonalAccessToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{
13+
"default": {
14+
ItemFields: map[sdk.FieldName]string{
15+
fieldname.Token: "xapt-wovexreez0qf7zvkn935na41cudk2example",
16+
fieldname.Organization: "example",
17+
fieldname.Deployment: "cloud",
18+
},
19+
ExpectedOutput: sdk.ProvisionOutput{
20+
Environment: map[string]string{
21+
"AXIOM_TOKEN": "xapt-wovexreez0qf7zvkn935na41cudk2example",
22+
"AXIOM_ORG_ID": "example",
23+
"AXIOM_DEPLOYMENT": "cloud",
24+
},
25+
},
26+
},
27+
})
28+
}
29+
30+
func TestPersonalAccessTokenImporter(t *testing.T) {
31+
plugintest.TestImporter(t, PersonalAccessToken().Importer, map[string]plugintest.ImportCase{
32+
"environment": {
33+
Environment: map[string]string{
34+
"AXIOM_TOKEN": "xapt-wovexreez0qf7zvkn935na41cudk2example",
35+
"AXIOM_ORG_ID": "example",
36+
"AXIOM_DEPLOYMENT": "cloud",
37+
},
38+
ExpectedCandidates: []sdk.ImportCandidate{
39+
{
40+
Fields: map[sdk.FieldName]string{
41+
fieldname.Token: "xapt-wovexreez0qf7zvkn935na41cudk2example",
42+
fieldname.Organization: "example",
43+
fieldname.Deployment: "cloud",
44+
},
45+
},
46+
},
47+
},
48+
})
49+
}

plugins/axiom/plugin.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package axiom
2+
3+
import (
4+
"github.com/1Password/shell-plugins/sdk"
5+
"github.com/1Password/shell-plugins/sdk/schema"
6+
)
7+
8+
func New() schema.Plugin {
9+
return schema.Plugin{
10+
Name: "axiom",
11+
Platform: schema.PlatformInfo{
12+
Name: "Axiom",
13+
Homepage: sdk.URL("https://axiom.co"),
14+
},
15+
Credentials: []schema.CredentialType{
16+
PersonalAccessToken(),
17+
},
18+
Executables: []schema.Executable{
19+
AxiomCLI(),
20+
},
21+
}
22+
}

sdk/schema/fieldname/names.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const (
2727
Credentials = sdk.FieldName("Credentials")
2828
Database = sdk.FieldName("Database")
2929
DefaultRegion = sdk.FieldName("Default Region")
30+
Deployment = sdk.FieldName("Deployment")
3031
Email = sdk.FieldName("Email")
3132
Endpoint = sdk.FieldName("Endpoint")
3233
Host = sdk.FieldName("Host")
@@ -81,6 +82,7 @@ func ListAll() []sdk.FieldName {
8182
Credentials,
8283
Database,
8384
DefaultRegion,
85+
Deployment,
8486
Endpoint,
8587
Host,
8688
HostAddress,

0 commit comments

Comments
 (0)