Skip to content
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
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ac2890c
CrateDB
parthiv11 Jun 20, 2023
b937375
Make A plugin for CrateDB
parthiv11 Jun 24, 2023
0950d62
Merge branch '1Password:main' into cratedb
parthiv11 Jun 24, 2023
652668b
Merge branch '1Password:main' into cratedb
parthiv11 Jun 27, 2023
95e2502
Removed config as it has no Creds stored
parthiv11 Jun 27, 2023
3b82afc
Added Provisioner
parthiv11 Jun 29, 2023
1a463e6
Added Provisioner
parthiv11 Jun 29, 2023
cb5fecb
Updated provision for crate
parthiv11 Jun 29, 2023
05b41cd
Merge branch '1Password:main' into cratedb
parthiv11 Jun 29, 2023
a3948a3
Updated tests
parthiv11 Jun 29, 2023
af2695f
Merge branch 'cratedb' of https://github.com/parthiv11/shell-plugins …
parthiv11 Jun 29, 2023
61ff5e1
Updated provision
parthiv11 Jun 29, 2023
0f9cf3f
Improved
parthiv11 Jun 29, 2023
d53010e
formatted code
parthiv11 Jun 30, 2023
ac6e97c
Test passed && validated
parthiv11 Jul 1, 2023
e457eb4
Removed unused function
parthiv11 Jul 5, 2023
7a38dc1
Merge branch '1Password:main' into cratedb
parthiv11 Jul 8, 2023
18bc6c0
..
parthiv11 Jul 10, 2023
6f78648
provision improved
parthiv11 Jul 11, 2023
955a8fb
Updated `_`
parthiv11 Jul 11, 2023
1c50922
changed needauth condition
parthiv11 Jul 11, 2023
b469c6e
changed needauth condition
parthiv11 Jul 11, 2023
bfa1a9c
Merge branch '1Password:main' into cratedb
parthiv11 Jul 13, 2023
91fa45c
formated document
parthiv11 Jul 14, 2023
3709fb2
Merge branch 'cratedb' of https://github.com/parthiv11/shell-plugins …
parthiv11 Jul 14, 2023
f6be8b4
typo
parthiv11 Sep 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions plugins/cratedb/crash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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.IfAll(
needsauth.NotForHelpOrVersion(),
needsauth.NotWithoutArgs(),
),
Uses: []schema.CredentialUsage{
{
Name: credname.DatabaseCredentials,
Provisioner: crateArgsProvisioner,
},
},
}
}
46 changes: 46 additions & 0 deletions plugins/cratedb/database_credentials.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cratedb

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://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: true,
},
{
Name: fieldname.Username,
MarkdownDescription: "CrateDB user to authenticate as.",
Optional: true,
AndyTitu marked this conversation as resolved.
Show resolved Hide resolved
},
{
Name: fieldname.Password,
MarkdownDescription: "Password used to authenticate to CrateDB.",
Secret: true,
},
},
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
AndyTitu marked this conversation as resolved.
Show resolved Hide resolved
AndyTitu marked this conversation as resolved.
Show resolved Hide resolved
Importer: importer.TryAll(
importer.TryEnvVarPair(defaultEnvVarMapping),

)}
AndyTitu marked this conversation as resolved.
Show resolved Hide resolved
}

var defaultEnvVarMapping = map[string]sdk.FieldName{
"CRATEPW": fieldname.Password,
}

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

import (
"testing"

"github.com/1Password/shell-plugins/sdk"
Copy link
Contributor

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.

"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{ // TODO: Check if this is correct
fieldname.: "yqch",
},
ExpectedOutput: sdk.ProvisionOutput{
Environment: map[string]string{
"CRATEDB": "yqch",
},
},
},
})
}

func TestDatabaseCredentialsImporter(t *testing.T) {
plugintest.TestImporter(t, DatabaseCredentials().Importer, map[string]plugintest.ImportCase{
"environment": {
Environment: map[string]string{ // TODO: Check if this is correct
"CRATEPW": "eog-l4ogPoIO4kX8ICHC*6kP",
},
ExpectedCandidates: []sdk.ImportCandidate{
{
Fields: map[sdk.FieldName]string{
fieldname.Password: "eog-l4ogPoIO4kX8ICHC*6kP",
},
},
},
},
// TODO: If you implemented a config file importer, add a test file example in cratedb/test-fixtures
// and fill the necessary details in the test template below.
"config file": {
Files: map[string]string{
// "~/path/to/config.yml": plugintest.LoadFixture(t, "config.yml"),
},
ExpectedCandidates: []sdk.ImportCandidate{
// {
// Fields: map[sdk.FieldName]string{
// fieldname.Token: "yqch",
// },
// },
},
},
})
}
22 changes: 22 additions & 0 deletions plugins/cratedb/plugin.go
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(),
},
}
}
37 changes: 37 additions & 0 deletions plugins/cratedb/provisioner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cratedb

import (
"context"

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

var argsToProvision = []string{
"--username", fieldname.Username,
"--hosts", fieldname.Host,
}

type crateArgsProvisioner struct {
}

AndyTitu marked this conversation as resolved.
Show resolved Hide resolved
func crateProvisioner() sdk.Provisioner {
AndyTitu marked this conversation as resolved.
Show resolved Hide resolved
return crateArgsProvisioner{}
}

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)
}

out.CommandLine = append(out.CommandLine[1:], argsToProvision...)
AndyTitu marked this conversation as resolved.
Show resolved Hide resolved

}

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 crate secrets as command-line arguments."
}
AndyTitu marked this conversation as resolved.
Show resolved Hide resolved