Skip to content

Commit 331a885

Browse files
Merge pull request #296 from itsCheithanya/civo2
Add support for Civo, a managed Kubernetes service
2 parents 73066ed + 4be5098 commit 331a885

File tree

5 files changed

+180
-0
lines changed

5 files changed

+180
-0
lines changed

plugins/civo/api_key.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package civo
2+
3+
import (
4+
"context"
5+
6+
"github.com/1Password/shell-plugins/sdk"
7+
"github.com/1Password/shell-plugins/sdk/importer"
8+
"github.com/1Password/shell-plugins/sdk/provision"
9+
"github.com/1Password/shell-plugins/sdk/schema"
10+
"github.com/1Password/shell-plugins/sdk/schema/credname"
11+
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
12+
)
13+
14+
func APIKey() schema.CredentialType {
15+
return schema.CredentialType{
16+
Name: credname.APIKey,
17+
DocsURL: sdk.URL("https://www.civo.com/docs/account/api-keys"),
18+
ManagementURL: sdk.URL("https://dashboard.civo.com/security"),
19+
Fields: []schema.CredentialField{
20+
{
21+
Name: fieldname.APIKey,
22+
MarkdownDescription: "API Key used to authenticate to Civo.",
23+
Secret: true,
24+
Composition: &schema.ValueComposition{
25+
Length: 50,
26+
Charset: schema.Charset{
27+
Uppercase: true,
28+
Lowercase: true,
29+
Digits: true,
30+
},
31+
},
32+
},
33+
},
34+
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
35+
Importer: importer.TryAll(
36+
importer.TryEnvVarPair(defaultEnvVarMapping),
37+
TryCivoConfigFile("~/.civo.json"),
38+
)}
39+
}
40+
41+
var defaultEnvVarMapping = map[string]sdk.FieldName{
42+
"CIVO_TOKEN": fieldname.APIKey,
43+
}
44+
45+
func TryCivoConfigFile(path string) sdk.Importer {
46+
return importer.TryFile(path, func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) {
47+
var config Config
48+
if err := contents.ToJSON(&config); err != nil {
49+
out.AddError(err)
50+
return
51+
}
52+
53+
if len(config.Properties) == 0 {
54+
return
55+
}
56+
57+
for key, value := range config.Properties {
58+
out.AddCandidate(sdk.ImportCandidate{
59+
NameHint: key,
60+
Fields: map[sdk.FieldName]string{
61+
fieldname.APIKey: value,
62+
},
63+
})
64+
}
65+
})
66+
}
67+
68+
type Config struct {
69+
Properties map[string]string `json:"apikeys"`
70+
}

plugins/civo/api_key_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package civo
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 TestAPIKeyProvisioner(t *testing.T) {
12+
plugintest.TestProvisioner(t, APIKey().DefaultProvisioner, map[string]plugintest.ProvisionCase{
13+
"default": {
14+
ItemFields: map[sdk.FieldName]string{
15+
fieldname.APIKey: "XFIx85McyfCQc490j1tBa5b5s2XiWerNdOdfnkrOnchEXAMPLE",
16+
},
17+
ExpectedOutput: sdk.ProvisionOutput{
18+
Environment: map[string]string{
19+
"CIVO_TOKEN": "XFIx85McyfCQc490j1tBa5b5s2XiWerNdOdfnkrOnchEXAMPLE",
20+
},
21+
},
22+
},
23+
})
24+
}
25+
26+
func TestAPIKeyImporter(t *testing.T) {
27+
plugintest.TestImporter(t, APIKey().Importer, map[string]plugintest.ImportCase{
28+
"environment": {
29+
Environment: map[string]string{
30+
"CIVO_TOKEN": "XFIx85McyfCQc490j1tBa5b5s2XiWerNdOdfnkrOnchEXAMPLE",
31+
},
32+
ExpectedCandidates: []sdk.ImportCandidate{
33+
{
34+
Fields: map[sdk.FieldName]string{
35+
fieldname.APIKey: "XFIx85McyfCQc490j1tBa5b5s2XiWerNdOdfnkrOnchEXAMPLE",
36+
},
37+
},
38+
},
39+
},
40+
41+
"config file": {
42+
Files: map[string]string{
43+
44+
"~/.civo.json": plugintest.LoadFixture(t, ".civo.json"),
45+
},
46+
ExpectedCandidates: []sdk.ImportCandidate{
47+
{
48+
Fields: map[sdk.FieldName]string{
49+
fieldname.APIKey: "XFIx85McyfCQc490j1tBa5b5s2XiWerNdOdfnkrOnchEXAMPLE",
50+
},
51+
NameHint: "testdemoname",
52+
},
53+
},
54+
},
55+
})
56+
}

plugins/civo/civo.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package civo
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 CivoCLI() schema.Executable {
11+
return schema.Executable{
12+
Name: "Civo CLI",
13+
Runs: []string{"civo"},
14+
DocsURL: sdk.URL("https://www.civo.com/docs/overview/civo-cli"),
15+
NeedsAuth: needsauth.IfAll(
16+
needsauth.NotForHelpOrVersion(),
17+
needsauth.NotWithoutArgs(),
18+
needsauth.NotForExactArgs("config"),
19+
needsauth.NotWhenContainsArgs("apikey", "save"),
20+
),
21+
Uses: []schema.CredentialUsage{
22+
{
23+
Name: credname.APIKey,
24+
},
25+
},
26+
}
27+
}

plugins/civo/plugin.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package civo
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: "civo",
11+
Platform: schema.PlatformInfo{
12+
Name: "Civo",
13+
Homepage: sdk.URL("https://www.civo.com"),
14+
},
15+
Credentials: []schema.CredentialType{
16+
APIKey(),
17+
},
18+
Executables: []schema.Executable{
19+
CivoCLI(),
20+
},
21+
}
22+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"apikeys": {
3+
"testdemoname": "XFIx85McyfCQc490j1tBa5b5s2XiWerNdOdfnkrOnchEXAMPLE"
4+
}
5+
}

0 commit comments

Comments
 (0)