-
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.
Merge pull request #322 from parthiv11/yugabyte
Added Shell Plugin for Yugabyte
- Loading branch information
Showing
4 changed files
with
157 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,53 @@ | ||
package yugabytedb | ||
|
||
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.yugabyte.com/preview/admin/ysqlsh/#connect-to-a-database"), | ||
ManagementURL: sdk.URL("https://cloud.yugabyte.com/clusters"), | ||
Fields: []schema.CredentialField{ | ||
{ | ||
Name: fieldname.Host, | ||
MarkdownDescription: "Yugabyte host to connect to.", | ||
}, | ||
{ | ||
Name: fieldname.Port, | ||
MarkdownDescription: "Port used to connect to Yugabyte.", | ||
Optional: true, | ||
}, | ||
{ | ||
Name: fieldname.Username, | ||
MarkdownDescription: "Yugabyte user to get authenticate.", | ||
}, | ||
{ | ||
Name: fieldname.Password, | ||
MarkdownDescription: "Password used to authenticate to Yugabyte.", | ||
Secret: true, | ||
}, | ||
{ | ||
Name: fieldname.Database, | ||
MarkdownDescription: "Database name to connect to Yugabyte.", | ||
Optional: true, | ||
}, | ||
}, | ||
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), | ||
Importer: importer.TryEnvVarPair(defaultEnvVarMapping), | ||
} | ||
} | ||
|
||
var defaultEnvVarMapping = map[string]sdk.FieldName{ | ||
"PGHOST": fieldname.Host, | ||
"PGPORT": fieldname.Port, | ||
"PGUSER": fieldname.Username, | ||
"PGPASSWORD": fieldname.Password, | ||
"PGDATABASE": 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,58 @@ | ||
package yugabytedb | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/1Password/shell-plugins/sdk" | ||
"github.com/1Password/shell-plugins/sdk/plugintest" | ||
"github.com/1Password/shell-plugins/sdk/schema/fieldname" | ||
) | ||
|
||
func TestDatabaseCredentialsImporter(t *testing.T) { | ||
plugintest.TestImporter(t, DatabaseCredentials().Importer, map[string]plugintest.ImportCase{ | ||
"yugabyte": { | ||
Environment: map[string]string{ | ||
"PGHOST": "localhost", | ||
"PGPORT": "5432", | ||
"PGUSER": "root", | ||
"PGPASSWORD": "123456", | ||
"PGDATABASE": "test", | ||
}, | ||
ExpectedCandidates: []sdk.ImportCandidate{ | ||
{ | ||
Fields: map[sdk.FieldName]string{ | ||
fieldname.Host: "localhost", | ||
fieldname.Port: "5432", | ||
fieldname.Username: "root", | ||
fieldname.Password: "123456", | ||
fieldname.Database: "test", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestDatabaseCredentialsProvisioner(t *testing.T) { | ||
plugintest.TestProvisioner(t, DatabaseCredentials().DefaultProvisioner, map[string]plugintest.ProvisionCase{ | ||
"default": { | ||
ItemFields: map[sdk.FieldName]string{ | ||
fieldname.Host: "localhost", | ||
fieldname.Port: "5432", | ||
fieldname.Username: "root", | ||
fieldname.Password: "123456", | ||
fieldname.Database: "test", | ||
}, | ||
ExpectedOutput: sdk.ProvisionOutput{ | ||
Environment: map[string]string{ | ||
"PGHOST": "localhost", | ||
"PGPORT": "5432", | ||
"PGUSER": "root", | ||
"PGPASSWORD": "123456", | ||
"PGDATABASE": "test", | ||
}, | ||
}, | ||
}, | ||
}, | ||
) | ||
} |
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 yugabytedb | ||
|
||
import ( | ||
"github.com/1Password/shell-plugins/sdk" | ||
"github.com/1Password/shell-plugins/sdk/schema" | ||
) | ||
|
||
func New() schema.Plugin { | ||
return schema.Plugin{ | ||
Name: "yugabytedb", | ||
Platform: schema.PlatformInfo{ | ||
Name: "YugabyteDB", | ||
Homepage: sdk.URL("https://yugabyte.com"), | ||
}, | ||
Credentials: []schema.CredentialType{ | ||
DatabaseCredentials(), | ||
}, | ||
Executables: []schema.Executable{ | ||
YugabyteDBCLI(), | ||
}, | ||
} | ||
} |
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,24 @@ | ||
package yugabytedb | ||
|
||
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 YugabyteDBCLI() schema.Executable { | ||
return schema.Executable{ | ||
Name: "YugabyteDB SQL Shell", | ||
Runs: []string{"ysqlsh"}, | ||
DocsURL: sdk.URL("https://docs.yugabyte.com/preview/admin/ysqlsh/"), | ||
NeedsAuth: needsauth.IfAll( | ||
needsauth.NotForHelpOrVersion(), | ||
), | ||
Uses: []schema.CredentialUsage{ | ||
{ | ||
Name: credname.DatabaseCredentials, | ||
}, | ||
}, | ||
} | ||
} |