Skip to content

Commit

Permalink
Added Vertica Shell Plugin (vsql)
Browse files Browse the repository at this point in the history
  • Loading branch information
parthiv11 committed Jun 29, 2023
1 parent d7a779f commit 9aa1195
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
57 changes: 57 additions & 0 deletions plugins/vertica/database_credentials.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package vertica

import (
"context"

"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://www.vertica.com/docs/9.2.x/HTML/Content/Authoring/ConnectingToVertica/vsql/Install/InstallingTheVsqlClient.htm"),
ManagementURL: sdk.URL("https://www.vertica.com/try/"),
Fields: []schema.CredentialField{
{
Name: fieldname.Host,
MarkdownDescription: "Vertica host to connect to.",
Optional: true,
},
{
Name: fieldname.Port,
MarkdownDescription: "Port used to connect to Vertica.",
Optional: true,
},
{
Name: fieldname.Username,
MarkdownDescription: "Vertica user to authenticate as.",
Optional: true,
},
{
Name: fieldname.Password,
MarkdownDescription: "Password used to authenticate to Vertica.",
Secret: true,
},
{
Name: fieldname.Database,
MarkdownDescription: "Database name to connect to.",
Optional: true,
},
},
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
Importer: importer.TryAllimporter.TryEnvVarPair(defaultEnvVarMapping)}
}

var defaultEnvVarMapping = map[string]sdk.FieldName{
"VSQL_USER": fieldname.Username,
"VSQL_PASSWORD": fieldname.Password,
"VSQL_HOST": fieldname.Host,
"VSQL_PORT": fieldname.Port,
"VSQL_DATABASE": fieldname.Database,
}

32 changes: 32 additions & 0 deletions plugins/vertica/database_credentials_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package vertica

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.User: "vertica",
fieldname.Password: "",
fieldname.Host: "localhost",
fieldname.Port: "5433",
fieldname.Database: "VMart",
},
ExpectedOutput: sdk.ProvisionOutput{
Environment: map[string]string{
"VSQL_USER": "vertica",
"VSQL_PASSWORD": "",
"VSQL_HOST": "localhost",
"VSQL_PORT": "5433",
"VSQL_DATABASE": "VMart",
},
},
},
})
}
22 changes: 22 additions & 0 deletions plugins/vertica/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package vertica

import (
"github.com/1Password/shell-plugins/sdk"
"github.com/1Password/shell-plugins/sdk/schema"
)

func New() schema.Plugin {
return schema.Plugin{
Name: "vertica",
Platform: schema.PlatformInfo{
Name: "Vertica",
Homepage: sdk.URL("https://www.vertica.com/"),
},
Credentials: []schema.CredentialType{
DatabaseCredentials(),
},
Executables: []schema.Executable{
VerticaCLI(),
},
}
}
25 changes: 25 additions & 0 deletions plugins/vertica/vsql.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package vertica

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 VerticaCLI() schema.Executable {
return schema.Executable{
Name: "Vertica CLI",
Runs: []string{"vsql"},
DocsURL: sdk.URL("https://www.vertica.com/docs/9.2.x/HTML/Content/Authoring/ConnectingToVertica/vsql/UsingVsql.htm"),
NeedsAuth: needsauth.IfAll(
needsauth.NotForHelpOrVersion(),
needsauth.NotWithoutArgs(),
),
Uses: []schema.CredentialUsage{
{
Name: credname.DatabaseCredentials,
},
},
}
}

0 comments on commit 9aa1195

Please sign in to comment.