Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for InfluxDB shell Plugin #332

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions plugins/influxdb/database_credentials.go
Original file line number Diff line number Diff line change
@@ -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/"),
bala-ceg marked this conversation as resolved.
Show resolved Hide resolved
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),
bala-ceg marked this conversation as resolved.
Show resolved Hide resolved
}
}

var defaultEnvVarMapping = map[string]sdk.FieldName{
"INFLUX_HOST": fieldname.Host,
"INFLUX_ORG": fieldname.Organization,
"INFLUX_TOKEN": fieldname.AccessToken,
}
28 changes: 28 additions & 0 deletions plugins/influxdb/database_credentials_test.go
Original file line number Diff line number Diff line change
@@ -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",
},
},
},
})
}
26 changes: 26 additions & 0 deletions plugins/influxdb/influx.go
Original file line number Diff line number Diff line change
@@ -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/"),
bala-ceg marked this conversation as resolved.
Show resolved Hide resolved
NeedsAuth: needsauth.IfAll(
needsauth.NotForHelpOrVersion(),
needsauth.NotWithoutArgs(),
needsauth.NotWhenContainsArgs("config"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see authentication for version and completion. Commands like backup and restore are specific to InfluxDB OSS and InfluxDB Cloud, but I am still figuring out whether we should exclude them entirely or build support for InfluxDB OSS too. I'll followup here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not done any changes to this comment. My assumption we are supporting only influxdb cloud at this moment via shell plugin

),
Uses: []schema.CredentialUsage{
{
Name: credname.DatabaseCredentials,
},
},
}
}
22 changes: 22 additions & 0 deletions plugins/influxdb/plugin.go
Original file line number Diff line number Diff line change
@@ -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/"),
bala-ceg marked this conversation as resolved.
Show resolved Hide resolved
},
Credentials: []schema.CredentialType{
DatabaseCredentials(),
},
Executables: []schema.Executable{
InfluxDBCLI(),
},
}
}