diff --git a/plugins/upcloud/plugin.go b/plugins/upcloud/plugin.go new file mode 100644 index 00000000..d23930ce --- /dev/null +++ b/plugins/upcloud/plugin.go @@ -0,0 +1,22 @@ +package upcloud + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/schema" +) + +func New() schema.Plugin { + return schema.Plugin{ + Name: "upcloud", + Platform: schema.PlatformInfo{ + Name: "UpCloud", + Homepage: sdk.URL("https://upcloud.com"), + }, + Credentials: []schema.CredentialType{ + UserLogin(), + }, + Executables: []schema.Executable{ + UpCloudCLI(), + }, + } +} diff --git a/plugins/upcloud/upctl.go b/plugins/upcloud/upctl.go new file mode 100644 index 00000000..b003bd0e --- /dev/null +++ b/plugins/upcloud/upctl.go @@ -0,0 +1,26 @@ +package upcloud + +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 UpCloudCLI() schema.Executable { + return schema.Executable{ + Name: "UpCloud CLI", + Runs: []string{"upctl"}, + DocsURL: sdk.URL("https://upcloudltd.github.io/upcloud-cli/"), + NeedsAuth: needsauth.IfAll( + needsauth.NotForHelpOrVersion(), + needsauth.NotWithoutArgs(), + needsauth.NotWhenContainsArgs("completion"), + ), + Uses: []schema.CredentialUsage{ + { + Name: credname.UserLogin, + }, + }, + } +} diff --git a/plugins/upcloud/user_login.go b/plugins/upcloud/user_login.go new file mode 100644 index 00000000..5313ba69 --- /dev/null +++ b/plugins/upcloud/user_login.go @@ -0,0 +1,54 @@ +package upcloud + +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 UserLogin() schema.CredentialType { + return schema.CredentialType{ + Name: credname.UserLogin, + DocsURL: sdk.URL("https://upcloudltd.github.io/upcloud-cli/"), + ManagementURL: sdk.URL("https://hub.upcloud.com/people/accounts"), + Fields: []schema.CredentialField{ + { + Name: fieldname.Username, + MarkdownDescription: "Username.", + Secret: false, + Optional: false, + Composition: &schema.ValueComposition{ + Length: 20, + Charset: schema.Charset{ + Uppercase: true, + Digits: true, + }, + }, + }, + { + Name: fieldname.Password, + MarkdownDescription: "Password.", + Secret: true, + Optional: false, + Composition: &schema.ValueComposition{ + Length: 36, + Charset: schema.Charset{ + Lowercase: true, + Digits: true, + }, + }, + }, + }, + DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), + Importer: importer.TryAll( + importer.TryEnvVarPair(defaultEnvVarMapping), + )} +} + +var defaultEnvVarMapping = map[string]sdk.FieldName{ + "UPCLOUD_USERNAME": fieldname.Username, + "UPCLOUD_PASSWORD": fieldname.Password, +} diff --git a/plugins/upcloud/user_login_test.go b/plugins/upcloud/user_login_test.go new file mode 100644 index 00000000..3fe6e189 --- /dev/null +++ b/plugins/upcloud/user_login_test.go @@ -0,0 +1,45 @@ +package upcloud + +import ( + "testing" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/plugintest" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +func TestAccessKeyProvisioner(t *testing.T) { + plugintest.TestProvisioner(t, UserLogin().DefaultProvisioner, map[string]plugintest.ProvisionCase{ + "default": { + ItemFields: map[sdk.FieldName]string{ + fieldname.Username: "theuser", + fieldname.Password: "SuperS3cret", + }, + ExpectedOutput: sdk.ProvisionOutput{ + Environment: map[string]string{ + "UPCLOUD_USERNAME": "theuser", + "UPCLOUD_PASSWORD": "SuperS3cret", + }, + }, + }, + }) +} + +func TestUserLoginImporter(t *testing.T) { + plugintest.TestImporter(t, UserLogin().Importer, map[string]plugintest.ImportCase{ + "default": { + Environment: map[string]string{ + "UPCLOUD_USERNAME": "theuser", + "UPCLOUD_PASSWORD": "SuperS3cret", + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.Username: "theuser", + fieldname.Password: "SuperS3cret", + }, + }, + }, + }, + }) +}