-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added plugin for dbt CLI #328
Open
guru-pochineni
wants to merge
2
commits into
1Password:main
Choose a base branch
from
guru-pochineni:dev/dbt-redshift-plugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,54 @@ | ||
package dbt | ||
|
||
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: "Host to connect to.", | ||
Optional: true, | ||
}, | ||
{ | ||
Name: fieldname.Port, | ||
MarkdownDescription: "Port used to connect to.", | ||
Optional: true, | ||
}, | ||
{ | ||
Name: fieldname.User, | ||
MarkdownDescription: "User to authenticate as.", | ||
Optional: true, | ||
}, | ||
{ | ||
Name: fieldname.Password, | ||
MarkdownDescription: "Password used to authenticate to.", | ||
Secret: true, | ||
}, | ||
{ | ||
Name: fieldname.Database, | ||
MarkdownDescription: "Database name to connect to.", | ||
Optional: true, | ||
}, | ||
}, | ||
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 dbt | ||
|
||
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 dbt | ||
|
||
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 dbtCLI() schema.Executable { | ||
return schema.Executable{ | ||
Name: "dbt", | ||
Runs: []string{"dbt"}, | ||
DocsURL: sdk.URL("https://docs.getdbt.com/docs/core/connect-data-platform/about-core-connections"), | ||
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 dbt | ||
|
||
import ( | ||
"github.com/1Password/shell-plugins/sdk" | ||
"github.com/1Password/shell-plugins/sdk/schema" | ||
) | ||
|
||
func New() schema.Plugin { | ||
return schema.Plugin{ | ||
Name: "dbt", | ||
Platform: schema.PlatformInfo{ | ||
Name: "DBT", | ||
Homepage: sdk.URL("https://www.getdbt.com"), | ||
}, | ||
Credentials: []schema.CredentialType{ | ||
DatabaseCredentials(), | ||
}, | ||
Executables: []schema.Executable{ | ||
dbtCLI(), | ||
}, | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I gather from the documentation, these environment variables are only used to be referenced in a configuration file, is that correct?
With these provisioned, a config file such as the one documented here: https://docs.getdbt.com/reference/dbt-jinja-functions/profiles-yml-context
is still necessary for the plugin to work. Is there some documentation that I have missed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that this is indeed what you are documenting in the PR description as well.
Rather than creating an additional requirement for the user to write their own config file, I would prefer if we were to provision a configuration file directly, using
provision.TempFile
, as in plugins such asmysql
orakamai
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the suggestion. Users would still need to configure
profiles.yml
file as lot of other attributes can be tweaked in it. I will add changes to incorporateprovision.TempFile
and keep env variables as it is.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thank you for the clarification.
@libutcher do you know of any other plugins that have a similar behaviour? Asking you since you tested/documented their vast majority, I wonder if there is already any occurrence of a plugin that requires additional setup on top of the 1Password CLI-related stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following up here, it doesn't look like there are any plugins with that behaviour. @guru-pochineni, are you still planning to add changes to incorporate provision.TempFile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't got the chance to make changes. Let me take a look into this next weekend.