Skip to content

Commit 604ef1e

Browse files
committed
Added Vertica Shell Plugin (vsql)
1 parent d7a779f commit 604ef1e

File tree

4 files changed

+136
-0
lines changed

4 files changed

+136
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package vertica
2+
3+
import (
4+
"context"
5+
6+
"github.com/1Password/shell-plugins/sdk"
7+
"github.com/1Password/shell-plugins/sdk/importer"
8+
"github.com/1Password/shell-plugins/sdk/provision"
9+
"github.com/1Password/shell-plugins/sdk/schema"
10+
"github.com/1Password/shell-plugins/sdk/schema/credname"
11+
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
12+
)
13+
14+
func DatabaseCredentials() schema.CredentialType {
15+
return schema.CredentialType{
16+
Name: credname.DatabaseCredentials,
17+
DocsURL: sdk.URL("https://www.vertica.com/docs/9.2.x/HTML/Content/Authoring/ConnectingToVertica/vsql/Install/InstallingTheVsqlClient.htm"),
18+
ManagementURL: sdk.URL("https://www.vertica.com/try/"),
19+
Fields: []schema.CredentialField{
20+
{
21+
Name: fieldname.Host,
22+
MarkdownDescription: "Vertica host to connect to.",
23+
Optional: true,
24+
},
25+
{
26+
Name: fieldname.Port,
27+
MarkdownDescription: "Port used to connect to Vertica.",
28+
Optional: true,
29+
},
30+
{
31+
Name: fieldname.Username,
32+
MarkdownDescription: "Vertica user to authenticate as.",
33+
Optional: true,
34+
},
35+
{
36+
Name: fieldname.Password,
37+
MarkdownDescription: "Password used to authenticate to Vertica.",
38+
Secret: true,
39+
},
40+
{
41+
Name: fieldname.Database,
42+
MarkdownDescription: "Database name to connect to.",
43+
Optional: true,
44+
},
45+
},
46+
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
47+
Importer: importer.TryAllimporter.TryEnvVarPair(defaultEnvVarMapping)}
48+
}
49+
50+
var defaultEnvVarMapping = map[string]sdk.FieldName{
51+
"VSQL_USER": fieldname.Username,
52+
"VSQL_PASSWORD": fieldname.Password,
53+
"VSQL_HOST": fieldname.Host,
54+
"VSQL_PORT": fieldname.Port,
55+
"VSQL_DATABASE": fieldname.Database,
56+
}
57+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package vertica
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.User: "vertica",
16+
fieldname.Password: "",
17+
fieldname.Host: "localhost",
18+
fieldname.Port: "5433",
19+
fieldname.Database: "VMart",
20+
},
21+
ExpectedOutput: sdk.ProvisionOutput{
22+
Environment: map[string]string{
23+
"VSQL_USER": "vertica",
24+
"VSQL_PASSWORD": "",
25+
"VSQL_HOST": "localhost",
26+
"VSQL_PORT": "5433",
27+
"VSQL_DATABASE": "VMart",
28+
},
29+
},
30+
},
31+
})
32+
}

plugins/vertica/plugin.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package vertica
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: "vertica",
11+
Platform: schema.PlatformInfo{
12+
Name: "Vertica",
13+
Homepage: sdk.URL("https://www.vertica.com/"),
14+
},
15+
Credentials: []schema.CredentialType{
16+
DatabaseCredentials(),
17+
},
18+
Executables: []schema.Executable{
19+
VerticaCLI(),
20+
},
21+
}
22+
}

plugins/vertica/vsql.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package vertica
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 VerticaCLI() schema.Executable {
11+
return schema.Executable{
12+
Name: "Vertica CLI",
13+
Runs: []string{"vsql"},
14+
DocsURL: sdk.URL("https://www.vertica.com/docs/9.2.x/HTML/Content/Authoring/ConnectingToVertica/vsql/UsingVsql.htm"),
15+
NeedsAuth: needsauth.IfAll(
16+
needsauth.NotForHelpOrVersion(),
17+
needsauth.NotWithoutArgs(),
18+
),
19+
Uses: []schema.CredentialUsage{
20+
{
21+
Name: credname.DatabaseCredentials,
22+
},
23+
},
24+
}
25+
}

0 commit comments

Comments
 (0)