Skip to content

Commit 7ecd3eb

Browse files
committed
chore: Add Bundler plugin with GitHub Packages support
- Implemented the Bundler CLI executable with authentication requirements. - Created Personal Access Token credential type with environment variable mapping. - Added tests for provisioning and importing Personal Access Tokens.
1 parent 49810df commit 7ecd3eb

File tree

4 files changed

+130
-0
lines changed

4 files changed

+130
-0
lines changed

plugins/bundler/bundle.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package bundler
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 BundleCLI() schema.Executable {
11+
return schema.Executable{
12+
Name: "Bundler CLI",
13+
Runs: []string{"bundle"},
14+
DocsURL: sdk.URL("https://bundler.io/man/bundle-install.1.html"),
15+
NeedsAuth: needsauth.IfAll(
16+
needsauth.NotForHelpOrVersion(),
17+
needsauth.ForCommand("install"),
18+
),
19+
Uses: []schema.CredentialUsage{
20+
{
21+
Name: credname.PersonalAccessToken,
22+
},
23+
},
24+
}
25+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package bundler
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 PersonalAccessToken() schema.CredentialType {
13+
return schema.CredentialType{
14+
Name: credname.PersonalAccessToken,
15+
DocsURL: sdk.URL("https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token"),
16+
ManagementURL: sdk.URL("https://github.com/settings/tokens"),
17+
Fields: []schema.CredentialField{
18+
{
19+
Name: fieldname.Token,
20+
MarkdownDescription: "GitHub Personal Access Token used to authenticate to GitHub Package Registry for Bundler.",
21+
Secret: true,
22+
Composition: &schema.ValueComposition{
23+
Length: 40,
24+
Prefix: "ghp_",
25+
Charset: schema.Charset{
26+
Uppercase: true,
27+
Lowercase: true,
28+
Digits: true,
29+
},
30+
},
31+
},
32+
},
33+
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
34+
Importer: importer.TryAll(
35+
importer.TryEnvVarPair(defaultEnvVarMapping),
36+
),
37+
}
38+
}
39+
40+
var defaultEnvVarMapping = map[string]sdk.FieldName{
41+
"BUNDLE_RUBYGEMS__PKG__GITHUB__COM": fieldname.Token,
42+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package bundler
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 TestPersonalAccessTokenProvisioner(t *testing.T) {
12+
plugintest.TestProvisioner(t, PersonalAccessToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{
13+
"default": {
14+
ItemFields: map[sdk.FieldName]string{
15+
fieldname.Token: "ghp_1234567890123456789012345678901234567890",
16+
},
17+
ExpectedOutput: sdk.ProvisionOutput{
18+
Environment: map[string]string{
19+
"BUNDLE_RUBYGEMS__PKG__GITHUB__COM": "ghp_1234567890123456789012345678901234567890",
20+
},
21+
},
22+
},
23+
})
24+
}
25+
26+
func TestPersonalAccessTokenImporter(t *testing.T) {
27+
plugintest.TestImporter(t, PersonalAccessToken().Importer, map[string]plugintest.ImportCase{
28+
"environment": {
29+
Environment: map[string]string{
30+
"BUNDLE_RUBYGEMS__PKG__GITHUB__COM": "ghp_1234567890123456789012345678901234567890",
31+
},
32+
ExpectedCandidates: []sdk.ImportCandidate{
33+
{
34+
Fields: map[sdk.FieldName]string{
35+
fieldname.Token: "ghp_1234567890123456789012345678901234567890",
36+
},
37+
},
38+
},
39+
},
40+
})
41+
}

plugins/bundler/plugin.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package bundler
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: "bundler",
11+
Platform: schema.PlatformInfo{
12+
Name: "Ruby Bundler",
13+
Homepage: sdk.URL("https://bundler.io"),
14+
},
15+
Credentials: []schema.CredentialType{
16+
PersonalAccessToken(),
17+
},
18+
Executables: []schema.Executable{
19+
BundleCLI(),
20+
},
21+
}
22+
}

0 commit comments

Comments
 (0)