-
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
173 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,71 @@ | ||
package deta | ||
|
||
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 APIKey() schema.CredentialType { | ||
return schema.CredentialType{ | ||
Name: credname.APIKey, | ||
DocsURL: sdk.URL("https://deta.com/docs/api_key"), // TODO: Replace with actual URL | ||
ManagementURL: sdk.URL("https://console.deta.com/user/security/tokens"), // TODO: Replace with actual URL | ||
Fields: []schema.CredentialField{ | ||
{ | ||
Name: fieldname.APIKey, | ||
MarkdownDescription: "API Key used to authenticate to Deta.", | ||
Secret: true, | ||
Composition: &schema.ValueComposition{ | ||
Length: 25, | ||
Prefix: "bE53FsM6_", // TODO: Check if this is correct | ||
Charset: schema.Charset{ | ||
Uppercase: true, | ||
Lowercase: true, | ||
Digits: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), | ||
Importer: importer.TryAll( | ||
importer.TryEnvVarPair(defaultEnvVarMapping), | ||
TryDetaConfigFile(), | ||
)} | ||
} | ||
|
||
var defaultEnvVarMapping = map[string]sdk.FieldName{ | ||
"DETA_API_KEY": fieldname.APIKey, // TODO: Check if this is correct | ||
} | ||
|
||
// TODO: Check if the platform stores the API Key in a local config file, and if so, | ||
// implement the function below to add support for importing it. | ||
func TryDetaConfigFile() sdk.Importer { | ||
return importer.TryFile("~/path/to/config/file.yml", func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) { | ||
// var config Config | ||
// if err := contents.ToYAML(&config); err != nil { | ||
// out.AddError(err) | ||
// return | ||
// } | ||
|
||
// if config.APIKey == "" { | ||
// return | ||
// } | ||
|
||
// out.AddCandidate(sdk.ImportCandidate{ | ||
// Fields: map[sdk.FieldName]string{ | ||
// fieldname.APIKey: config.APIKey, | ||
// }, | ||
// }) | ||
}) | ||
} | ||
|
||
// TODO: Implement the config file schema | ||
// type Config struct { | ||
// APIKey string | ||
// } |
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,55 @@ | ||
package deta | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/1Password/shell-plugins/sdk" | ||
"github.com/1Password/shell-plugins/sdk/plugintest" | ||
"github.com/1Password/shell-plugins/sdk/schema/fieldname" | ||
) | ||
|
||
func TestAPIKeyProvisioner(t *testing.T) { | ||
plugintest.TestProvisioner(t, APIKey().DefaultProvisioner, map[string]plugintest.ProvisionCase{ | ||
"default": { | ||
ItemFields: map[sdk.FieldName]string{ // TODO: Check if this is correct | ||
fieldname.APIKey: "bE53FsM6_MPPjP3sg6EXAMPLE", | ||
}, | ||
ExpectedOutput: sdk.ProvisionOutput{ | ||
Environment: map[string]string{ | ||
"DETA_API_KEY": "bE53FsM6_MPPjP3sg6EXAMPLE", | ||
}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAPIKeyImporter(t *testing.T) { | ||
plugintest.TestImporter(t, APIKey().Importer, map[string]plugintest.ImportCase{ | ||
"environment": { | ||
Environment: map[string]string{ // TODO: Check if this is correct | ||
"DETA_API_KEY": "bE53FsM6_MPPjP3sg6EXAMPLE", | ||
}, | ||
ExpectedCandidates: []sdk.ImportCandidate{ | ||
{ | ||
Fields: map[sdk.FieldName]string{ | ||
fieldname.APIKey: "bE53FsM6_MPPjP3sg6EXAMPLE", | ||
}, | ||
}, | ||
}, | ||
}, | ||
// TODO: If you implemented a config file importer, add a test file example in deta/test-fixtures | ||
// and fill the necessary details in the test template below. | ||
"config file": { | ||
Files: map[string]string{ | ||
// "~/path/to/config.yml": plugintest.LoadFixture(t, "config.yml"), | ||
}, | ||
ExpectedCandidates: []sdk.ImportCandidate{ | ||
// { | ||
// Fields: map[sdk.FieldName]string{ | ||
// fieldname.Token: "bE53FsM6_MPPjP3sg6EXAMPLE", | ||
// }, | ||
// }, | ||
}, | ||
}, | ||
}) | ||
} |
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 deta | ||
|
||
import ( | ||
"github.com/1Password/shell-plugins/sdk" | ||
"github.com/1Password/shell-plugins/sdk/schema" | ||
) | ||
|
||
func New() schema.Plugin { | ||
return schema.Plugin{ | ||
Name: "deta", | ||
Platform: schema.PlatformInfo{ | ||
Name: "Deta", | ||
Homepage: sdk.URL("https://deta.com"), // TODO: Check if this is correct | ||
}, | ||
Credentials: []schema.CredentialType{ | ||
APIKey(), | ||
}, | ||
Executables: []schema.Executable{ | ||
DetaCLI(), | ||
}, | ||
} | ||
} |
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 deta | ||
|
||
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 DetaCLI() schema.Executable { | ||
return schema.Executable{ | ||
Name: "Deta CLI", // TODO: Check if this is correct | ||
Runs: []string{"space"}, | ||
DocsURL: sdk.URL("https://deta.com/docs/cli"), // TODO: Replace with actual URL | ||
NeedsAuth: needsauth.IfAll( | ||
needsauth.NotForHelpOrVersion(), | ||
needsauth.NotWithoutArgs(), | ||
), | ||
Uses: []schema.CredentialUsage{ | ||
{ | ||
Name: credname.APIKey, | ||
}, | ||
}, | ||
} | ||
} |