Repository navigation
Add plugin for Nimble package manager #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
electrocally
wants to merge
4
commits into
1Password:main
Choose a base branch
from
electrocally:add/nimble
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,27 @@ | ||
| package nimble | ||
|
|
||
| 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 nimCLI() schema.Executable { | ||
| return schema.Executable{ | ||
| Name: "Nimble CLI", | ||
| Runs: []string{"nimble"}, | ||
| DocsURL: sdk.URL("https://github.com/nim-lang/nimble"), | ||
| NeedsAuth: needsauth.IfAll( | ||
| needsauth.IfAny( | ||
| needsauth.ForCommand("publish"), | ||
| ), | ||
| needsauth.NotForHelp(), | ||
| ), | ||
| Uses: []schema.CredentialUsage{ | ||
| { | ||
| Name: credname.PersonalAccessToken, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
This file contains hidden or 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,59 @@ | ||
| package nimble | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "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://github.com/nim-lang/nimble"), | ||
| ManagementURL: sdk.URL("https://nimble.directory/about.html"), | ||
| Fields: []schema.CredentialField{ | ||
| { | ||
| Name: fieldname.Token, | ||
| MarkdownDescription: "Token used to authenticate to GitHub.", | ||
| Secret: true, | ||
| Composition: &schema.ValueComposition{ | ||
| Length: 40, | ||
| Prefix: "ghp_", | ||
| Charset: schema.Charset{ | ||
| Uppercase: true, | ||
| Lowercase: true, | ||
| Digits: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| DefaultProvisioner: provision.EnvVars(nimbleDefaultEnvVarMapping), | ||
| Importer: importer.TryAll( | ||
| importer.TryEnvVarPair(nimbleDefaultEnvVarMapping), | ||
| TryNimbleConfigFile(), | ||
| ), | ||
| } | ||
| } | ||
|
|
||
| var nimbleDefaultEnvVarMapping = map[string]sdk.FieldName{ | ||
| "NIMBLE_GITHUB_API_TOKEN": fieldname.Token, | ||
|
AndyTitu marked this conversation as resolved.
|
||
| } | ||
|
|
||
| func TryNimbleConfigFile() sdk.Importer { | ||
| return importer.TryFile("~/.nimble/github_api_token", func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) { | ||
| credential := contents.ToString() | ||
| fields := make(map[sdk.FieldName]string) | ||
|
|
||
| if len(credential) != 0 { | ||
| fields[fieldname.Token] = credential | ||
| } | ||
| out.AddCandidate(sdk.ImportCandidate{ | ||
| Fields: fields, | ||
| }) | ||
| }) | ||
| } | ||
This file contains hidden or 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 nimble | ||
|
|
||
| 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_ahhfw82h48fh72nfn29fn291nwidhf8EXAMPLE", | ||
| }, | ||
| ExpectedOutput: sdk.ProvisionOutput{ | ||
| Environment: map[string]string{ | ||
| "NIMBLE_GITHUB_API_TOKEN": "ghp_ahhfw82h48fh72nfn29fn291nwidhf8EXAMPLE", | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func TestPersonalAccessTokenImporter(t *testing.T) { | ||
| plugintest.TestImporter(t, PersonalAccessToken().Importer, map[string]plugintest.ImportCase{ | ||
| "environment": { | ||
| Environment: map[string]string{ | ||
| "NIMBLE_GITHUB_API_TOKEN": "ghp_ahhfw82h48fh72nfn29fn291nwidhf8EXAMPLE", | ||
| }, | ||
| ExpectedCandidates: []sdk.ImportCandidate{ | ||
| { | ||
| Fields: map[sdk.FieldName]string{ | ||
| fieldname.Token: "ghp_ahhfw82h48fh72nfn29fn291nwidhf8EXAMPLE", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| "config file": { | ||
| Files: map[string]string{ | ||
| "~/.nimble/github_api_token": plugintest.LoadFixture(t, "github_api_token"), | ||
| }, | ||
| ExpectedCandidates: []sdk.ImportCandidate{ | ||
| { | ||
| Fields: map[sdk.FieldName]string{ | ||
| fieldname.Token: "ghp_ahhfw82h48fh72nfn29fn291nwidhf8EXAMPLE", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| } |
This file contains hidden or 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 nimble | ||
|
|
||
| import ( | ||
| "github.com/1Password/shell-plugins/sdk" | ||
| "github.com/1Password/shell-plugins/sdk/schema" | ||
| ) | ||
|
|
||
| func New() schema.Plugin { | ||
| return schema.Plugin{ | ||
| Name: "nimble", | ||
| Platform: schema.PlatformInfo{ | ||
| Name: "Nimble", | ||
| Homepage: sdk.URL("https://nimble.directory/"), | ||
| }, | ||
| Credentials: []schema.CredentialType{ | ||
| PersonalAccessToken(), | ||
| }, | ||
| Executables: []schema.Executable{ | ||
| nimCLI(), | ||
| }, | ||
| } | ||
| } |
This file contains hidden or 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 @@ | ||
| ghp_ahhfw82h48fh72nfn29fn291nwidhf8EXAMPLE | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add an extra line |
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for
IfAnyin this situation, since it only contains one rule.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has yet to be resolved