From 52856668845a0ad6bdb2f5fa64aba5ae7ce533a7 Mon Sep 17 00:00:00 2001 From: parthiv11 Date: Sat, 24 Jun 2023 11:54:43 +0530 Subject: [PATCH 1/9] Added Scaleway plugin code from old --- plugins/scaleway/api_key.go | 138 +++++++++++++++++++ plugins/scaleway/api_key_test.go | 79 +++++++++++ plugins/scaleway/plugin.go | 22 +++ plugins/scaleway/scw.go | 27 ++++ plugins/scaleway/test-fixtures/optional.yaml | 6 + plugins/scaleway/test-fixtures/simple.yaml | 3 + 6 files changed, 275 insertions(+) create mode 100644 plugins/scaleway/api_key.go create mode 100644 plugins/scaleway/api_key_test.go create mode 100644 plugins/scaleway/plugin.go create mode 100644 plugins/scaleway/scw.go create mode 100644 plugins/scaleway/test-fixtures/optional.yaml create mode 100644 plugins/scaleway/test-fixtures/simple.yaml diff --git a/plugins/scaleway/api_key.go b/plugins/scaleway/api_key.go new file mode 100644 index 000000000..c03cf1859 --- /dev/null +++ b/plugins/scaleway/api_key.go @@ -0,0 +1,138 @@ +package scaleway + +import ( + "context" + "os" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/importer" + "github.com/1Password/shell-plugins/sdk/provision" + "github.com/1Password/shell-plugins/sdk/schema" + "github.com/1Password/shell-plugins/sdk/schema/credname" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +func APIKey() schema.CredentialType { + return schema.CredentialType{ + Name: credname.APIKey, + DocsURL: sdk.URL("https://www.scaleway.com/en/docs/identity-and-access-management/iam/how-to/create-api-keys"), + ManagementURL: sdk.URL("https://console.scaleway.com/iam/api-keys"), + Fields: []schema.CredentialField{ + { + Name: fieldname.AccessKeyID, + MarkdownDescription: "The ID of the API Key used to authenticate to Scaleway.", + Secret: false, + Composition: &schema.ValueComposition{ + Length: 20, + Prefix: "SCW", + Charset: schema.Charset{ + Uppercase: true, + Digits: true, + }, + }, + }, + { + Name: fieldname.SecretAccessKey, + MarkdownDescription: "The secret access key used to authenticate to Scaleway.", + Secret: true, + Composition: &schema.ValueComposition{ + Length: 36, + Charset: schema.Charset{ + Lowercase: true, + Digits: true, + Specific: []rune{'-'}, + }, + }, + }, + { + Name: fieldname.DefaultOrganization, + MarkdownDescription: "The default organization ID to use for this access key.", + Secret: false, + Composition: &schema.ValueComposition{ + Length: 36, + Charset: schema.Charset{ + Lowercase: true, + Digits: true, + Specific: []rune{'-'}, + }, + }, + }, + { + Name: fieldname.DefaultRegion, + MarkdownDescription: "The default region to use for this access key.", + Optional: true, + }, + { + Name: fieldname.DefaultZone, + MarkdownDescription: "The default zone to use for this access key.", + Optional: true, + }, + }, + DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), + Importer: importer.TryAll( + importer.TryEnvVarPair(defaultEnvVarMapping), + TryScalewayConfigFile(), + )} +} + +var defaultEnvVarMapping = map[string]sdk.FieldName{ + "SCW_ACCESS_KEY": fieldname.AccessKeyID, + "SCW_SECRET_KEY": fieldname.SecretAccessKey, + "SCW_DEFAULT_ORGANIZATION_ID": fieldname.DefaultOrganization, + "SCW_DEFAULT_REGION": fieldname.DefaultRegion, + "SCW_DEFAULT_ZONE": fieldname.DefaultZone, +} + +func TryScalewayConfigFile() sdk.Importer { + file := os.Getenv("SCW_CONFIG_PATH") + if file == "" { + file = "~/.config/scw/config.yaml" + } + return importer.TryFile(file, func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) { + var config Config + if err := contents.ToYAML(&config); err != nil { + out.AddError(err) + return + } + + // TODO : Handle multiple profiles + + if config.AccessKey == "" || config.SecretKey == "" { + return + } + + fields := make(map[sdk.FieldName]string) + fields[fieldname.AccessKeyID] = config.AccessKey + fields[fieldname.SecretAccessKey] = config.SecretKey + fields[fieldname.DefaultOrganization] = config.DefaultOrganizationID + if config.DefaultRegion != "" { + fields[fieldname.DefaultRegion] = config.DefaultRegion + } + if config.DefaultZone != "" { + fields[fieldname.DefaultZone] = config.DefaultZone + } + out.AddCandidate(sdk.ImportCandidate{ + Fields: fields, + }) + }) +} + +type Config struct { + AccessKey string `yaml:"access_key"` + SecretKey string `yaml:"secret_key"` + DefaultOrganizationID string `yaml:"default_organization_id"` + DefaultProjectID string `yaml:"default_project_id"` + DefaultRegion string `yaml:"default_region"` + DefaultZone string `yaml:"default_zone"` + ActiveProfile string `yaml:"active_profile,omitempty"` + Profiles map[string]Profil `yaml:"profiles,omitempty"` +} + +type Profil struct { + AccessKey string `yaml:"access_key"` + SecretKey string `yaml:"secret_key"` + DefaultOrganizationID string `yaml:"default_organization_id"` + DefaultProjectID string `yaml:"default_project_id"` + DefaultZone string `yaml:"default_zone"` + DefaultRegion string `yaml:"default_region"` +} diff --git a/plugins/scaleway/api_key_test.go b/plugins/scaleway/api_key_test.go new file mode 100644 index 000000000..657bf1809 --- /dev/null +++ b/plugins/scaleway/api_key_test.go @@ -0,0 +1,79 @@ +package scaleway + +import ( + "testing" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/plugintest" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +func TestAPIKeyImporter(t *testing.T) { + plugintest.TestImporter(t, APIKey().Importer, map[string]plugintest.ImportCase{ + "Environment variables": { + Environment: map[string]string{ + "SCW_ACCESS_KEY": "SCWSYXTFI97NSEXAMPLE", + "SCW_SECRET_KEY": "d9b67b48-873c-8ece-8270-e1e15example", + "SCW_DEFAULT_ORGANIZATION_ID": "11111111-2222-3333-4444-55555example", + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.AccessKeyID: "SCWSYXTFI97NSEXAMPLE", + fieldname.SecretAccessKey: "d9b67b48-873c-8ece-8270-e1e15example", + fieldname.DefaultOrganization: "11111111-2222-3333-4444-55555example", + }, + }, + }, + }, + "SCW default config file location": { + Files: map[string]string{ + "~/.config/scw/config.yaml": plugintest.LoadFixture(t, "simple.yaml"), + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.AccessKeyID: "SCWSYXTFI97NSEXAMPLE", + fieldname.SecretAccessKey: "d9b67b48-873c-8ece-8270-e1e15example", + fieldname.DefaultOrganization: "11111111-2222-3333-4444-55555example", + }, + }, + }, + }, + "SCW config file with optional settings": { + Files: map[string]string{ + "~/.config/scw/config.yaml": plugintest.LoadFixture(t, "optional.yaml"), + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.AccessKeyID: "SCWSYXTFI97NSEXAMPLE", + fieldname.SecretAccessKey: "d9b67b48-873c-8ece-8270-e1e15example", + fieldname.DefaultOrganization: "11111111-2222-3333-4444-55555example", + fieldname.DefaultRegion: "fr-par", + fieldname.DefaultZone: "fr-par-1", + }, + }, + }, + }, + }) +} + +func TestAPIKeyProvisioner(t *testing.T) { + plugintest.TestProvisioner(t, APIKey().DefaultProvisioner, map[string]plugintest.ProvisionCase{ + "default": { + ItemFields: map[sdk.FieldName]string{ + fieldname.AccessKeyID: "SCWSYXTFI97NSEXAMPLE", + fieldname.SecretAccessKey: "d9b67b48-873c-8ece-8270-e1e15example", + fieldname.DefaultOrganization: "11111111-2222-3333-4444-55555example", + }, + ExpectedOutput: sdk.ProvisionOutput{ + Environment: map[string]string{ + "SCW_ACCESS_KEY": "SCWSYXTFI97NSEXAMPLE", + "SCW_SECRET_KEY": "d9b67b48-873c-8ece-8270-e1e15example", + "SCW_DEFAULT_ORGANIZATION_ID": "11111111-2222-3333-4444-55555example", + }, + }, + }, + }) +} diff --git a/plugins/scaleway/plugin.go b/plugins/scaleway/plugin.go new file mode 100644 index 000000000..23f3b4d25 --- /dev/null +++ b/plugins/scaleway/plugin.go @@ -0,0 +1,22 @@ +package scaleway + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/schema" +) + +func New() schema.Plugin { + return schema.Plugin{ + Name: "scaleway", + Platform: schema.PlatformInfo{ + Name: "Scaleway", + Homepage: sdk.URL("https://scaleway.com"), + }, + Credentials: []schema.CredentialType{ + APIKey(), + }, + Executables: []schema.Executable{ + ScalewayCLI(), + }, + } +} diff --git a/plugins/scaleway/scw.go b/plugins/scaleway/scw.go new file mode 100644 index 000000000..c94ae86aa --- /dev/null +++ b/plugins/scaleway/scw.go @@ -0,0 +1,27 @@ +package scaleway + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/needsauth" + "github.com/1Password/shell-plugins/sdk/schema" + "github.com/1Password/shell-plugins/sdk/schema/credname" +) + +func ScalewayCLI() schema.Executable { + return schema.Executable{ + Name: "Scaleway CLI", + Runs: []string{"scw"}, + DocsURL: sdk.URL("https://www.scaleway.com/en/cli"), + NeedsAuth: needsauth.IfAll( + needsauth.NotForHelpOrVersion(), + needsauth.NotWithoutArgs(), + needsauth.NotWhenContainsArgs("-c"), + needsauth.NotWhenContainsArgs("--config"), + ), + Uses: []schema.CredentialUsage{ + { + Name: credname.APIKey, + }, + }, + } +} diff --git a/plugins/scaleway/test-fixtures/optional.yaml b/plugins/scaleway/test-fixtures/optional.yaml new file mode 100644 index 000000000..73b4e51c2 --- /dev/null +++ b/plugins/scaleway/test-fixtures/optional.yaml @@ -0,0 +1,6 @@ +--- +access_key: SCWSYXTFI97NSEXAMPLE +secret_key: d9b67b48-873c-8ece-8270-e1e15example +default_organization_id: 11111111-2222-3333-4444-55555example +default_region: fr-par +default_zone: fr-par-1 diff --git a/plugins/scaleway/test-fixtures/simple.yaml b/plugins/scaleway/test-fixtures/simple.yaml new file mode 100644 index 000000000..ce0b02001 --- /dev/null +++ b/plugins/scaleway/test-fixtures/simple.yaml @@ -0,0 +1,3 @@ +access_key: SCWSYXTFI97NSEXAMPLE +secret_key: d9b67b48-873c-8ece-8270-e1e15example +default_organization_id: 11111111-2222-3333-4444-55555example From bc0a2a25da465ce5402a9084b6c20360ff98f1a2 Mon Sep 17 00:00:00 2001 From: parthiv11 Date: Fri, 30 Jun 2023 12:09:29 +0530 Subject: [PATCH 2/9] Changes made as Suggested by Maintainer --- plugins/scaleway/api_key.go | 7 +-- sdk/schema/fieldname/names.go | 98 ++++++++++++++++------------------- 2 files changed, 49 insertions(+), 56 deletions(-) diff --git a/plugins/scaleway/api_key.go b/plugins/scaleway/api_key.go index c03cf1859..997e7efc8 100644 --- a/plugins/scaleway/api_key.go +++ b/plugins/scaleway/api_key.go @@ -95,7 +95,6 @@ func TryScalewayConfigFile() sdk.Importer { return } - // TODO : Handle multiple profiles if config.AccessKey == "" || config.SecretKey == "" { return @@ -104,7 +103,9 @@ func TryScalewayConfigFile() sdk.Importer { fields := make(map[sdk.FieldName]string) fields[fieldname.AccessKeyID] = config.AccessKey fields[fieldname.SecretAccessKey] = config.SecretKey + if config.DefaultOrganizationID != "" { fields[fieldname.DefaultOrganization] = config.DefaultOrganizationID + } if config.DefaultRegion != "" { fields[fieldname.DefaultRegion] = config.DefaultRegion } @@ -125,10 +126,10 @@ type Config struct { DefaultRegion string `yaml:"default_region"` DefaultZone string `yaml:"default_zone"` ActiveProfile string `yaml:"active_profile,omitempty"` - Profiles map[string]Profil `yaml:"profiles,omitempty"` + Profiles map[string]Profile `yaml:"profiles,omitempty"` } -type Profil struct { +type Profile struct { AccessKey string `yaml:"access_key"` SecretKey string `yaml:"secret_key"` DefaultOrganizationID string `yaml:"default_organization_id"` diff --git a/sdk/schema/fieldname/names.go b/sdk/schema/fieldname/names.go index d227bc1a8..a1164f234 100644 --- a/sdk/schema/fieldname/names.go +++ b/sdk/schema/fieldname/names.go @@ -4,53 +4,48 @@ import "github.com/1Password/shell-plugins/sdk" // Credential field names. const ( - APIHost = sdk.FieldName("API Host") - APIKey = sdk.FieldName("API Key") - APIKeyID = sdk.FieldName("API Key ID") - APISecret = sdk.FieldName("API Secret") - AccessKeyID = sdk.FieldName("Access Key ID") - AccessToken = sdk.FieldName("Access Token") - Account = sdk.FieldName("Account") - AccountID = sdk.FieldName("Account ID") - AccountSID = sdk.FieldName("Account SID") - Address = sdk.FieldName("Address") - AppKey = sdk.FieldName("App Key") - AppSecret = sdk.FieldName("App Secret") - AppToken = sdk.FieldName("App Token") - AuthToken = sdk.FieldName("Auth Token") - Authtoken = sdk.FieldName("Authtoken") - Cert = sdk.FieldName("Cert") - Certificate = sdk.FieldName("Certificate") - ClientSecret = sdk.FieldName("Client Secret") - ClientToken = sdk.FieldName("Client Token") - Credential = sdk.FieldName("Credential") - Credentials = sdk.FieldName("Credentials") - Database = sdk.FieldName("Database") - DefaultRegion = sdk.FieldName("Default Region") - Email = sdk.FieldName("Email") - Endpoint = sdk.FieldName("Endpoint") - Host = sdk.FieldName("Host") - HostAddress = sdk.FieldName("Host Address") - Key = sdk.FieldName("Key") - MFASerial = sdk.FieldName("MFA Serial") - Mode = sdk.FieldName("Mode") - Namespace = sdk.FieldName("Namespace") - OneTimePassword = sdk.FieldName("One-Time Password") - OrgURL = sdk.FieldName("Org URL") - Organization = sdk.FieldName("Organization") - Password = sdk.FieldName("Password") - Port = sdk.FieldName("Port") - PublicKey = sdk.FieldName("Public Key") - PrivateKey = sdk.FieldName("Private Key") - Region = sdk.FieldName("Region") - Secret = sdk.FieldName("Secret") - SecretAccessKey = sdk.FieldName("Secret Access Key") - Subdomain = sdk.FieldName("Subdomain") - Token = sdk.FieldName("Token") - URL = sdk.FieldName("URL") - User = sdk.FieldName("User") - Username = sdk.FieldName("Username") - Website = sdk.FieldName("Website") + APIHost = sdk.FieldName("API Host") + APIKey = sdk.FieldName("API Key") + APIKeyID = sdk.FieldName("API Key ID") + APISecret = sdk.FieldName("API Secret") + AccessKeyID = sdk.FieldName("Access Key ID") + Account = sdk.FieldName("Account") + AccountID = sdk.FieldName("Account ID") + AccountSID = sdk.FieldName("Account SID") + Address = sdk.FieldName("Address") + AppKey = sdk.FieldName("App Key") + AppSecret = sdk.FieldName("App Secret") + AppToken = sdk.FieldName("App Token") + AuthToken = sdk.FieldName("Auth Token") + Cert = sdk.FieldName("Cert") + Certificate = sdk.FieldName("Certificate") + Credential = sdk.FieldName("Credential") + Credentials = sdk.FieldName("Credentials") + Database = sdk.FieldName("Database") + DefaultOrganization = sdk.FieldName("Default Organization") + DefaultRegion = sdk.FieldName("Default Region") + DefaultZone = sdk.FieldName("Default Zone") + Endpoint = sdk.FieldName("Endpoint") + Host = sdk.FieldName("Host") + HostAddress = sdk.FieldName("Host Address") + Key = sdk.FieldName("Key") + MFASerial = sdk.FieldName("MFA Serial") + Mode = sdk.FieldName("Mode") + Namespace = sdk.FieldName("Namespace") + OneTimePassword = sdk.FieldName("One-Time Password") + OrgURL = sdk.FieldName("Org URL") + Organization = sdk.FieldName("Organization") + Password = sdk.FieldName("Password") + Port = sdk.FieldName("Port") + PrivateKey = sdk.FieldName("Private Key") + Region = sdk.FieldName("Region") + Secret = sdk.FieldName("Secret") + SecretAccessKey = sdk.FieldName("Secret Access Key") + Token = sdk.FieldName("Token") + URL = sdk.FieldName("URL") + User = sdk.FieldName("User") + Username = sdk.FieldName("Username") + Website = sdk.FieldName("Website") ) func ListAll() []sdk.FieldName { @@ -60,7 +55,6 @@ func ListAll() []sdk.FieldName { APIKeyID, APISecret, AccessKeyID, - AccessToken, Account, AccountID, AccountSID, @@ -69,15 +63,14 @@ func ListAll() []sdk.FieldName { AppSecret, AppToken, AuthToken, - Authtoken, Cert, Certificate, - ClientSecret, - ClientToken, Credential, Credentials, Database, + DefaultOrganization, DefaultRegion, + DefaultZone, Endpoint, Host, HostAddress, @@ -90,7 +83,6 @@ func ListAll() []sdk.FieldName { Organization, Password, Port, - PublicKey, PrivateKey, Region, Secret, @@ -101,4 +93,4 @@ func ListAll() []sdk.FieldName { Username, Website, } -} +} \ No newline at end of file From 28475e73574ff4423a7d172d34d24ece34d43fff Mon Sep 17 00:00:00 2001 From: parthiv11 Date: Fri, 30 Jun 2023 12:13:56 +0530 Subject: [PATCH 3/9] Changes made as Suggested by Maintainer --- plugins/scaleway/api_key.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/plugins/scaleway/api_key.go b/plugins/scaleway/api_key.go index 997e7efc8..617308191 100644 --- a/plugins/scaleway/api_key.go +++ b/plugins/scaleway/api_key.go @@ -125,15 +125,5 @@ type Config struct { DefaultProjectID string `yaml:"default_project_id"` DefaultRegion string `yaml:"default_region"` DefaultZone string `yaml:"default_zone"` - ActiveProfile string `yaml:"active_profile,omitempty"` - Profiles map[string]Profile `yaml:"profiles,omitempty"` } -type Profile struct { - AccessKey string `yaml:"access_key"` - SecretKey string `yaml:"secret_key"` - DefaultOrganizationID string `yaml:"default_organization_id"` - DefaultProjectID string `yaml:"default_project_id"` - DefaultZone string `yaml:"default_zone"` - DefaultRegion string `yaml:"default_region"` -} From 1237d896520bb2da87d115c3b218018d9d487e8b Mon Sep 17 00:00:00 2001 From: parthiv11 Date: Fri, 30 Jun 2023 12:52:13 +0530 Subject: [PATCH 4/9] DefaultOrganization DefaultZone added to fieldname/names.go --- sdk/schema/fieldname/names.go | 98 ++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 43 deletions(-) diff --git a/sdk/schema/fieldname/names.go b/sdk/schema/fieldname/names.go index a1164f234..c7eb50a93 100644 --- a/sdk/schema/fieldname/names.go +++ b/sdk/schema/fieldname/names.go @@ -4,48 +4,55 @@ import "github.com/1Password/shell-plugins/sdk" // Credential field names. const ( - APIHost = sdk.FieldName("API Host") - APIKey = sdk.FieldName("API Key") - APIKeyID = sdk.FieldName("API Key ID") - APISecret = sdk.FieldName("API Secret") - AccessKeyID = sdk.FieldName("Access Key ID") - Account = sdk.FieldName("Account") - AccountID = sdk.FieldName("Account ID") - AccountSID = sdk.FieldName("Account SID") - Address = sdk.FieldName("Address") - AppKey = sdk.FieldName("App Key") - AppSecret = sdk.FieldName("App Secret") - AppToken = sdk.FieldName("App Token") - AuthToken = sdk.FieldName("Auth Token") - Cert = sdk.FieldName("Cert") - Certificate = sdk.FieldName("Certificate") - Credential = sdk.FieldName("Credential") - Credentials = sdk.FieldName("Credentials") - Database = sdk.FieldName("Database") - DefaultOrganization = sdk.FieldName("Default Organization") - DefaultRegion = sdk.FieldName("Default Region") - DefaultZone = sdk.FieldName("Default Zone") - Endpoint = sdk.FieldName("Endpoint") - Host = sdk.FieldName("Host") - HostAddress = sdk.FieldName("Host Address") - Key = sdk.FieldName("Key") - MFASerial = sdk.FieldName("MFA Serial") - Mode = sdk.FieldName("Mode") - Namespace = sdk.FieldName("Namespace") - OneTimePassword = sdk.FieldName("One-Time Password") - OrgURL = sdk.FieldName("Org URL") - Organization = sdk.FieldName("Organization") - Password = sdk.FieldName("Password") - Port = sdk.FieldName("Port") - PrivateKey = sdk.FieldName("Private Key") - Region = sdk.FieldName("Region") - Secret = sdk.FieldName("Secret") - SecretAccessKey = sdk.FieldName("Secret Access Key") - Token = sdk.FieldName("Token") - URL = sdk.FieldName("URL") - User = sdk.FieldName("User") - Username = sdk.FieldName("Username") - Website = sdk.FieldName("Website") + APIHost = sdk.FieldName("API Host") + APIKey = sdk.FieldName("API Key") + APIKeyID = sdk.FieldName("API Key ID") + APISecret = sdk.FieldName("API Secret") + AccessKeyID = sdk.FieldName("Access Key ID") + AccessToken = sdk.FieldName("Access Token") + Account = sdk.FieldName("Account") + AccountID = sdk.FieldName("Account ID") + AccountSID = sdk.FieldName("Account SID") + Address = sdk.FieldName("Address") + AppKey = sdk.FieldName("App Key") + AppSecret = sdk.FieldName("App Secret") + AppToken = sdk.FieldName("App Token") + AuthToken = sdk.FieldName("Auth Token") + Authtoken = sdk.FieldName("Authtoken") + Cert = sdk.FieldName("Cert") + Certificate = sdk.FieldName("Certificate") + ClientSecret = sdk.FieldName("Client Secret") + ClientToken = sdk.FieldName("Client Token") + Credential = sdk.FieldName("Credential") + Credentials = sdk.FieldName("Credentials") + Database = sdk.FieldName("Database") + DefaultRegion = sdk.FieldName("Default Region") + DefaultOrganization = sdk.FieldName("Default Organization") + DefaultZone = sdk.FieldName("Default Zone") + Email = sdk.FieldName("Email") + Endpoint = sdk.FieldName("Endpoint") + Host = sdk.FieldName("Host") + HostAddress = sdk.FieldName("Host Address") + Key = sdk.FieldName("Key") + MFASerial = sdk.FieldName("MFA Serial") + Mode = sdk.FieldName("Mode") + Namespace = sdk.FieldName("Namespace") + OneTimePassword = sdk.FieldName("One-Time Password") + OrgURL = sdk.FieldName("Org URL") + Organization = sdk.FieldName("Organization") + Password = sdk.FieldName("Password") + Port = sdk.FieldName("Port") + PublicKey = sdk.FieldName("Public Key") + PrivateKey = sdk.FieldName("Private Key") + Region = sdk.FieldName("Region") + Secret = sdk.FieldName("Secret") + SecretAccessKey = sdk.FieldName("Secret Access Key") + Subdomain = sdk.FieldName("Subdomain") + Token = sdk.FieldName("Token") + URL = sdk.FieldName("URL") + User = sdk.FieldName("User") + Username = sdk.FieldName("Username") + Website = sdk.FieldName("Website") ) func ListAll() []sdk.FieldName { @@ -55,6 +62,7 @@ func ListAll() []sdk.FieldName { APIKeyID, APISecret, AccessKeyID, + AccessToken, Account, AccountID, AccountSID, @@ -63,13 +71,16 @@ func ListAll() []sdk.FieldName { AppSecret, AppToken, AuthToken, + Authtoken, Cert, Certificate, + ClientSecret, + ClientToken, Credential, Credentials, Database, - DefaultOrganization, DefaultRegion, + DefaultOrganization, DefaultZone, Endpoint, Host, @@ -83,6 +94,7 @@ func ListAll() []sdk.FieldName { Organization, Password, Port, + PublicKey, PrivateKey, Region, Secret, From b283ae7588f29a1a5eb0d3eb9eb4d19c3014e52c Mon Sep 17 00:00:00 2001 From: parthiv11 Date: Sat, 1 Jul 2023 01:01:21 +0530 Subject: [PATCH 5/9] Reformated sdk/schema/fieldname/names.go --- sdk/schema/fieldname/names.go | 96 +++++++++++++++++------------------ 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/sdk/schema/fieldname/names.go b/sdk/schema/fieldname/names.go index c7eb50a93..617af964b 100644 --- a/sdk/schema/fieldname/names.go +++ b/sdk/schema/fieldname/names.go @@ -4,55 +4,55 @@ import "github.com/1Password/shell-plugins/sdk" // Credential field names. const ( - APIHost = sdk.FieldName("API Host") - APIKey = sdk.FieldName("API Key") - APIKeyID = sdk.FieldName("API Key ID") - APISecret = sdk.FieldName("API Secret") - AccessKeyID = sdk.FieldName("Access Key ID") - AccessToken = sdk.FieldName("Access Token") - Account = sdk.FieldName("Account") - AccountID = sdk.FieldName("Account ID") - AccountSID = sdk.FieldName("Account SID") - Address = sdk.FieldName("Address") - AppKey = sdk.FieldName("App Key") - AppSecret = sdk.FieldName("App Secret") - AppToken = sdk.FieldName("App Token") - AuthToken = sdk.FieldName("Auth Token") - Authtoken = sdk.FieldName("Authtoken") - Cert = sdk.FieldName("Cert") - Certificate = sdk.FieldName("Certificate") - ClientSecret = sdk.FieldName("Client Secret") - ClientToken = sdk.FieldName("Client Token") - Credential = sdk.FieldName("Credential") - Credentials = sdk.FieldName("Credentials") - Database = sdk.FieldName("Database") - DefaultRegion = sdk.FieldName("Default Region") + APIHost = sdk.FieldName("API Host") + APIKey = sdk.FieldName("API Key") + APIKeyID = sdk.FieldName("API Key ID") + APISecret = sdk.FieldName("API Secret") + AccessKeyID = sdk.FieldName("Access Key ID") + AccessToken = sdk.FieldName("Access Token") + Account = sdk.FieldName("Account") + AccountID = sdk.FieldName("Account ID") + AccountSID = sdk.FieldName("Account SID") + Address = sdk.FieldName("Address") + AppKey = sdk.FieldName("App Key") + AppSecret = sdk.FieldName("App Secret") + AppToken = sdk.FieldName("App Token") + AuthToken = sdk.FieldName("Auth Token") + Authtoken = sdk.FieldName("Authtoken") + Cert = sdk.FieldName("Cert") + Certificate = sdk.FieldName("Certificate") + ClientSecret = sdk.FieldName("Client Secret") + ClientToken = sdk.FieldName("Client Token") + Credential = sdk.FieldName("Credential") + Credentials = sdk.FieldName("Credentials") + Database = sdk.FieldName("Database") + DefaultRegion = sdk.FieldName("Default Region") DefaultOrganization = sdk.FieldName("Default Organization") - DefaultZone = sdk.FieldName("Default Zone") - Email = sdk.FieldName("Email") - Endpoint = sdk.FieldName("Endpoint") - Host = sdk.FieldName("Host") - HostAddress = sdk.FieldName("Host Address") - Key = sdk.FieldName("Key") - MFASerial = sdk.FieldName("MFA Serial") - Mode = sdk.FieldName("Mode") - Namespace = sdk.FieldName("Namespace") - OneTimePassword = sdk.FieldName("One-Time Password") - OrgURL = sdk.FieldName("Org URL") - Organization = sdk.FieldName("Organization") - Password = sdk.FieldName("Password") - Port = sdk.FieldName("Port") - PublicKey = sdk.FieldName("Public Key") - PrivateKey = sdk.FieldName("Private Key") - Region = sdk.FieldName("Region") - Secret = sdk.FieldName("Secret") - SecretAccessKey = sdk.FieldName("Secret Access Key") - Subdomain = sdk.FieldName("Subdomain") - Token = sdk.FieldName("Token") - URL = sdk.FieldName("URL") - User = sdk.FieldName("User") - Username = sdk.FieldName("Username") - Website = sdk.FieldName("Website") + DefaultZone = sdk.FieldName("Default Zone") + Email = sdk.FieldName("Email") + Endpoint = sdk.FieldName("Endpoint") + Host = sdk.FieldName("Host") + HostAddress = sdk.FieldName("Host Address") + Key = sdk.FieldName("Key") + MFASerial = sdk.FieldName("MFA Serial") + Mode = sdk.FieldName("Mode") + Namespace = sdk.FieldName("Namespace") + OneTimePassword = sdk.FieldName("One-Time Password") + OrgURL = sdk.FieldName("Org URL") + Organization = sdk.FieldName("Organization") + Password = sdk.FieldName("Password") + Port = sdk.FieldName("Port") + PublicKey = sdk.FieldName("Public Key") + PrivateKey = sdk.FieldName("Private Key") + Region = sdk.FieldName("Region") + Secret = sdk.FieldName("Secret") + SecretAccessKey = sdk.FieldName("Secret Access Key") + Subdomain = sdk.FieldName("Subdomain") + Token = sdk.FieldName("Token") + URL = sdk.FieldName("URL") + User = sdk.FieldName("User") + Username = sdk.FieldName("Username") + Website = sdk.FieldName("Website") ) func ListAll() []sdk.FieldName { From 192a6857de4e517ccd798372f3eb1a904ec6c5db Mon Sep 17 00:00:00 2001 From: parthiv11 Date: Sat, 1 Jul 2023 01:27:13 +0530 Subject: [PATCH 6/9] formatted codebase --- plugins/scaleway/api_key.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/plugins/scaleway/api_key.go b/plugins/scaleway/api_key.go index 617308191..408065cf2 100644 --- a/plugins/scaleway/api_key.go +++ b/plugins/scaleway/api_key.go @@ -95,7 +95,6 @@ func TryScalewayConfigFile() sdk.Importer { return } - if config.AccessKey == "" || config.SecretKey == "" { return } @@ -104,7 +103,7 @@ func TryScalewayConfigFile() sdk.Importer { fields[fieldname.AccessKeyID] = config.AccessKey fields[fieldname.SecretAccessKey] = config.SecretKey if config.DefaultOrganizationID != "" { - fields[fieldname.DefaultOrganization] = config.DefaultOrganizationID + fields[fieldname.DefaultOrganization] = config.DefaultOrganizationID } if config.DefaultRegion != "" { fields[fieldname.DefaultRegion] = config.DefaultRegion @@ -119,11 +118,10 @@ func TryScalewayConfigFile() sdk.Importer { } type Config struct { - AccessKey string `yaml:"access_key"` - SecretKey string `yaml:"secret_key"` - DefaultOrganizationID string `yaml:"default_organization_id"` - DefaultProjectID string `yaml:"default_project_id"` - DefaultRegion string `yaml:"default_region"` - DefaultZone string `yaml:"default_zone"` + AccessKey string `yaml:"access_key"` + SecretKey string `yaml:"secret_key"` + DefaultOrganizationID string `yaml:"default_organization_id"` + DefaultProjectID string `yaml:"default_project_id"` + DefaultRegion string `yaml:"default_region"` + DefaultZone string `yaml:"default_zone"` } - From 7455ea37729e2afde2f055ac283a7f7683f53a23 Mon Sep 17 00:00:00 2001 From: parthiv11 Date: Tue, 11 Jul 2023 19:37:10 +0530 Subject: [PATCH 7/9] improved tests --- plugins/scaleway/api_key_test.go | 8 +++ sdk/schema/fieldname/names.go | 101 ++++++++++++++++--------------- 2 files changed, 59 insertions(+), 50 deletions(-) diff --git a/plugins/scaleway/api_key_test.go b/plugins/scaleway/api_key_test.go index 657bf1809..616121eca 100644 --- a/plugins/scaleway/api_key_test.go +++ b/plugins/scaleway/api_key_test.go @@ -15,6 +15,8 @@ func TestAPIKeyImporter(t *testing.T) { "SCW_ACCESS_KEY": "SCWSYXTFI97NSEXAMPLE", "SCW_SECRET_KEY": "d9b67b48-873c-8ece-8270-e1e15example", "SCW_DEFAULT_ORGANIZATION_ID": "11111111-2222-3333-4444-55555example", + "SCW_DEFAULT_REGION": "fr-par", + "SCW_DEFAULT_ZONE": "fr-par-1", }, ExpectedCandidates: []sdk.ImportCandidate{ { @@ -22,6 +24,8 @@ func TestAPIKeyImporter(t *testing.T) { fieldname.AccessKeyID: "SCWSYXTFI97NSEXAMPLE", fieldname.SecretAccessKey: "d9b67b48-873c-8ece-8270-e1e15example", fieldname.DefaultOrganization: "11111111-2222-3333-4444-55555example", + fieldname.DefaultRegion: "fr-par", + fieldname.DefaultZone: "fr-par-1", }, }, }, @@ -66,12 +70,16 @@ func TestAPIKeyProvisioner(t *testing.T) { fieldname.AccessKeyID: "SCWSYXTFI97NSEXAMPLE", fieldname.SecretAccessKey: "d9b67b48-873c-8ece-8270-e1e15example", fieldname.DefaultOrganization: "11111111-2222-3333-4444-55555example", + fieldname.DefaultRegion: "fr-par", + fieldname.DefaultZone: "fr-par-1", }, ExpectedOutput: sdk.ProvisionOutput{ Environment: map[string]string{ "SCW_ACCESS_KEY": "SCWSYXTFI97NSEXAMPLE", "SCW_SECRET_KEY": "d9b67b48-873c-8ece-8270-e1e15example", "SCW_DEFAULT_ORGANIZATION_ID": "11111111-2222-3333-4444-55555example", + "SCW_DEFAULT_REGION": "fr-par", + "SCW_DEFAULT_ZONE": "fr-par-1", }, }, }, diff --git a/sdk/schema/fieldname/names.go b/sdk/schema/fieldname/names.go index 617af964b..bad5be5d0 100644 --- a/sdk/schema/fieldname/names.go +++ b/sdk/schema/fieldname/names.go @@ -4,55 +4,55 @@ import "github.com/1Password/shell-plugins/sdk" // Credential field names. const ( - APIHost = sdk.FieldName("API Host") - APIKey = sdk.FieldName("API Key") - APIKeyID = sdk.FieldName("API Key ID") - APISecret = sdk.FieldName("API Secret") - AccessKeyID = sdk.FieldName("Access Key ID") - AccessToken = sdk.FieldName("Access Token") - Account = sdk.FieldName("Account") - AccountID = sdk.FieldName("Account ID") - AccountSID = sdk.FieldName("Account SID") - Address = sdk.FieldName("Address") - AppKey = sdk.FieldName("App Key") - AppSecret = sdk.FieldName("App Secret") - AppToken = sdk.FieldName("App Token") - AuthToken = sdk.FieldName("Auth Token") - Authtoken = sdk.FieldName("Authtoken") - Cert = sdk.FieldName("Cert") - Certificate = sdk.FieldName("Certificate") - ClientSecret = sdk.FieldName("Client Secret") - ClientToken = sdk.FieldName("Client Token") - Credential = sdk.FieldName("Credential") - Credentials = sdk.FieldName("Credentials") - Database = sdk.FieldName("Database") - DefaultRegion = sdk.FieldName("Default Region") - DefaultOrganization = sdk.FieldName("Default Organization") - DefaultZone = sdk.FieldName("Default Zone") - Email = sdk.FieldName("Email") - Endpoint = sdk.FieldName("Endpoint") - Host = sdk.FieldName("Host") - HostAddress = sdk.FieldName("Host Address") - Key = sdk.FieldName("Key") - MFASerial = sdk.FieldName("MFA Serial") - Mode = sdk.FieldName("Mode") - Namespace = sdk.FieldName("Namespace") - OneTimePassword = sdk.FieldName("One-Time Password") - OrgURL = sdk.FieldName("Org URL") - Organization = sdk.FieldName("Organization") - Password = sdk.FieldName("Password") - Port = sdk.FieldName("Port") - PublicKey = sdk.FieldName("Public Key") - PrivateKey = sdk.FieldName("Private Key") - Region = sdk.FieldName("Region") - Secret = sdk.FieldName("Secret") - SecretAccessKey = sdk.FieldName("Secret Access Key") - Subdomain = sdk.FieldName("Subdomain") - Token = sdk.FieldName("Token") - URL = sdk.FieldName("URL") - User = sdk.FieldName("User") - Username = sdk.FieldName("Username") - Website = sdk.FieldName("Website") + APIHost = sdk.FieldName("API Host") + APIKey = sdk.FieldName("API Key") + APIKeyID = sdk.FieldName("API Key ID") + APISecret = sdk.FieldName("API Secret") + AccessKeyID = sdk.FieldName("Access Key ID") + AccessToken = sdk.FieldName("Access Token") + Account = sdk.FieldName("Account") + AccountID = sdk.FieldName("Account ID") + AccountSID = sdk.FieldName("Account SID") + Address = sdk.FieldName("Address") + AppKey = sdk.FieldName("App Key") + AppSecret = sdk.FieldName("App Secret") + AppToken = sdk.FieldName("App Token") + AuthToken = sdk.FieldName("Auth Token") + Authtoken = sdk.FieldName("Authtoken") + Cert = sdk.FieldName("Cert") + Certificate = sdk.FieldName("Certificate") + ClientSecret = sdk.FieldName("Client Secret") + ClientToken = sdk.FieldName("Client Token") + Credential = sdk.FieldName("Credential") + Credentials = sdk.FieldName("Credentials") + Database = sdk.FieldName("Database") + DefaultRegion = sdk.FieldName("Default Region") + DefaultOrganization = sdk.FieldName("Default Organization") + DefaultZone = sdk.FieldName("Default Zone") + Email = sdk.FieldName("Email") + Endpoint = sdk.FieldName("Endpoint") + Host = sdk.FieldName("Host") + HostAddress = sdk.FieldName("Host Address") + Key = sdk.FieldName("Key") + MFASerial = sdk.FieldName("MFA Serial") + Mode = sdk.FieldName("Mode") + Namespace = sdk.FieldName("Namespace") + OneTimePassword = sdk.FieldName("One-Time Password") + OrgURL = sdk.FieldName("Org URL") + Organization = sdk.FieldName("Organization") + Password = sdk.FieldName("Password") + Port = sdk.FieldName("Port") + PublicKey = sdk.FieldName("Public Key") + PrivateKey = sdk.FieldName("Private Key") + Region = sdk.FieldName("Region") + Secret = sdk.FieldName("Secret") + SecretAccessKey = sdk.FieldName("Secret Access Key") + Subdomain = sdk.FieldName("Subdomain") + Token = sdk.FieldName("Token") + URL = sdk.FieldName("URL") + User = sdk.FieldName("User") + Username = sdk.FieldName("Username") + Website = sdk.FieldName("Website") ) func ListAll() []sdk.FieldName { @@ -105,4 +105,5 @@ func ListAll() []sdk.FieldName { Username, Website, } -} \ No newline at end of file + +} From 44db03448ff8e23252c440c39ad37dd8a3a342d9 Mon Sep 17 00:00:00 2001 From: parthiv11 Date: Sun, 16 Jul 2023 18:06:39 +0530 Subject: [PATCH 8/9] Some updates --- plugins/scaleway/api_key.go | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/plugins/scaleway/api_key.go b/plugins/scaleway/api_key.go index 408065cf2..e8be89601 100644 --- a/plugins/scaleway/api_key.go +++ b/plugins/scaleway/api_key.go @@ -112,16 +112,45 @@ func TryScalewayConfigFile() sdk.Importer { fields[fieldname.DefaultZone] = config.DefaultZone } out.AddCandidate(sdk.ImportCandidate{ - Fields: fields, + Fields: fields, + NameHint: importer.SanitizeNameHint("default"), }) + + for profileName, profile := range config.Profiles { + profileFields := make(map[sdk.FieldName]string) + profileFields[fieldname.AccessKeyID] = profile.AccessKey + profileFields[fieldname.SecretAccessKey] = profile.SecretKey + if profile.DefaultOrganizationID != "" { + profileFields[fieldname.DefaultOrganization] = profile.DefaultOrganizationID + } + if profile.DefaultRegion != "" { + profileFields[fieldname.DefaultRegion] = profile.DefaultRegion + } + if profile.DefaultZone != "" { + profileFields[fieldname.DefaultZone] = profile.DefaultZone + } + + out.AddCandidate(sdk.ImportCandidate{ + Fields: profileFields, + NameHint: importer.SanitizeNameHint(profileName), + }) + } }) } type Config struct { + AccessKey string `yaml:"access_key"` + SecretKey string `yaml:"secret_key"` + DefaultOrganizationID string `yaml:"default_organization_id"` + DefaultRegion string `yaml:"default_region"` + DefaultZone string `yaml:"default_zone"` + Profiles map[string]Profile `yaml:"profiles"` +} + +type Profile struct { AccessKey string `yaml:"access_key"` SecretKey string `yaml:"secret_key"` DefaultOrganizationID string `yaml:"default_organization_id"` - DefaultProjectID string `yaml:"default_project_id"` DefaultRegion string `yaml:"default_region"` DefaultZone string `yaml:"default_zone"` } From be57756b7a359b82334f9bf23b6409d406fa9040 Mon Sep 17 00:00:00 2001 From: parthiv11 Date: Sun, 16 Jul 2023 18:19:21 +0530 Subject: [PATCH 9/9] Updated config import --- plugins/scaleway/api_key.go | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/plugins/scaleway/api_key.go b/plugins/scaleway/api_key.go index e8be89601..4ac6d54fe 100644 --- a/plugins/scaleway/api_key.go +++ b/plugins/scaleway/api_key.go @@ -95,27 +95,6 @@ func TryScalewayConfigFile() sdk.Importer { return } - if config.AccessKey == "" || config.SecretKey == "" { - return - } - - fields := make(map[sdk.FieldName]string) - fields[fieldname.AccessKeyID] = config.AccessKey - fields[fieldname.SecretAccessKey] = config.SecretKey - if config.DefaultOrganizationID != "" { - fields[fieldname.DefaultOrganization] = config.DefaultOrganizationID - } - if config.DefaultRegion != "" { - fields[fieldname.DefaultRegion] = config.DefaultRegion - } - if config.DefaultZone != "" { - fields[fieldname.DefaultZone] = config.DefaultZone - } - out.AddCandidate(sdk.ImportCandidate{ - Fields: fields, - NameHint: importer.SanitizeNameHint("default"), - }) - for profileName, profile := range config.Profiles { profileFields := make(map[sdk.FieldName]string) profileFields[fieldname.AccessKeyID] = profile.AccessKey @@ -139,11 +118,6 @@ func TryScalewayConfigFile() sdk.Importer { } type Config struct { - AccessKey string `yaml:"access_key"` - SecretKey string `yaml:"secret_key"` - DefaultOrganizationID string `yaml:"default_organization_id"` - DefaultRegion string `yaml:"default_region"` - DefaultZone string `yaml:"default_zone"` Profiles map[string]Profile `yaml:"profiles"` }