@@ -2,9 +2,8 @@ package civo
22
33import (
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
5147var 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
9482type 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}
0 commit comments