Skip to content

Commit a4de470

Browse files
authored
Merge pull request #327 from parthiv11/vsql
Added Vertica Shell Plugin (vsql)
2 parents 1f44f6e + 700fb49 commit a4de470

File tree

4 files changed

+154
-0
lines changed

4 files changed

+154
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package vertica
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://www.vertica.com/docs/9.2.x/HTML/Content/Authoring/AdministratorsGuide/DBUsersAndPrivileges/Users/CreatingADatabaseUser.htm"),
16+
Fields: []schema.CredentialField{
17+
{
18+
Name: fieldname.Host,
19+
MarkdownDescription: "Vertica host to connect to.",
20+
Optional: true,
21+
},
22+
{
23+
Name: fieldname.Port,
24+
MarkdownDescription: "Port used to connect to Vertica.",
25+
Optional: true,
26+
},
27+
{
28+
Name: fieldname.Username,
29+
MarkdownDescription: "Vertica user to authenticate as.",
30+
},
31+
{
32+
Name: fieldname.Password,
33+
MarkdownDescription: "Password used to authenticate to Vertica.",
34+
Secret: true,
35+
},
36+
{
37+
Name: fieldname.Database,
38+
MarkdownDescription: "Database name to connect to.",
39+
},
40+
},
41+
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
42+
Importer: importer.TryEnvVarPair(defaultEnvVarMapping)}
43+
}
44+
45+
var defaultEnvVarMapping = map[string]sdk.FieldName{
46+
"VSQL_USER": fieldname.Username,
47+
"VSQL_PASSWORD": fieldname.Password,
48+
"VSQL_HOST": fieldname.Host,
49+
"VSQL_PORT": fieldname.Port,
50+
"VSQL_DATABASE": fieldname.Database,
51+
}
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+
"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.Username: "vertica",
16+
fieldname.Password: "Il0v3y04",
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": "Il0v3y04",
25+
"VSQL_HOST": "localhost",
26+
"VSQL_PORT": "5433",
27+
"VSQL_DATABASE": "VMart",
28+
},
29+
},
30+
},
31+
})
32+
}
33+
34+
func TestAPIKeyImporter(t *testing.T) {
35+
plugintest.TestImporter(t, DatabaseCredentials().Importer, map[string]plugintest.ImportCase{
36+
"environment": {
37+
Environment: map[string]string{
38+
"VSQL_USER": "vertica",
39+
"VSQL_PASSWORD": "Il0v3y04",
40+
"VSQL_HOST": "localhost",
41+
"VSQL_PORT": "5433",
42+
"VSQL_DATABASE": "VMart",
43+
},
44+
ExpectedCandidates: []sdk.ImportCandidate{
45+
{
46+
Fields: map[sdk.FieldName]string{
47+
fieldname.Username: "vertica",
48+
fieldname.Password: "Il0v3y04",
49+
fieldname.Host: "localhost",
50+
fieldname.Port: "5433",
51+
fieldname.Database: "VMart",
52+
},
53+
},
54+
},
55+
},
56+
})
57+
}

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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
),
18+
Uses: []schema.CredentialUsage{
19+
{
20+
Name: credname.DatabaseCredentials,
21+
},
22+
},
23+
}
24+
}

0 commit comments

Comments
 (0)