From 367edfe8f68ea9bc47073a40735a6ab6be14735f Mon Sep 17 00:00:00 2001 From: bala_ceg Date: Fri, 30 Jun 2023 00:38:24 +0530 Subject: [PATCH 1/3] Add support for InfluxDB Plugin --- plugins/influxdb/database_credentials.go | 40 +++++++++++++++++++ plugins/influxdb/database_credentials_test.go | 28 +++++++++++++ plugins/influxdb/influx.go | 26 ++++++++++++ plugins/influxdb/plugin.go | 22 ++++++++++ 4 files changed, 116 insertions(+) create mode 100644 plugins/influxdb/database_credentials.go create mode 100644 plugins/influxdb/database_credentials_test.go create mode 100644 plugins/influxdb/influx.go create mode 100644 plugins/influxdb/plugin.go diff --git a/plugins/influxdb/database_credentials.go b/plugins/influxdb/database_credentials.go new file mode 100644 index 000000000..de65a6100 --- /dev/null +++ b/plugins/influxdb/database_credentials.go @@ -0,0 +1,40 @@ +package influxdb + +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 DatabaseCredentials() schema.CredentialType { + return schema.CredentialType{ + Name: credname.DatabaseCredentials, + DocsURL: sdk.URL("https://docs.influxdata.com/influxdb/v2.7/reference/cli/influx/config/create/"), + Fields: []schema.CredentialField{ + { + Name: fieldname.Host, + MarkdownDescription: "InfluxDB host name", + }, + { + Name: fieldname.Organization, + MarkdownDescription: "InfluxDB Organization name", + }, + { + Name: fieldname.AccessToken, + MarkdownDescription: "InfluxDB Token value", + Secret: true, + }, + }, + DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), + Importer: importer.TryEnvVarPair(defaultEnvVarMapping), + } +} + +var defaultEnvVarMapping = map[string]sdk.FieldName{ + "INFLUX_HOST": fieldname.Host, + "INFLUX_ORG": fieldname.Organization, + "INFLUX_TOKEN": fieldname.AccessToken, +} diff --git a/plugins/influxdb/database_credentials_test.go b/plugins/influxdb/database_credentials_test.go new file mode 100644 index 000000000..86b262c37 --- /dev/null +++ b/plugins/influxdb/database_credentials_test.go @@ -0,0 +1,28 @@ +package influxdb + +import ( + "testing" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/plugintest" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +func TestDatabaseCredentialsProvisioner(t *testing.T) { + plugintest.TestProvisioner(t, DatabaseCredentials().DefaultProvisioner, map[string]plugintest.ProvisionCase{ + "default": { + ItemFields: map[sdk.FieldName]string{ + fieldname.Host: "https://us-west-2-1.aws.cloud2.influxdata.com", + fieldname.Organization: "1Password.com", + fieldname.AccessToken: "BHsmEerxKV2yDaNNv31lPHMEXAMPLE", + }, + ExpectedOutput: sdk.ProvisionOutput{ + Environment: map[string]string{ + "INFLUX_HOST": "https://us-west-2-1.aws.cloud2.influxdata.com", + "INFLUX_ORG": "1Password.com", + "INFLUX_TOKEN": "BHsmEerxKV2yDaNNv31lPHMEXAMPLE", + }, + }, + }, + }) +} diff --git a/plugins/influxdb/influx.go b/plugins/influxdb/influx.go new file mode 100644 index 000000000..ed9f7c3d2 --- /dev/null +++ b/plugins/influxdb/influx.go @@ -0,0 +1,26 @@ +package influxdb + +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 InfluxDBCLI() schema.Executable { + return schema.Executable{ + Name: "InfluxDB CLI", + Runs: []string{"influx"}, + DocsURL: sdk.URL("https://docs.influxdata.com/influxdb/"), + NeedsAuth: needsauth.IfAll( + needsauth.NotForHelpOrVersion(), + needsauth.NotWithoutArgs(), + needsauth.NotWhenContainsArgs("config"), + ), + Uses: []schema.CredentialUsage{ + { + Name: credname.DatabaseCredentials, + }, + }, + } +} diff --git a/plugins/influxdb/plugin.go b/plugins/influxdb/plugin.go new file mode 100644 index 000000000..166d13979 --- /dev/null +++ b/plugins/influxdb/plugin.go @@ -0,0 +1,22 @@ +package influxdb + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/schema" +) + +func New() schema.Plugin { + return schema.Plugin{ + Name: "influxdb", + Platform: schema.PlatformInfo{ + Name: "InfluxDB", + Homepage: sdk.URL("https://docs.influxdata.com/influxdb/"), + }, + Credentials: []schema.CredentialType{ + DatabaseCredentials(), + }, + Executables: []schema.Executable{ + InfluxDBCLI(), + }, + } +} From 6c7381b9501f47f13b5e1b72fb52f84d5535d5fd Mon Sep 17 00:00:00 2001 From: bala_ceg Date: Wed, 19 Jul 2023 21:07:37 +0530 Subject: [PATCH 2/3] Addressing the review comments received from arun --- plugins/influxdb/database_credentials.go | 2 +- plugins/influxdb/influx.go | 2 +- plugins/influxdb/plugin.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/influxdb/database_credentials.go b/plugins/influxdb/database_credentials.go index de65a6100..89460a5d6 100644 --- a/plugins/influxdb/database_credentials.go +++ b/plugins/influxdb/database_credentials.go @@ -12,7 +12,7 @@ import ( func DatabaseCredentials() schema.CredentialType { return schema.CredentialType{ Name: credname.DatabaseCredentials, - DocsURL: sdk.URL("https://docs.influxdata.com/influxdb/v2.7/reference/cli/influx/config/create/"), + DocsURL: sdk.URL("https://docs.influxdata.com/influxdb/cloud/reference/cli/influx/config/"), Fields: []schema.CredentialField{ { Name: fieldname.Host, diff --git a/plugins/influxdb/influx.go b/plugins/influxdb/influx.go index ed9f7c3d2..10f13436f 100644 --- a/plugins/influxdb/influx.go +++ b/plugins/influxdb/influx.go @@ -11,7 +11,7 @@ func InfluxDBCLI() schema.Executable { return schema.Executable{ Name: "InfluxDB CLI", Runs: []string{"influx"}, - DocsURL: sdk.URL("https://docs.influxdata.com/influxdb/"), + DocsURL: sdk.URL("https://docs.influxdata.com/influxdb/cloud/tools/influx-cli/"), NeedsAuth: needsauth.IfAll( needsauth.NotForHelpOrVersion(), needsauth.NotWithoutArgs(), diff --git a/plugins/influxdb/plugin.go b/plugins/influxdb/plugin.go index 166d13979..39562e054 100644 --- a/plugins/influxdb/plugin.go +++ b/plugins/influxdb/plugin.go @@ -10,7 +10,7 @@ func New() schema.Plugin { Name: "influxdb", Platform: schema.PlatformInfo{ Name: "InfluxDB", - Homepage: sdk.URL("https://docs.influxdata.com/influxdb/"), + Homepage: sdk.URL(" https://www.influxdata.com/"), }, Credentials: []schema.CredentialType{ DatabaseCredentials(), From 85a01813b76743745fd875d6dbac2e311b340e74 Mon Sep 17 00:00:00 2001 From: Arun Sathiya Date: Wed, 19 Jul 2023 12:49:02 -0700 Subject: [PATCH 3/3] Remove extra space at the start of the platform URL --- plugins/influxdb/plugin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/influxdb/plugin.go b/plugins/influxdb/plugin.go index 39562e054..585470b3e 100644 --- a/plugins/influxdb/plugin.go +++ b/plugins/influxdb/plugin.go @@ -10,7 +10,7 @@ func New() schema.Plugin { Name: "influxdb", Platform: schema.PlatformInfo{ Name: "InfluxDB", - Homepage: sdk.URL(" https://www.influxdata.com/"), + Homepage: sdk.URL("https://www.influxdata.com/"), }, Credentials: []schema.CredentialType{ DatabaseCredentials(),