-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,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, | ||
} |
This file contains 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,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", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |
This file contains 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,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, | ||
}, | ||
}, | ||
} | ||
} |
This file contains 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 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(), | ||
}, | ||
} | ||
} |