Skip to content

Commit

Permalink
Merge pull request #269 from owenvoke/feature/ohdear-cli
Browse files Browse the repository at this point in the history
feat: add Oh Dear CLI plugin
  • Loading branch information
hculea committed Jun 27, 2023
2 parents 09f8e19 + a23c53a commit d7a779f
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
40 changes: 40 additions & 0 deletions plugins/ohdear/api_token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ohdear

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 APIToken() schema.CredentialType {
return schema.CredentialType{
Name: credname.APIToken,
DocsURL: sdk.URL("https://ohdear.app/docs/integrations/the-oh-dear-api#get-your-api-token"),
ManagementURL: sdk.URL("https://ohdear.app/user/api-tokens"),
Fields: []schema.CredentialField{
{
Name: fieldname.Token,
MarkdownDescription: "Token used to authenticate to Oh Dear.",
Secret: true,
Composition: &schema.ValueComposition{
Length: 40,
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{
"OHDEAR_API_TOKEN": fieldname.Token,
}
41 changes: 41 additions & 0 deletions plugins/ohdear/api_token_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package ohdear

import (
"testing"

"github.com/1Password/shell-plugins/sdk"
"github.com/1Password/shell-plugins/sdk/plugintest"
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
)

func TestAPITokenProvisioner(t *testing.T) {
plugintest.TestProvisioner(t, APIToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{
"default": {
ItemFields: map[sdk.FieldName]string{
fieldname.Token: "SZ5rluwzbtMyyQFQNoeqEFbpVbTL0ItsXEXAMPLE",
},
ExpectedOutput: sdk.ProvisionOutput{
Environment: map[string]string{
"OHDEAR_API_TOKEN": "SZ5rluwzbtMyyQFQNoeqEFbpVbTL0ItsXEXAMPLE",
},
},
},
})
}

func TestAPITokenImporter(t *testing.T) {
plugintest.TestImporter(t, APIToken().Importer, map[string]plugintest.ImportCase{
"environment": {
Environment: map[string]string{
"OHDEAR_API_TOKEN": "SZ5rluwzbtMyyQFQNoeqEFbpVbTL0ItsXEXAMPLE",
},
ExpectedCandidates: []sdk.ImportCandidate{
{
Fields: map[sdk.FieldName]string{
fieldname.Token: "SZ5rluwzbtMyyQFQNoeqEFbpVbTL0ItsXEXAMPLE",
},
},
},
},
})
}
25 changes: 25 additions & 0 deletions plugins/ohdear/ohdear.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ohdear

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 OhDearCLI() schema.Executable {
return schema.Executable{
Name: "Oh Dear CLI",
Runs: []string{"ohdear"},
DocsURL: sdk.URL("https://ohdear.app/docs/integrations/our-cli-tool"),
NeedsAuth: needsauth.IfAll(
needsauth.NotForHelpOrVersion(),
needsauth.NotWithoutArgs(),
),
Uses: []schema.CredentialUsage{
{
Name: credname.APIToken,
},
},
}
}
22 changes: 22 additions & 0 deletions plugins/ohdear/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ohdear

import (
"github.com/1Password/shell-plugins/sdk"
"github.com/1Password/shell-plugins/sdk/schema"
)

func New() schema.Plugin {
return schema.Plugin{
Name: "ohdear",
Platform: schema.PlatformInfo{
Name: "Oh Dear",
Homepage: sdk.URL("https://ohdear.app"),
},
Credentials: []schema.CredentialType{
APIToken(),
},
Executables: []schema.Executable{
OhDearCLI(),
},
}
}

0 comments on commit d7a779f

Please sign in to comment.