diff --git a/plugins/bundler/bundle.go b/plugins/bundler/bundle.go new file mode 100644 index 00000000..d8955747 --- /dev/null +++ b/plugins/bundler/bundle.go @@ -0,0 +1,25 @@ +package bundler + +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 BundleCLI() schema.Executable { + return schema.Executable{ + Name: "Bundler CLI", + Runs: []string{"bundle"}, + DocsURL: sdk.URL("https://bundler.io/man/bundle-install.1.html"), + NeedsAuth: needsauth.IfAll( + needsauth.NotForHelpOrVersion(), + needsauth.ForCommand("install"), + ), + Uses: []schema.CredentialUsage{ + { + Name: credname.PersonalAccessToken, + }, + }, + } +} diff --git a/plugins/bundler/personal_access_token.go b/plugins/bundler/personal_access_token.go new file mode 100644 index 00000000..7dfdc541 --- /dev/null +++ b/plugins/bundler/personal_access_token.go @@ -0,0 +1,42 @@ +package bundler + +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 PersonalAccessToken() schema.CredentialType { + return schema.CredentialType{ + Name: credname.PersonalAccessToken, + DocsURL: sdk.URL("https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token"), + ManagementURL: sdk.URL("https://github.com/settings/tokens"), + Fields: []schema.CredentialField{ + { + Name: fieldname.Token, + MarkdownDescription: "GitHub Personal Access Token (classic) used to authenticate to GitHub Package Registry for Bundler. Note: GitHub Packages only supports authentication using a personal access token (classic). For more information, see [Managing your personal access tokens](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens).", + Secret: true, + Composition: &schema.ValueComposition{ + Length: 40, + Prefix: "ghp_", + Charset: schema.Charset{ + Uppercase: true, + Lowercase: true, + Digits: true, + }, + }, + }, + }, + DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), + Importer: importer.TryAll( + importer.TryEnvVarPair(defaultEnvVarMapping), + ), + } +} + +var defaultEnvVarMapping = map[string]sdk.FieldName{ + "BUNDLE_RUBYGEMS__PKG__GITHUB__COM": fieldname.Token, +} diff --git a/plugins/bundler/personal_access_token_test.go b/plugins/bundler/personal_access_token_test.go new file mode 100644 index 00000000..4604cdfe --- /dev/null +++ b/plugins/bundler/personal_access_token_test.go @@ -0,0 +1,41 @@ +package bundler + +import ( + "testing" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/plugintest" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +func TestPersonalAccessTokenProvisioner(t *testing.T) { + plugintest.TestProvisioner(t, PersonalAccessToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{ + "default": { + ItemFields: map[sdk.FieldName]string{ + fieldname.Token: "ghp_1234567890123456789012345678901234567890", + }, + ExpectedOutput: sdk.ProvisionOutput{ + Environment: map[string]string{ + "BUNDLE_RUBYGEMS__PKG__GITHUB__COM": "ghp_1234567890123456789012345678901234567890", + }, + }, + }, + }) +} + +func TestPersonalAccessTokenImporter(t *testing.T) { + plugintest.TestImporter(t, PersonalAccessToken().Importer, map[string]plugintest.ImportCase{ + "environment": { + Environment: map[string]string{ + "BUNDLE_RUBYGEMS__PKG__GITHUB__COM": "ghp_1234567890123456789012345678901234567890", + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.Token: "ghp_1234567890123456789012345678901234567890", + }, + }, + }, + }, + }) +} diff --git a/plugins/bundler/plugin.go b/plugins/bundler/plugin.go new file mode 100644 index 00000000..62890a96 --- /dev/null +++ b/plugins/bundler/plugin.go @@ -0,0 +1,22 @@ +package bundler + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/schema" +) + +func New() schema.Plugin { + return schema.Plugin{ + Name: "bundler", + Platform: schema.PlatformInfo{ + Name: "Ruby Bundler", + Homepage: sdk.URL("https://bundler.io"), + }, + Credentials: []schema.CredentialType{ + PersonalAccessToken(), + }, + Executables: []schema.Executable{ + BundleCLI(), + }, + } +}