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
27 changes: 27 additions & 0 deletions plugins/nimble/nimble.go
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(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for IfAny in this situation, since it only contains one rule.

Copy link
Copy Markdown
Contributor

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

needsauth.ForCommand("publish"),
),
needsauth.NotForHelp(),
),
Uses: []schema.CredentialUsage{
{
Name: credname.PersonalAccessToken,
},
},
}
}
59 changes: 59 additions & 0 deletions plugins/nimble/personal_access_token.go
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,
Comment thread
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,
})
})
}
53 changes: 53 additions & 0 deletions plugins/nimble/personal_access_token_test.go
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",
},
},
},
},
})
}
22 changes: 22 additions & 0 deletions plugins/nimble/plugin.go
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(),
},
}
}
1 change: 1 addition & 0 deletions plugins/nimble/test-fixtures/github_api_token
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ghp_ahhfw82h48fh72nfn29fn291nwidhf8EXAMPLE

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add an extra line

Loading