-
Notifications
You must be signed in to change notification settings - Fork 171
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 CrateDB Shell Plugin #313
Open
parthiv11
wants to merge
26
commits into
1Password:main
Choose a base branch
from
parthiv11:cratedb
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
26 commits
Select commit
Hold shift + click to select a range
ac2890c
CrateDB
parthiv11 b937375
Make A plugin for CrateDB
parthiv11 0950d62
Merge branch '1Password:main' into cratedb
parthiv11 652668b
Merge branch '1Password:main' into cratedb
parthiv11 95e2502
Removed config as it has no Creds stored
parthiv11 3b82afc
Added Provisioner
parthiv11 1a463e6
Added Provisioner
parthiv11 cb5fecb
Updated provision for crate
parthiv11 05b41cd
Merge branch '1Password:main' into cratedb
parthiv11 a3948a3
Updated tests
parthiv11 af2695f
Merge branch 'cratedb' of https://github.com/parthiv11/shell-plugins …
parthiv11 61ff5e1
Updated provision
parthiv11 0f9cf3f
Improved
parthiv11 d53010e
formatted code
parthiv11 ac6e97c
Test passed && validated
parthiv11 e457eb4
Removed unused function
parthiv11 7a38dc1
Merge branch '1Password:main' into cratedb
parthiv11 18bc6c0
..
parthiv11 6f78648
provision improved
parthiv11 955a8fb
Updated `_`
parthiv11 1c50922
changed needauth condition
parthiv11 b469c6e
changed needauth condition
parthiv11 bfa1a9c
Merge branch '1Password:main' into cratedb
parthiv11 91fa45c
formated document
parthiv11 3709fb2
Merge branch 'cratedb' of https://github.com/parthiv11/shell-plugins …
parthiv11 f6be8b4
typo
parthiv11 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,23 @@ | ||
package cratedb | ||
|
||
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 CrateDBCLI() schema.Executable { | ||
return schema.Executable{ | ||
Name: "CrateDB Shell", | ||
Runs: []string{"crash"}, | ||
DocsURL: sdk.URL("https://crate.io/docs/crate/crash/en/latest/"), | ||
NeedsAuth: needsauth.NotForHelpOrVersion(), | ||
Uses: []schema.CredentialUsage{ | ||
{ | ||
Name: credname.DatabaseCredentials, | ||
Provisioner: CrateArgsProvisioner{}, | ||
}, | ||
}, | ||
} | ||
} |
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,41 @@ | ||
package cratedb | ||
|
||
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://crate.io/docs/crate/crash/en/latest/run.html#environment-variables"), | ||
ManagementURL: sdk.URL("https://console.cratedb.cloud/account/settings"), | ||
Fields: []schema.CredentialField{ | ||
{ | ||
Name: fieldname.Host, | ||
MarkdownDescription: "CrateDB host to connect to.", | ||
Optional: false, | ||
}, | ||
{ | ||
Name: fieldname.Username, | ||
MarkdownDescription: "CrateDB user to authenticate as.", | ||
Optional: false, | ||
}, | ||
{ | ||
Name: fieldname.Password, | ||
MarkdownDescription: "Password used to authenticate to CrateDB.", | ||
Secret: true, | ||
}, | ||
}, | ||
DefaultProvisioner: provision.NoOp(), | ||
Importer: importer.TryEnvVarPair(defaultEnvVarMapping), | ||
} | ||
} | ||
|
||
var defaultEnvVarMapping = map[string]sdk.FieldName{ | ||
"CRATEPW": fieldname.Password, | ||
} |
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,35 @@ | ||
package cratedb | ||
|
||
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, CrateArgsProvisioner{}, map[string]plugintest.ProvisionCase{ | ||
"default": { | ||
ItemFields: map[sdk.FieldName]string{ | ||
|
||
fieldname.Host: "https://love.aks1.eastus2.azure.cratedb.net:4200", | ||
fieldname.Username: "admin", | ||
fieldname.Password: "1<34&f0rg3t@me", | ||
}, | ||
CommandLine: []string{"crash"}, | ||
ExpectedOutput: sdk.ProvisionOutput{ | ||
Environment: map[string]string{ | ||
"CRATEPW": "1<34&f0rg3t@me", | ||
}, | ||
CommandLine: []string{ | ||
"crash", | ||
"--hosts", | ||
"https://love.aks1.eastus2.azure.cratedb.net:4200", | ||
"--username", | ||
"admin", | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |
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 cratedb | ||
|
||
import ( | ||
"github.com/1Password/shell-plugins/sdk" | ||
"github.com/1Password/shell-plugins/sdk/schema" | ||
) | ||
|
||
func New() schema.Plugin { | ||
return schema.Plugin{ | ||
Name: "cratedb", | ||
Platform: schema.PlatformInfo{ | ||
Name: "CrateDB", | ||
Homepage: sdk.URL("https://crate.io/"), | ||
}, | ||
Credentials: []schema.CredentialType{ | ||
DatabaseCredentials(), | ||
}, | ||
Executables: []schema.Executable{ | ||
CrateDBCLI(), | ||
}, | ||
} | ||
} |
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,33 @@ | ||
package cratedb | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/1Password/shell-plugins/sdk" | ||
"github.com/1Password/shell-plugins/sdk/schema/fieldname" | ||
) | ||
|
||
type CrateArgsProvisioner struct { | ||
} | ||
|
||
func (p CrateArgsProvisioner) Provision(ctx context.Context, in sdk.ProvisionInput, out *sdk.ProvisionOutput) { | ||
if value, ok := in.ItemFields[fieldname.Password]; ok { | ||
out.AddEnvVar("CRATEPW", value) | ||
} | ||
|
||
user, userFound := in.ItemFields[fieldname.Username] | ||
host, hostFound := in.ItemFields[fieldname.Host] | ||
if userFound && hostFound { | ||
commandLine := []string{out.CommandLine[0], "--user", user, "--host", host} | ||
commandLine = append(commandLine, out.CommandLine[1:]...) | ||
out.CommandLine = commandLine | ||
} | ||
} | ||
|
||
func (p CrateArgsProvisioner) Deprovision(ctx context.Context, in sdk.DeprovisionInput, out *sdk.DeprovisionOutput) { | ||
// Nothing to do here: credentials get wiped automatically when the process exits. | ||
} | ||
|
||
func (p CrateArgsProvisioner) Description() string { | ||
return "Provision CrateDB username, host as command-line arguments && Password as Env ." | ||
} |
Oops, something went wrong.
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.
Linter is complaining that this file is not formatted, and more specifically these imports are not in order.