From a20372d15c035204a56deff7c82c1b6ccd6e422e Mon Sep 17 00:00:00 2001 From: Simon Walker Date: Wed, 14 Feb 2024 14:41:36 +0000 Subject: [PATCH 1/2] Update localstack plugin to use LOCALSTACK_AUTH_TOKEN --- plugins/localstack/api_key.go | 3 +- plugins/localstack/auth_token.go | 37 ++++++++++++++++++++++++ plugins/localstack/auth_token_test.go | 41 +++++++++++++++++++++++++++ plugins/localstack/localstack.go | 2 +- plugins/localstack/plugin.go | 5 +++- 5 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 plugins/localstack/auth_token.go create mode 100644 plugins/localstack/auth_token_test.go diff --git a/plugins/localstack/api_key.go b/plugins/localstack/api_key.go index 5b168a054..c37b8bfff 100644 --- a/plugins/localstack/api_key.go +++ b/plugins/localstack/api_key.go @@ -36,5 +36,6 @@ func APIKey() schema.CredentialType { } var defaultEnvVarMapping = map[string]sdk.FieldName{ - "LOCALSTACK_API_KEY": fieldname.APIKey, + "LOCALSTACK_API_KEY": fieldname.APIKey, + "LOCALSTACK_AUTH_TOKEN": fieldname.AuthToken, } diff --git a/plugins/localstack/auth_token.go b/plugins/localstack/auth_token.go new file mode 100644 index 000000000..285da9060 --- /dev/null +++ b/plugins/localstack/auth_token.go @@ -0,0 +1,37 @@ +package localstack + +import ( + "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 AuthToken() schema.CredentialType { + return schema.CredentialType{ + Name: credname.AuthToken, + DocsURL: sdk.URL("https://docs.localstack.cloud/getting-started/auth-token/"), + ManagementURL: sdk.URL("https://app.localstack.cloud/workspace/auth-token"), + Fields: []schema.CredentialField{ + { + Name: fieldname.AuthToken, + MarkdownDescription: "Auth token used to authenticate to LocalStack.", + Secret: true, + Composition: &schema.ValueComposition{ + Length: 39, + Charset: schema.Charset{ + Uppercase: true, + Lowercase: true, + Digits: true, + Specific: []rune{'-'}, + }, + }, + }, + }, + DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), + Importer: importer.TryAll( + importer.TryEnvVarPair(defaultEnvVarMapping), + )} +} diff --git a/plugins/localstack/auth_token_test.go b/plugins/localstack/auth_token_test.go new file mode 100644 index 000000000..c2ebcc57e --- /dev/null +++ b/plugins/localstack/auth_token_test.go @@ -0,0 +1,41 @@ +package localstack + +import ( + "testing" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/plugintest" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +func TestAuthTokenProvisioner(t *testing.T) { + plugintest.TestProvisioner(t, AuthToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{ + "default": { + ItemFields: map[sdk.FieldName]string{ + fieldname.AuthToken: "ls-02b523ae-52f2-4905-b46a-0a7d7c2947aa", + }, + ExpectedOutput: sdk.ProvisionOutput{ + Environment: map[string]string{ + "LOCALSTACK_AUTH_TOKEN": "ls-02b523ae-52f2-4905-b46a-0a7d7c2947aa", + }, + }, + }, + }) +} + +func TestAuthTokenImporter(t *testing.T) { + plugintest.TestImporter(t, AuthToken().Importer, map[string]plugintest.ImportCase{ + "environment": { + Environment: map[string]string{ + "LOCALSTACK_AUTH_TOKEN": "ls-02b523ae-52f2-4905-b46a-0a7d7c2947aa", + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.AuthToken: "ls-02b523ae-52f2-4905-b46a-0a7d7c2947aa", + }, + }, + }, + }, + }) +} diff --git a/plugins/localstack/localstack.go b/plugins/localstack/localstack.go index 07337a253..4a1dad63a 100644 --- a/plugins/localstack/localstack.go +++ b/plugins/localstack/localstack.go @@ -18,7 +18,7 @@ func LocalStackCLI() schema.Executable { ), Uses: []schema.CredentialUsage{ { - Name: credname.APIKey, + Name: credname.AuthToken, }, }, } diff --git a/plugins/localstack/plugin.go b/plugins/localstack/plugin.go index d588dff29..233f7dc7b 100644 --- a/plugins/localstack/plugin.go +++ b/plugins/localstack/plugin.go @@ -12,8 +12,11 @@ func New() schema.Plugin { Name: "LocalStack", Homepage: sdk.URL("https://localstack.cloud"), }, + // TODO: LocalStack accepts both auth token and api key. When multiple + // credentials types are supported, update this list to include both + // options. Credentials: []schema.CredentialType{ - APIKey(), + AuthToken(), }, Executables: []schema.Executable{ LocalStackCLI(), From e3d1768de76535d6a169b29312d03f214d05fda5 Mon Sep 17 00:00:00 2001 From: Simon Walker Date: Mon, 29 Jun 2026 20:05:00 +0100 Subject: [PATCH 2/2] Only support auth tokens --- plugins/localstack/api_key.go | 41 ------------------------------ plugins/localstack/api_key_test.go | 41 ------------------------------ plugins/localstack/auth_token.go | 5 ++++ plugins/localstack/localstack.go | 1 + plugins/localstack/plugin.go | 3 --- 5 files changed, 6 insertions(+), 85 deletions(-) delete mode 100644 plugins/localstack/api_key.go delete mode 100644 plugins/localstack/api_key_test.go diff --git a/plugins/localstack/api_key.go b/plugins/localstack/api_key.go deleted file mode 100644 index c37b8bfff..000000000 --- a/plugins/localstack/api_key.go +++ /dev/null @@ -1,41 +0,0 @@ -package localstack - -import ( - "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://docs.localstack.cloud/getting-started/api-key/"), - ManagementURL: sdk.URL("https://app.localstack.cloud/account/apikeys"), - Fields: []schema.CredentialField{ - { - Name: fieldname.APIKey, - MarkdownDescription: "API Key used to authenticate to LocalStack.", - Secret: true, - Composition: &schema.ValueComposition{ - Length: 10, - Charset: schema.Charset{ - Uppercase: true, - Lowercase: true, - Digits: true, - }, - }, - }, - }, - DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), - Importer: importer.TryAll( - importer.TryEnvVarPair(defaultEnvVarMapping), - )} -} - -var defaultEnvVarMapping = map[string]sdk.FieldName{ - "LOCALSTACK_API_KEY": fieldname.APIKey, - "LOCALSTACK_AUTH_TOKEN": fieldname.AuthToken, -} diff --git a/plugins/localstack/api_key_test.go b/plugins/localstack/api_key_test.go deleted file mode 100644 index 9882a28ac..000000000 --- a/plugins/localstack/api_key_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package localstack - -import ( - "testing" - - "github.com/1Password/shell-plugins/sdk" - "github.com/1Password/shell-plugins/sdk/plugintest" - "github.com/1Password/shell-plugins/sdk/schema/fieldname" -) - -func TestAPIKeyProvisioner(t *testing.T) { - plugintest.TestProvisioner(t, APIKey().DefaultProvisioner, map[string]plugintest.ProvisionCase{ - "default": { - ItemFields: map[sdk.FieldName]string{ - fieldname.APIKey: "SzCEXAMPLE", - }, - ExpectedOutput: sdk.ProvisionOutput{ - Environment: map[string]string{ - "LOCALSTACK_API_KEY": "SzCEXAMPLE", - }, - }, - }, - }) -} - -func TestAPIKeyImporter(t *testing.T) { - plugintest.TestImporter(t, APIKey().Importer, map[string]plugintest.ImportCase{ - "environment": { - Environment: map[string]string{ - "LOCALSTACK_API_KEY": "SzCEXAMPLE", - }, - ExpectedCandidates: []sdk.ImportCandidate{ - { - Fields: map[sdk.FieldName]string{ - fieldname.APIKey: "SzCEXAMPLE", - }, - }, - }, - }, - }) -} diff --git a/plugins/localstack/auth_token.go b/plugins/localstack/auth_token.go index 285da9060..671c45342 100644 --- a/plugins/localstack/auth_token.go +++ b/plugins/localstack/auth_token.go @@ -27,6 +27,7 @@ func AuthToken() schema.CredentialType { Digits: true, Specific: []rune{'-'}, }, + Prefix: "ls-", }, }, }, @@ -35,3 +36,7 @@ func AuthToken() schema.CredentialType { importer.TryEnvVarPair(defaultEnvVarMapping), )} } + +var defaultEnvVarMapping = map[string]sdk.FieldName{ + "LOCALSTACK_AUTH_TOKEN": fieldname.AuthToken, +} diff --git a/plugins/localstack/localstack.go b/plugins/localstack/localstack.go index 4a1dad63a..b9b1f490a 100644 --- a/plugins/localstack/localstack.go +++ b/plugins/localstack/localstack.go @@ -15,6 +15,7 @@ func LocalStackCLI() schema.Executable { NeedsAuth: needsauth.IfAll( needsauth.NotForHelpOrVersion(), needsauth.NotWithoutArgs(), + needsauth.NotWhenContainsArgs("auth"), ), Uses: []schema.CredentialUsage{ { diff --git a/plugins/localstack/plugin.go b/plugins/localstack/plugin.go index 233f7dc7b..69cd454c3 100644 --- a/plugins/localstack/plugin.go +++ b/plugins/localstack/plugin.go @@ -12,9 +12,6 @@ func New() schema.Plugin { Name: "LocalStack", Homepage: sdk.URL("https://localstack.cloud"), }, - // TODO: LocalStack accepts both auth token and api key. When multiple - // credentials types are supported, update this list to include both - // options. Credentials: []schema.CredentialType{ AuthToken(), },