From dad13ef163f0ce3eb29eff0ed1001fe583f9da61 Mon Sep 17 00:00:00 2001 From: siddhikhapare Date: Thu, 29 Jun 2023 15:48:55 +0530 Subject: [PATCH 1/6] changes added in files --- plugins/upstash/api_key.go | 81 +++++++++++++++++++++ plugins/upstash/api_key_test.go | 59 +++++++++++++++ plugins/upstash/plugin.go | 22 ++++++ plugins/upstash/test-fixtures/.upstash.json | 4 + plugins/upstash/upstash.go | 27 +++++++ 5 files changed, 193 insertions(+) create mode 100644 plugins/upstash/api_key.go create mode 100644 plugins/upstash/api_key_test.go create mode 100644 plugins/upstash/plugin.go create mode 100755 plugins/upstash/test-fixtures/.upstash.json create mode 100644 plugins/upstash/upstash.go diff --git a/plugins/upstash/api_key.go b/plugins/upstash/api_key.go new file mode 100644 index 000000000..e502aba31 --- /dev/null +++ b/plugins/upstash/api_key.go @@ -0,0 +1,81 @@ +package upstash + +import ( + "context" + + "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.upstash.com/redis/account/developerapi#create-an-api-key"), // TODO: Replace with actual URL + ManagementURL: sdk.URL("https://console.upstash.com/account/api"), + Fields: []schema.CredentialField{ + { + Name: fieldname.APIKey, + MarkdownDescription: "API Key used to authenticate to Upstash.", + Secret: true, + Composition: &schema.ValueComposition{ + Length: 36, + Charset: schema.Charset{ + Lowercase: true, + Digits: true, + }, + }, + }, + { + Name: fieldname.Email, + MarkdownDescription: "Email used to authenticate to Upstash.", + Composition: &schema.ValueComposition{ + Charset: schema.Charset{ + Uppercase: true, + Lowercase: true, + Digits: true, + Symbols: true, + }, + }, + }, + }, + DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), + Importer: importer.TryAll( + importer.TryEnvVarPair(defaultEnvVarMapping), + TryUpstashConfigFile(), + )} +} + +var defaultEnvVarMapping = map[string]sdk.FieldName{ + "UPSTASH_API_KEY": fieldname.APIKey, + "UPSTASH_EMAIL" : fieldname.Email, +} + +func TryUpstashConfigFile() sdk.Importer { + return importer.TryFile("~/.upstash.json", 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 + } + + if config.APIKey == "" && config.Email == "" { + return + } + + out.AddCandidate(sdk.ImportCandidate{ + Fields: map[sdk.FieldName]string{ + fieldname.APIKey: config.APIKey, + fieldname.Email : config.Email, + }, + }) + }) +} + +type Config struct { + APIKey string `json:"apiKey"` + Email string `json:"email"` +} diff --git a/plugins/upstash/api_key_test.go b/plugins/upstash/api_key_test.go new file mode 100644 index 000000000..c011834ba --- /dev/null +++ b/plugins/upstash/api_key_test.go @@ -0,0 +1,59 @@ +package upstash + +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: "d68850db-69f7-qxe9pubcmjnqfgyexample", + fieldname.Email : "fakememail12@gmail.com", + }, + ExpectedOutput: sdk.ProvisionOutput{ + Environment: map[string]string{ + "UPSTASH_API_KEY": "d68850db-69f7-qxe9pubcmjnqfgyexample", + "UPSTASH_EMAIL" : "fakememail12@gmail.com", + }, + }, + }, + }) +} + +func TestAPIKeyImporter(t *testing.T) { + plugintest.TestImporter(t, APIKey().Importer, map[string]plugintest.ImportCase{ + "environment": { + Environment: map[string]string{ + "UPSTASH_API_KEY": "d68850db-69f7-qxe9pubcmjnqfgyexample", + "UPSTASH_EMAIL" : "fakememail12@gmail.com", + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.APIKey: "d68850db-69f7-qxe9pubcmjnqfgyexample", + fieldname.Email : "fakememail12@gmail.com", + }, + }, + }, + }, + + "config file": { + Files: map[string]string{ + "~/.upstash.json": plugintest.LoadFixture(t, ".upstash.json"), + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.APIKey: "d68850db-69f7-qxe9pubcmjnqfgyexample", + fieldname.Email : "fakememail12@gmail.com", + }, + }, + }, + }, + }) +} diff --git a/plugins/upstash/plugin.go b/plugins/upstash/plugin.go new file mode 100644 index 000000000..61dcbca6d --- /dev/null +++ b/plugins/upstash/plugin.go @@ -0,0 +1,22 @@ +package upstash + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/schema" +) + +func New() schema.Plugin { + return schema.Plugin{ + Name: "upstash", + Platform: schema.PlatformInfo{ + Name: "Upstash", + Homepage: sdk.URL("https://upstash.com"), + }, + Credentials: []schema.CredentialType{ + APIKey(), + }, + Executables: []schema.Executable{ + UpstashCLI(), + }, + } +} diff --git a/plugins/upstash/test-fixtures/.upstash.json b/plugins/upstash/test-fixtures/.upstash.json new file mode 100755 index 000000000..77f770494 --- /dev/null +++ b/plugins/upstash/test-fixtures/.upstash.json @@ -0,0 +1,4 @@ +{ + "apiKey":"d68850db-69f7-qxe9pubcmjnqfgyexample", + "email" : "fakememail12@gmail.com" +} \ No newline at end of file diff --git a/plugins/upstash/upstash.go b/plugins/upstash/upstash.go new file mode 100644 index 000000000..08e6dbecd --- /dev/null +++ b/plugins/upstash/upstash.go @@ -0,0 +1,27 @@ +package upstash + +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 UpstashCLI() schema.Executable { + return schema.Executable{ + Name: "Upstash CLI", + Runs: []string{"upstash"}, + DocsURL: sdk.URL("https://github.com/upstash/cli"), + NeedsAuth: needsauth.IfAll( + needsauth.NotForHelpOrVersion(), + needsauth.NotWithoutArgs(), + needsauth.NotForExactArgs("config"), + needsauth.NotWhenContainsArgs("auth"), + ), + Uses: []schema.CredentialUsage{ + { + Name: credname.APIKey, + }, + }, + } +} From addf6f1e8c828bcf0429c16caa9ecef9f719d634 Mon Sep 17 00:00:00 2001 From: siddhikhapare Date: Thu, 29 Jun 2023 16:25:36 +0530 Subject: [PATCH 2/6] apikey file changed --- plugins/upstash/api_key.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/upstash/api_key.go b/plugins/upstash/api_key.go index e502aba31..7d8f58e03 100644 --- a/plugins/upstash/api_key.go +++ b/plugins/upstash/api_key.go @@ -14,7 +14,7 @@ import ( func APIKey() schema.CredentialType { return schema.CredentialType{ Name: credname.APIKey, - DocsURL: sdk.URL("https://docs.upstash.com/redis/account/developerapi#create-an-api-key"), // TODO: Replace with actual URL + DocsURL: sdk.URL("https://docs.upstash.com/redis/account/developerapi#create-an-api-key"), ManagementURL: sdk.URL("https://console.upstash.com/account/api"), Fields: []schema.CredentialField{ { @@ -57,7 +57,7 @@ var defaultEnvVarMapping = map[string]sdk.FieldName{ func TryUpstashConfigFile() sdk.Importer { return importer.TryFile("~/.upstash.json", func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) { var config Config - if err := contents.ToYAML(&config); err != nil { + if err := contents.ToJSON(&config); err != nil { out.AddError(err) return } From b58afee7b97f3653c6226ea908745eeab4b4de51 Mon Sep 17 00:00:00 2001 From: siddhikhapare Date: Thu, 29 Jun 2023 20:42:14 +0530 Subject: [PATCH 3/6] files modified --- plugins/upstash/api_key.go | 16 ++++++++-------- plugins/upstash/api_key_test.go | 20 ++++++++++---------- plugins/upstash/plugin.go | 2 +- plugins/upstash/upstash.go | 6 +++--- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/plugins/upstash/api_key.go b/plugins/upstash/api_key.go index 7d8f58e03..0b0964745 100644 --- a/plugins/upstash/api_key.go +++ b/plugins/upstash/api_key.go @@ -14,8 +14,8 @@ import ( func APIKey() schema.CredentialType { return schema.CredentialType{ Name: credname.APIKey, - DocsURL: sdk.URL("https://docs.upstash.com/redis/account/developerapi#create-an-api-key"), - ManagementURL: sdk.URL("https://console.upstash.com/account/api"), + DocsURL: sdk.URL("https://docs.upstash.com/redis/account/developerapi#create-an-api-key"), + ManagementURL: sdk.URL("https://console.upstash.com/account/api"), Fields: []schema.CredentialField{ { Name: fieldname.APIKey, @@ -42,7 +42,7 @@ func APIKey() schema.CredentialType { }, }, }, - DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), + DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), Importer: importer.TryAll( importer.TryEnvVarPair(defaultEnvVarMapping), TryUpstashConfigFile(), @@ -50,8 +50,8 @@ func APIKey() schema.CredentialType { } var defaultEnvVarMapping = map[string]sdk.FieldName{ - "UPSTASH_API_KEY": fieldname.APIKey, - "UPSTASH_EMAIL" : fieldname.Email, + "UPSTASH_API_KEY": fieldname.APIKey, + "UPSTASH_EMAIL": fieldname.Email, } func TryUpstashConfigFile() sdk.Importer { @@ -69,13 +69,13 @@ func TryUpstashConfigFile() sdk.Importer { out.AddCandidate(sdk.ImportCandidate{ Fields: map[sdk.FieldName]string{ fieldname.APIKey: config.APIKey, - fieldname.Email : config.Email, + fieldname.Email: config.Email, }, }) }) } type Config struct { - APIKey string `json:"apiKey"` - Email string `json:"email"` + APIKey string `json:"apiKey"` + Email string `json:"email"` } diff --git a/plugins/upstash/api_key_test.go b/plugins/upstash/api_key_test.go index c011834ba..613881415 100644 --- a/plugins/upstash/api_key_test.go +++ b/plugins/upstash/api_key_test.go @@ -2,23 +2,23 @@ package upstash 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{ + ItemFields: map[sdk.FieldName]string{ fieldname.APIKey: "d68850db-69f7-qxe9pubcmjnqfgyexample", - fieldname.Email : "fakememail12@gmail.com", + fieldname.Email: "fakememail12@gmail.com", }, ExpectedOutput: sdk.ProvisionOutput{ Environment: map[string]string{ "UPSTASH_API_KEY": "d68850db-69f7-qxe9pubcmjnqfgyexample", - "UPSTASH_EMAIL" : "fakememail12@gmail.com", + "UPSTASH_EMAIL": "fakememail12@gmail.com", }, }, }, @@ -28,20 +28,20 @@ func TestAPIKeyProvisioner(t *testing.T) { func TestAPIKeyImporter(t *testing.T) { plugintest.TestImporter(t, APIKey().Importer, map[string]plugintest.ImportCase{ "environment": { - Environment: map[string]string{ + Environment: map[string]string{ "UPSTASH_API_KEY": "d68850db-69f7-qxe9pubcmjnqfgyexample", - "UPSTASH_EMAIL" : "fakememail12@gmail.com", + "UPSTASH_EMAIL": "fakememail12@gmail.com", }, ExpectedCandidates: []sdk.ImportCandidate{ { Fields: map[sdk.FieldName]string{ fieldname.APIKey: "d68850db-69f7-qxe9pubcmjnqfgyexample", - fieldname.Email : "fakememail12@gmail.com", + fieldname.Email: "fakememail12@gmail.com", }, }, }, }, - + "config file": { Files: map[string]string{ "~/.upstash.json": plugintest.LoadFixture(t, ".upstash.json"), @@ -50,7 +50,7 @@ func TestAPIKeyImporter(t *testing.T) { { Fields: map[sdk.FieldName]string{ fieldname.APIKey: "d68850db-69f7-qxe9pubcmjnqfgyexample", - fieldname.Email : "fakememail12@gmail.com", + fieldname.Email: "fakememail12@gmail.com", }, }, }, diff --git a/plugins/upstash/plugin.go b/plugins/upstash/plugin.go index 61dcbca6d..06ba9d390 100644 --- a/plugins/upstash/plugin.go +++ b/plugins/upstash/plugin.go @@ -10,7 +10,7 @@ func New() schema.Plugin { Name: "upstash", Platform: schema.PlatformInfo{ Name: "Upstash", - Homepage: sdk.URL("https://upstash.com"), + Homepage: sdk.URL("https://upstash.com"), }, Credentials: []schema.CredentialType{ APIKey(), diff --git a/plugins/upstash/upstash.go b/plugins/upstash/upstash.go index 08e6dbecd..4ce262baa 100644 --- a/plugins/upstash/upstash.go +++ b/plugins/upstash/upstash.go @@ -9,9 +9,9 @@ import ( func UpstashCLI() schema.Executable { return schema.Executable{ - Name: "Upstash CLI", - Runs: []string{"upstash"}, - DocsURL: sdk.URL("https://github.com/upstash/cli"), + Name: "Upstash CLI", + Runs: []string{"upstash"}, + DocsURL: sdk.URL("https://github.com/upstash/cli"), NeedsAuth: needsauth.IfAll( needsauth.NotForHelpOrVersion(), needsauth.NotWithoutArgs(), From d43d07836385c9388a54d27f591c0cb714249432 Mon Sep 17 00:00:00 2001 From: siddhikhapare Date: Thu, 29 Jun 2023 23:17:26 +0530 Subject: [PATCH 4/6] suggested changes added --- plugins/upstash/api_key.go | 1 + plugins/upstash/api_key_test.go | 10 +++++----- plugins/upstash/test-fixtures/.upstash.json | 2 +- plugins/upstash/upstash.go | 3 ++- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/upstash/api_key.go b/plugins/upstash/api_key.go index 0b0964745..29387c296 100644 --- a/plugins/upstash/api_key.go +++ b/plugins/upstash/api_key.go @@ -26,6 +26,7 @@ func APIKey() schema.CredentialType { Charset: schema.Charset{ Lowercase: true, Digits: true, + Symbols: true, }, }, }, diff --git a/plugins/upstash/api_key_test.go b/plugins/upstash/api_key_test.go index 613881415..6d26d7c84 100644 --- a/plugins/upstash/api_key_test.go +++ b/plugins/upstash/api_key_test.go @@ -13,12 +13,12 @@ func TestAPIKeyProvisioner(t *testing.T) { "default": { ItemFields: map[sdk.FieldName]string{ fieldname.APIKey: "d68850db-69f7-qxe9pubcmjnqfgyexample", - fieldname.Email: "fakememail12@gmail.com", + fieldname.Email: "wendy@appleseed.com", }, ExpectedOutput: sdk.ProvisionOutput{ Environment: map[string]string{ "UPSTASH_API_KEY": "d68850db-69f7-qxe9pubcmjnqfgyexample", - "UPSTASH_EMAIL": "fakememail12@gmail.com", + "UPSTASH_EMAIL": "wendy@appleseed.com", }, }, }, @@ -30,13 +30,13 @@ func TestAPIKeyImporter(t *testing.T) { "environment": { Environment: map[string]string{ "UPSTASH_API_KEY": "d68850db-69f7-qxe9pubcmjnqfgyexample", - "UPSTASH_EMAIL": "fakememail12@gmail.com", + "UPSTASH_EMAIL": "wendy@appleseed.com", }, ExpectedCandidates: []sdk.ImportCandidate{ { Fields: map[sdk.FieldName]string{ fieldname.APIKey: "d68850db-69f7-qxe9pubcmjnqfgyexample", - fieldname.Email: "fakememail12@gmail.com", + fieldname.Email: "wendy@appleseed.com", }, }, }, @@ -50,7 +50,7 @@ func TestAPIKeyImporter(t *testing.T) { { Fields: map[sdk.FieldName]string{ fieldname.APIKey: "d68850db-69f7-qxe9pubcmjnqfgyexample", - fieldname.Email: "fakememail12@gmail.com", + fieldname.Email: "wendy@appleseed.com", }, }, }, diff --git a/plugins/upstash/test-fixtures/.upstash.json b/plugins/upstash/test-fixtures/.upstash.json index 77f770494..2a9830fd5 100755 --- a/plugins/upstash/test-fixtures/.upstash.json +++ b/plugins/upstash/test-fixtures/.upstash.json @@ -1,4 +1,4 @@ { "apiKey":"d68850db-69f7-qxe9pubcmjnqfgyexample", - "email" : "fakememail12@gmail.com" + "email" : "wendy@appleseed.com" } \ No newline at end of file diff --git a/plugins/upstash/upstash.go b/plugins/upstash/upstash.go index 4ce262baa..89e88f3cb 100644 --- a/plugins/upstash/upstash.go +++ b/plugins/upstash/upstash.go @@ -15,7 +15,8 @@ func UpstashCLI() schema.Executable { NeedsAuth: needsauth.IfAll( needsauth.NotForHelpOrVersion(), needsauth.NotWithoutArgs(), - needsauth.NotForExactArgs("config"), + needsauth.NotWhenContainsArgs("--config"), + needsauth.NotWhenContainsArgs("-c"), needsauth.NotWhenContainsArgs("auth"), ), Uses: []schema.CredentialUsage{ From be53d920b1cb7e4457009c90ebbd063564166925 Mon Sep 17 00:00:00 2001 From: siddhikhapare Date: Fri, 30 Jun 2023 10:30:03 +0530 Subject: [PATCH 5/6] file formatted --- plugins/upstash/api_key_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/upstash/api_key_test.go b/plugins/upstash/api_key_test.go index 6d26d7c84..8d6e4ab09 100644 --- a/plugins/upstash/api_key_test.go +++ b/plugins/upstash/api_key_test.go @@ -18,7 +18,7 @@ func TestAPIKeyProvisioner(t *testing.T) { ExpectedOutput: sdk.ProvisionOutput{ Environment: map[string]string{ "UPSTASH_API_KEY": "d68850db-69f7-qxe9pubcmjnqfgyexample", - "UPSTASH_EMAIL": "wendy@appleseed.com", + "UPSTASH_EMAIL": "wendy@appleseed.com", }, }, }, From fb3d3c5cf18d46868218cd284bfcf37b527c91e4 Mon Sep 17 00:00:00 2001 From: Joris Coenen Date: Tue, 4 Jul 2023 17:18:30 +0200 Subject: [PATCH 6/6] Add missing newline to test fixture --- plugins/upstash/test-fixtures/.upstash.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/upstash/test-fixtures/.upstash.json b/plugins/upstash/test-fixtures/.upstash.json index 2a9830fd5..14467b5e5 100755 --- a/plugins/upstash/test-fixtures/.upstash.json +++ b/plugins/upstash/test-fixtures/.upstash.json @@ -1,4 +1,4 @@ { "apiKey":"d68850db-69f7-qxe9pubcmjnqfgyexample", "email" : "wendy@appleseed.com" -} \ No newline at end of file +}