Skip to content

Commit

Permalink
Added plugin for DBT Redshift
Browse files Browse the repository at this point in the history
  • Loading branch information
guru-pochineni committed Jun 29, 2023
1 parent a39d64a commit 6325958
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 0 deletions.
51 changes: 51 additions & 0 deletions plugins/dbtredshift/database_credentials.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package dbtredshift

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.getdbt.com/docs/core/connect-data-platform/redshift-setup#password-based-authentication"),
Fields: []schema.CredentialField{
{
Name: fieldname.Host,
MarkdownDescription: "Redshift host to connect to.",
},
{
Name: fieldname.Port,
MarkdownDescription: "Port used to connect to Redshift.",
Optional: true,
},
{
Name: fieldname.User,
MarkdownDescription: "Redshift user to authenticate as.",
},
{
Name: fieldname.Password,
MarkdownDescription: "Password used to authenticate to Redshift.",
Secret: true,
},
{
Name: fieldname.Database,
MarkdownDescription: "Database name to connect to.",
},
},
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
Importer: importer.TryEnvVarPair(defaultEnvVarMapping),
}
}

var defaultEnvVarMapping = map[string]sdk.FieldName{
"DBT_HOST": fieldname.Host,
"DBT_PORT": fieldname.Port,
"DBT_USER": fieldname.User,
"DBT_PASSWORD": fieldname.Password,
"DBT_DB": fieldname.Database,
}
57 changes: 57 additions & 0 deletions plugins/dbtredshift/database_credentials_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package dbtredshift

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: "examplecluster.abc123xyz789.us-west-1.redshift.amazonaws.com",
fieldname.Port: "5439",
fieldname.User: "awsuser",
fieldname.Password: "my_password",
fieldname.Database: "dev",
},
ExpectedOutput: sdk.ProvisionOutput{
Environment: map[string]string{
"DBT_HOST": "examplecluster.abc123xyz789.us-west-1.redshift.amazonaws.com",
"DBT_PORT": "5439",
"DBT_USER": "awsuser",
"DBT_PASSWORD": "my_password",
"DBT_DB": "dev",
},
},
},
})
}

func TestDatabaseCredentialsImporter(t *testing.T) {
plugintest.TestImporter(t, DatabaseCredentials().Importer, map[string]plugintest.ImportCase{
"default": {
Environment: map[string]string{
"DBT_HOST": "examplecluster.abc123xyz789.us-west-1.redshift.amazonaws.com",
"DBT_PORT": "5439",
"DBT_USER": "awsuser",
"DBT_PASSWORD": "my_password",
"DBT_DB": "dev",
},
ExpectedCandidates: []sdk.ImportCandidate{
{
Fields: map[sdk.FieldName]string{
fieldname.Host: "examplecluster.abc123xyz789.us-west-1.redshift.amazonaws.com",
fieldname.Port: "5439",
fieldname.User: "awsuser",
fieldname.Password: "my_password",
fieldname.Database: "dev",
},
},
},
},
})
}
25 changes: 25 additions & 0 deletions plugins/dbtredshift/dbtredshift.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package dbtredshift

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 dbtredshiftCLI() schema.Executable {
return schema.Executable{
Name: "dbtredshift",
Runs: []string{"dbt"},
DocsURL: sdk.URL("https://docs.getdbt.com/docs/core/connect-data-platform/redshift-setup"),
NeedsAuth: needsauth.IfAll(
needsauth.NotForHelpOrVersion(),
needsauth.NotWithoutArgs(),
),
Uses: []schema.CredentialUsage{
{
Name: credname.DatabaseCredentials,
},
},
}
}
22 changes: 22 additions & 0 deletions plugins/dbtredshift/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dbtredshift

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

func New() schema.Plugin {
return schema.Plugin{
Name: "dbtredshift",
Platform: schema.PlatformInfo{
Name: "DBT Redshift",
Homepage: sdk.URL("https://www.getdbt.com"),
},
Credentials: []schema.CredentialType{
DatabaseCredentials(),
},
Executables: []schema.Executable{
dbtredshiftCLI(),
},
}
}

0 comments on commit 6325958

Please sign in to comment.