Skip to content

Commit b423b94

Browse files
committed
Add support for Axiom CLI
1 parent 1e4048c commit b423b94

File tree

4 files changed

+128
-0
lines changed

4 files changed

+128
-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.com/docs/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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
Prefix: "xapt-",
25+
Charset: schema.Charset{
26+
Lowercase: true,
27+
Digits: true,
28+
},
29+
},
30+
},
31+
},
32+
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
33+
Importer: importer.TryAll(
34+
importer.TryEnvVarPair(defaultEnvVarMapping),
35+
)}
36+
}
37+
38+
var defaultEnvVarMapping = map[string]sdk.FieldName{
39+
"AXIOM_TOKEN": fieldname.Token,
40+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
},
17+
ExpectedOutput: sdk.ProvisionOutput{
18+
Environment: map[string]string{
19+
"AXIOM_TOKEN": "xapt-wovexreez0qf7zvkn935na41cudk2example",
20+
},
21+
},
22+
},
23+
})
24+
}
25+
26+
func TestPersonalAccessTokenImporter(t *testing.T) {
27+
plugintest.TestImporter(t, PersonalAccessToken().Importer, map[string]plugintest.ImportCase{
28+
"environment": {
29+
Environment: map[string]string{
30+
"AXIOM_TOKEN": "xapt-wovexreez0qf7zvkn935na41cudk2example",
31+
},
32+
ExpectedCandidates: []sdk.ImportCandidate{
33+
{
34+
Fields: map[sdk.FieldName]string{
35+
fieldname.Token: "xapt-wovexreez0qf7zvkn935na41cudk2example",
36+
},
37+
},
38+
},
39+
},
40+
})
41+
}

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+
}

0 commit comments

Comments
 (0)