Skip to content

Commit

Permalink
Add support for InfluxDB Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
bala-ceg committed Jun 29, 2023
1 parent a39d64a commit 367edfe
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
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/"),
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,
}
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/"),
NeedsAuth: needsauth.IfAll(
needsauth.NotForHelpOrVersion(),
needsauth.NotWithoutArgs(),
needsauth.NotWhenContainsArgs("config"),
),
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/"),
},
Credentials: []schema.CredentialType{
DatabaseCredentials(),
},
Executables: []schema.Executable{
InfluxDBCLI(),
},
}
}

0 comments on commit 367edfe

Please sign in to comment.