Skip to content

Commit d7a779f

Browse files
authored
Merge pull request #269 from owenvoke/feature/ohdear-cli
feat: add Oh Dear CLI plugin
2 parents 09f8e19 + a23c53a commit d7a779f

File tree

4 files changed

+128
-0
lines changed

4 files changed

+128
-0
lines changed

plugins/ohdear/api_token.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package ohdear
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 APIToken() schema.CredentialType {
13+
return schema.CredentialType{
14+
Name: credname.APIToken,
15+
DocsURL: sdk.URL("https://ohdear.app/docs/integrations/the-oh-dear-api#get-your-api-token"),
16+
ManagementURL: sdk.URL("https://ohdear.app/user/api-tokens"),
17+
Fields: []schema.CredentialField{
18+
{
19+
Name: fieldname.Token,
20+
MarkdownDescription: "Token used to authenticate to Oh Dear.",
21+
Secret: true,
22+
Composition: &schema.ValueComposition{
23+
Length: 40,
24+
Charset: schema.Charset{
25+
Uppercase: true,
26+
Lowercase: true,
27+
Digits: true,
28+
},
29+
},
30+
},
31+
},
32+
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
33+
Importer: importer.TryAll(
34+
importer.TryEnvVarPair(defaultEnvVarMapping),
35+
)}
36+
}
37+
38+
var defaultEnvVarMapping = map[string]sdk.FieldName{
39+
"OHDEAR_API_TOKEN": fieldname.Token,
40+
}

plugins/ohdear/api_token_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package ohdear
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 TestAPITokenProvisioner(t *testing.T) {
12+
plugintest.TestProvisioner(t, APIToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{
13+
"default": {
14+
ItemFields: map[sdk.FieldName]string{
15+
fieldname.Token: "SZ5rluwzbtMyyQFQNoeqEFbpVbTL0ItsXEXAMPLE",
16+
},
17+
ExpectedOutput: sdk.ProvisionOutput{
18+
Environment: map[string]string{
19+
"OHDEAR_API_TOKEN": "SZ5rluwzbtMyyQFQNoeqEFbpVbTL0ItsXEXAMPLE",
20+
},
21+
},
22+
},
23+
})
24+
}
25+
26+
func TestAPITokenImporter(t *testing.T) {
27+
plugintest.TestImporter(t, APIToken().Importer, map[string]plugintest.ImportCase{
28+
"environment": {
29+
Environment: map[string]string{
30+
"OHDEAR_API_TOKEN": "SZ5rluwzbtMyyQFQNoeqEFbpVbTL0ItsXEXAMPLE",
31+
},
32+
ExpectedCandidates: []sdk.ImportCandidate{
33+
{
34+
Fields: map[sdk.FieldName]string{
35+
fieldname.Token: "SZ5rluwzbtMyyQFQNoeqEFbpVbTL0ItsXEXAMPLE",
36+
},
37+
},
38+
},
39+
},
40+
})
41+
}

plugins/ohdear/ohdear.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package ohdear
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 OhDearCLI() schema.Executable {
11+
return schema.Executable{
12+
Name: "Oh Dear CLI",
13+
Runs: []string{"ohdear"},
14+
DocsURL: sdk.URL("https://ohdear.app/docs/integrations/our-cli-tool"),
15+
NeedsAuth: needsauth.IfAll(
16+
needsauth.NotForHelpOrVersion(),
17+
needsauth.NotWithoutArgs(),
18+
),
19+
Uses: []schema.CredentialUsage{
20+
{
21+
Name: credname.APIToken,
22+
},
23+
},
24+
}
25+
}

plugins/ohdear/plugin.go

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

0 commit comments

Comments
 (0)