Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 25 additions & 0 deletions plugins/bundler/bundle.go
Original file line number Diff line number Diff line change
@@ -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,
},
},
}
}
42 changes: 42 additions & 0 deletions plugins/bundler/personal_access_token.go
Original file line number Diff line number Diff line change
@@ -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,
}
41 changes: 41 additions & 0 deletions plugins/bundler/personal_access_token_test.go
Original file line number Diff line number Diff line change
@@ -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",
},
},
},
},
})
}
22 changes: 22 additions & 0 deletions plugins/bundler/plugin.go
Original file line number Diff line number Diff line change
@@ -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(),
},
}
}
Loading