Skip to content

Commit 6f8040b

Browse files
authored
Merge pull request #322 from parthiv11/yugabyte
Added Shell Plugin for Yugabyte
2 parents 3d4bde6 + 2dcf34a commit 6f8040b

File tree

4 files changed

+157
-0
lines changed

4 files changed

+157
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package yugabytedb
2+
3+
import (
4+
"github.com/1Password/shell-plugins/sdk"
5+
"github.com/1Password/shell-plugins/sdk/importer"
6+
"github.com/1Password/shell-plugins/sdk/provision"
7+
"github.com/1Password/shell-plugins/sdk/schema"
8+
"github.com/1Password/shell-plugins/sdk/schema/credname"
9+
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
10+
)
11+
12+
func DatabaseCredentials() schema.CredentialType {
13+
return schema.CredentialType{
14+
Name: credname.DatabaseCredentials,
15+
DocsURL: sdk.URL("https://docs.yugabyte.com/preview/admin/ysqlsh/#connect-to-a-database"),
16+
ManagementURL: sdk.URL("https://cloud.yugabyte.com/clusters"),
17+
Fields: []schema.CredentialField{
18+
{
19+
Name: fieldname.Host,
20+
MarkdownDescription: "Yugabyte host to connect to.",
21+
},
22+
{
23+
Name: fieldname.Port,
24+
MarkdownDescription: "Port used to connect to Yugabyte.",
25+
Optional: true,
26+
},
27+
{
28+
Name: fieldname.Username,
29+
MarkdownDescription: "Yugabyte user to get authenticate.",
30+
},
31+
{
32+
Name: fieldname.Password,
33+
MarkdownDescription: "Password used to authenticate to Yugabyte.",
34+
Secret: true,
35+
},
36+
{
37+
Name: fieldname.Database,
38+
MarkdownDescription: "Database name to connect to Yugabyte.",
39+
Optional: true,
40+
},
41+
},
42+
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
43+
Importer: importer.TryEnvVarPair(defaultEnvVarMapping),
44+
}
45+
}
46+
47+
var defaultEnvVarMapping = map[string]sdk.FieldName{
48+
"PGHOST": fieldname.Host,
49+
"PGPORT": fieldname.Port,
50+
"PGUSER": fieldname.Username,
51+
"PGPASSWORD": fieldname.Password,
52+
"PGDATABASE": fieldname.Database,
53+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package yugabytedb
2+
3+
import (
4+
"testing"
5+
6+
"github.com/1Password/shell-plugins/sdk"
7+
"github.com/1Password/shell-plugins/sdk/plugintest"
8+
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
9+
)
10+
11+
func TestDatabaseCredentialsImporter(t *testing.T) {
12+
plugintest.TestImporter(t, DatabaseCredentials().Importer, map[string]plugintest.ImportCase{
13+
"yugabyte": {
14+
Environment: map[string]string{
15+
"PGHOST": "localhost",
16+
"PGPORT": "5432",
17+
"PGUSER": "root",
18+
"PGPASSWORD": "123456",
19+
"PGDATABASE": "test",
20+
},
21+
ExpectedCandidates: []sdk.ImportCandidate{
22+
{
23+
Fields: map[sdk.FieldName]string{
24+
fieldname.Host: "localhost",
25+
fieldname.Port: "5432",
26+
fieldname.Username: "root",
27+
fieldname.Password: "123456",
28+
fieldname.Database: "test",
29+
},
30+
},
31+
},
32+
},
33+
})
34+
}
35+
36+
func TestDatabaseCredentialsProvisioner(t *testing.T) {
37+
plugintest.TestProvisioner(t, DatabaseCredentials().DefaultProvisioner, map[string]plugintest.ProvisionCase{
38+
"default": {
39+
ItemFields: map[sdk.FieldName]string{
40+
fieldname.Host: "localhost",
41+
fieldname.Port: "5432",
42+
fieldname.Username: "root",
43+
fieldname.Password: "123456",
44+
fieldname.Database: "test",
45+
},
46+
ExpectedOutput: sdk.ProvisionOutput{
47+
Environment: map[string]string{
48+
"PGHOST": "localhost",
49+
"PGPORT": "5432",
50+
"PGUSER": "root",
51+
"PGPASSWORD": "123456",
52+
"PGDATABASE": "test",
53+
},
54+
},
55+
},
56+
},
57+
)
58+
}

plugins/yugabytedb/plugin.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package yugabytedb
2+
3+
import (
4+
"github.com/1Password/shell-plugins/sdk"
5+
"github.com/1Password/shell-plugins/sdk/schema"
6+
)
7+
8+
func New() schema.Plugin {
9+
return schema.Plugin{
10+
Name: "yugabytedb",
11+
Platform: schema.PlatformInfo{
12+
Name: "YugabyteDB",
13+
Homepage: sdk.URL("https://yugabyte.com"),
14+
},
15+
Credentials: []schema.CredentialType{
16+
DatabaseCredentials(),
17+
},
18+
Executables: []schema.Executable{
19+
YugabyteDBCLI(),
20+
},
21+
}
22+
}

plugins/yugabytedb/ysqlsh.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package yugabytedb
2+
3+
import (
4+
"github.com/1Password/shell-plugins/sdk"
5+
"github.com/1Password/shell-plugins/sdk/needsauth"
6+
"github.com/1Password/shell-plugins/sdk/schema"
7+
"github.com/1Password/shell-plugins/sdk/schema/credname"
8+
)
9+
10+
func YugabyteDBCLI() schema.Executable {
11+
return schema.Executable{
12+
Name: "YugabyteDB SQL Shell",
13+
Runs: []string{"ysqlsh"},
14+
DocsURL: sdk.URL("https://docs.yugabyte.com/preview/admin/ysqlsh/"),
15+
NeedsAuth: needsauth.IfAll(
16+
needsauth.NotForHelpOrVersion(),
17+
),
18+
Uses: []schema.CredentialUsage{
19+
{
20+
Name: credname.DatabaseCredentials,
21+
},
22+
},
23+
}
24+
}

0 commit comments

Comments
 (0)