-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a39d64a
commit 6325958
Showing
4 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
}, | ||
} | ||
} |