Skip to content

Commit 3e37102

Browse files
Merge pull request #392 from 1Password/amanda/influxdb
Amanda/influxdb
2 parents 33b9329 + a10acc7 commit 3e37102

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package influxdb
2+
3+
import (
4+
"github.com/1Password/shell-plugins/sdk"
5+
"github.com/1Password/shell-plugins/sdk/importer"
6+
"github.com/1Password/shell-plugins/sdk/provision"
7+
"github.com/1Password/shell-plugins/sdk/schema"
8+
"github.com/1Password/shell-plugins/sdk/schema/credname"
9+
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
10+
)
11+
12+
func DatabaseCredentials() schema.CredentialType {
13+
return schema.CredentialType{
14+
Name: credname.DatabaseCredentials,
15+
DocsURL: sdk.URL("https://docs.influxdata.com/influxdb/cloud/reference/cli/influx/config/"),
16+
Fields: []schema.CredentialField{
17+
{
18+
Name: fieldname.Host,
19+
MarkdownDescription: "InfluxDB host name",
20+
},
21+
{
22+
Name: fieldname.Organization,
23+
MarkdownDescription: "InfluxDB Organization name",
24+
},
25+
{
26+
Name: fieldname.AccessToken,
27+
MarkdownDescription: "InfluxDB Token value",
28+
Secret: true,
29+
},
30+
},
31+
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
32+
Importer: importer.TryEnvVarPair(defaultEnvVarMapping),
33+
}
34+
}
35+
36+
var defaultEnvVarMapping = map[string]sdk.FieldName{
37+
"INFLUX_HOST": fieldname.Host,
38+
"INFLUX_ORG": fieldname.Organization,
39+
"INFLUX_TOKEN": fieldname.AccessToken,
40+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package influxdb
2+
3+
import (
4+
"testing"
5+
6+
"github.com/1Password/shell-plugins/sdk"
7+
"github.com/1Password/shell-plugins/sdk/plugintest"
8+
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
9+
)
10+
11+
func TestDatabaseCredentialsProvisioner(t *testing.T) {
12+
plugintest.TestProvisioner(t, DatabaseCredentials().DefaultProvisioner, map[string]plugintest.ProvisionCase{
13+
"default": {
14+
ItemFields: map[sdk.FieldName]string{
15+
fieldname.Host: "https://us-west-2-1.aws.cloud2.influxdata.com",
16+
fieldname.Organization: "1Password.com",
17+
fieldname.AccessToken: "BHsmEerxKV2yDaNNv31lPHMEXAMPLE",
18+
},
19+
ExpectedOutput: sdk.ProvisionOutput{
20+
Environment: map[string]string{
21+
"INFLUX_HOST": "https://us-west-2-1.aws.cloud2.influxdata.com",
22+
"INFLUX_ORG": "1Password.com",
23+
"INFLUX_TOKEN": "BHsmEerxKV2yDaNNv31lPHMEXAMPLE",
24+
},
25+
},
26+
},
27+
})
28+
}

plugins/influxdb/influx.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package influxdb
2+
3+
import (
4+
"github.com/1Password/shell-plugins/sdk"
5+
"github.com/1Password/shell-plugins/sdk/needsauth"
6+
"github.com/1Password/shell-plugins/sdk/schema"
7+
"github.com/1Password/shell-plugins/sdk/schema/credname"
8+
)
9+
10+
func InfluxDBCLI() schema.Executable {
11+
return schema.Executable{
12+
Name: "InfluxDB CLI",
13+
Runs: []string{"influx"},
14+
DocsURL: sdk.URL("https://docs.influxdata.com/influxdb/cloud/tools/influx-cli/"),
15+
NeedsAuth: needsauth.IfAll(
16+
needsauth.NotForHelpOrVersion(),
17+
needsauth.NotWithoutArgs(),
18+
needsauth.NotWhenContainsArgs("config"),
19+
),
20+
Uses: []schema.CredentialUsage{
21+
{
22+
Name: credname.DatabaseCredentials,
23+
},
24+
},
25+
}
26+
}

plugins/influxdb/plugin.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package influxdb
2+
3+
import (
4+
"github.com/1Password/shell-plugins/sdk"
5+
"github.com/1Password/shell-plugins/sdk/schema"
6+
)
7+
8+
func New() schema.Plugin {
9+
return schema.Plugin{
10+
Name: "influxdb",
11+
Platform: schema.PlatformInfo{
12+
Name: "InfluxDB",
13+
Homepage: sdk.URL("https://www.influxdata.com/"),
14+
},
15+
Credentials: []schema.CredentialType{
16+
DatabaseCredentials(),
17+
},
18+
Executables: []schema.Executable{
19+
InfluxDBCLI(),
20+
},
21+
}
22+
}

0 commit comments

Comments
 (0)