Skip to content

Commit 37ecffe

Browse files
committed
files modified
1 parent 0304366 commit 37ecffe

File tree

5 files changed

+22
-48
lines changed

5 files changed

+22
-48
lines changed

plugins/civo/api_key.go

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ package civo
22

33
import (
44
"context"
5-
"encoding/json"
6-
7-
"github.com/1Password/shell-plugins/sdk"
5+
6+
"github.com/1Password/shell-plugins/sdk"
87
"github.com/1Password/shell-plugins/sdk/importer"
98
"github.com/1Password/shell-plugins/sdk/provision"
109
"github.com/1Password/shell-plugins/sdk/schema"
@@ -33,69 +32,53 @@ func APIKey() schema.CredentialType {
3332
},
3433
{
3534
Name: fieldname.APIKeyID,
36-
MarkdownDescription: "API Name to identify the API Key.",
37-
},
38-
{
39-
Name: fieldname.DefaultRegion,
40-
MarkdownDescription: "The default region to use for this API Key.",
35+
MarkdownDescription: "The Name of apikey used to authenticate to civo",
4136
Optional: true,
4237
},
4338
},
4439
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
4540
Importer: importer.TryAll(
4641
importer.TryEnvVarPair(defaultEnvVarMapping),
47-
TryCivoConfigFile(),
42+
importer.TryEnvVarPair(secondEnvVarMapping),
43+
TryCivoConfigFile("~/.civo.json"),
4844
)}
4945
}
5046

5147
var defaultEnvVarMapping = map[string]sdk.FieldName{
5248
"CIVO_TOKEN": fieldname.APIKey,
53-
"CIVO_API_KEY_NAME": fieldname.APIKeyID,
54-
"CIVO_API_KEY": fieldname.APIKey,
49+
//"CIVO_API_KEY_NAME": fieldname.APIKeyID,
50+
}
51+
52+
var secondEnvVarMapping = map[string]sdk.FieldName{
53+
"CIVO_API_KEY" : fieldname.APIKey,
54+
"CIVO_API_KEY_NAME": fieldname.APIKeyID,
5555
}
5656

57-
func TryCivoConfigFile() sdk.Importer {
57+
func TryCivoConfigFile(path string) sdk.Importer {
5858

59-
return importer.TryFile("~/.civo.json", func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) {
59+
return importer.TryFile(path, func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) {
6060
var config Config
6161
if err := contents.ToJSON(&config); err != nil {
6262
out.AddError(err)
6363
return
6464

6565
}
6666

67-
if len(config.Properties) == 0 && config.Meta.CurrentAPIKey == "" {
67+
if len(config.Properties) == 0 {
6868
return
6969
}
7070

7171
for key, value := range config.Properties {
72-
var apiKey string
73-
74-
err := json.Unmarshal(value, &apiKey)
75-
if err != nil {
76-
out.AddError(err)
77-
return
78-
}
7972
out.AddCandidate(sdk.ImportCandidate{
8073
NameHint: key,
8174
Fields: map[sdk.FieldName]string{
82-
fieldname.APIKey: apiKey,
83-
fieldname.APIKeyID: config.Meta.CurrentAPIKey,
84-
fieldname.DefaultRegion: config.Meta.DefaultRegion,
75+
fieldname.APIKey: value,
8576
},
8677
})
87-
88-
break
8978
}
90-
9179
})
9280
}
9381

9482
type Config struct {
95-
Properties map[string]json.RawMessage `json:"apikeys"`
96-
97-
Meta struct {
98-
CurrentAPIKey string `json:"current_apikey"`
99-
DefaultRegion string `json:"default_region"`
100-
} `json:"meta"`
83+
Properties map[string]string `json:"apikeys"`
10184
}

plugins/civo/api_key_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ func TestAPIKeyProvisioner(t *testing.T) {
1313
"default": {
1414
ItemFields: map[sdk.FieldName]string{
1515
fieldname.APIKey: "XFIx85McyfCQc490j1tBa5b5s2XiWerNdOdfnkrOnchEXAMPLE",
16-
fieldname.APIKeyID: "testdemoname",
1716
},
1817
ExpectedOutput: sdk.ProvisionOutput{
1918
Environment: map[string]string{
2019
"CIVO_TOKEN": "XFIx85McyfCQc490j1tBa5b5s2XiWerNdOdfnkrOnchEXAMPLE",
21-
"CIVO_API_KEY": "XFIx85McyfCQc490j1tBa5b5s2XiWerNdOdfnkrOnchEXAMPLE",
22-
"CIVO_API_KEY_NAME": "testdemoname",
2320
},
2421
},
2522
},
@@ -55,7 +52,6 @@ func TestAPIKeyImporter(t *testing.T) {
5552
Fields: map[sdk.FieldName]string{
5653
fieldname.APIKey: "XFIx85McyfCQc490j1tBa5b5s2XiWerNdOdfnkrOnchEXAMPLE",
5754
fieldname.APIKeyID: "testdemoname",
58-
fieldname.DefaultRegion: "LON1",
5955
},
6056
},
6157
},

plugins/civo/civo.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ func CivoCLI() schema.Executable {
1111
return schema.Executable{
1212
Name: "Civo CLI",
1313
Runs: []string{"civo"},
14-
DocsURL: sdk.URL("https://civo.com/docs/cli"),
14+
DocsURL: sdk.URL("https://www.civo.com/docs/overview/civo-cli"),
1515
NeedsAuth: needsauth.IfAll(
1616
needsauth.NotForHelpOrVersion(),
1717
needsauth.NotWithoutArgs(),
18-
needsauth.NotWhenContainsArgs("update"),
18+
needsauth.NotForExactArgs("config"),
19+
needsauth.NotWhenContainsArgs("apikey", "save"),
1920
),
2021
Uses: []schema.CredentialUsage{
2122
{

plugins/civo/plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func New() schema.Plugin {
1010
Name: "civo",
1111
Platform: schema.PlatformInfo{
1212
Name: "Civo",
13-
Homepage: sdk.URL("https://civo.com"),
13+
Homepage: sdk.URL("https://www.civo.com"),
1414
},
1515
Credentials: []schema.CredentialType{
1616
APIKey(),
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
{
22
"apikeys": {
3-
"newspidey": "XFIx85McyfCQc490j1tBa5b5s2XiWerNdOdfnkrOnchEXAMPLE"
4-
},
5-
"meta": {
6-
7-
"current_apikey": "newspidey1",
8-
"default_region": "LON1"
9-
3+
"testdemoname": "XFIx85McyfCQc490j1tBa5b5s2XiWerNdOdfnkrOnchEXAMPLE"
104
}
11-
}
5+
}

0 commit comments

Comments
 (0)