Skip to content

Commit a806116

Browse files
committed
Create initial scaffolded plugin
1 parent 1f44f6e commit a806116

File tree

4 files changed

+172
-0
lines changed

4 files changed

+172
-0
lines changed

plugins/localstack/api_key.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package localstack
2+
3+
import (
4+
"context"
5+
6+
"github.com/1Password/shell-plugins/sdk"
7+
"github.com/1Password/shell-plugins/sdk/importer"
8+
"github.com/1Password/shell-plugins/sdk/provision"
9+
"github.com/1Password/shell-plugins/sdk/schema"
10+
"github.com/1Password/shell-plugins/sdk/schema/credname"
11+
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
12+
)
13+
14+
func APIKey() schema.CredentialType {
15+
return schema.CredentialType{
16+
Name: credname.APIKey,
17+
DocsURL: sdk.URL("https://localstack.com/docs/api_key"), // TODO: Replace with actual URL
18+
ManagementURL: sdk.URL("https://console.localstack.com/user/security/tokens"), // TODO: Replace with actual URL
19+
Fields: []schema.CredentialField{
20+
{
21+
Name: fieldname.APIKey,
22+
MarkdownDescription: "API Key used to authenticate to LocalStack.",
23+
Secret: true,
24+
Composition: &schema.ValueComposition{
25+
Length: 10,
26+
Charset: schema.Charset{
27+
Uppercase: true,
28+
Lowercase: true,
29+
Digits: true,
30+
},
31+
},
32+
},
33+
},
34+
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
35+
Importer: importer.TryAll(
36+
importer.TryEnvVarPair(defaultEnvVarMapping),
37+
TryLocalStackConfigFile(),
38+
)}
39+
}
40+
41+
var defaultEnvVarMapping = map[string]sdk.FieldName{
42+
"LOCALSTACK_API_KEY": fieldname.APIKey, // TODO: Check if this is correct
43+
}
44+
45+
// TODO: Check if the platform stores the API Key in a local config file, and if so,
46+
// implement the function below to add support for importing it.
47+
func TryLocalStackConfigFile() sdk.Importer {
48+
return importer.TryFile("~/path/to/config/file.yml", func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) {
49+
// var config Config
50+
// if err := contents.ToYAML(&config); err != nil {
51+
// out.AddError(err)
52+
// return
53+
// }
54+
55+
// if config.APIKey == "" {
56+
// return
57+
// }
58+
59+
// out.AddCandidate(sdk.ImportCandidate{
60+
// Fields: map[sdk.FieldName]string{
61+
// fieldname.APIKey: config.APIKey,
62+
// },
63+
// })
64+
})
65+
}
66+
67+
// TODO: Implement the config file schema
68+
// type Config struct {
69+
// APIKey string
70+
// }

plugins/localstack/api_key_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package localstack
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 TestAPIKeyProvisioner(t *testing.T) {
12+
plugintest.TestProvisioner(t, APIKey().DefaultProvisioner, map[string]plugintest.ProvisionCase{
13+
"default": {
14+
ItemFields: map[sdk.FieldName]string{ // TODO: Check if this is correct
15+
fieldname.APIKey: "SzCEXAMPLE",
16+
},
17+
ExpectedOutput: sdk.ProvisionOutput{
18+
Environment: map[string]string{
19+
"LOCALSTACK_API_KEY": "SzCEXAMPLE",
20+
},
21+
},
22+
},
23+
})
24+
}
25+
26+
func TestAPIKeyImporter(t *testing.T) {
27+
plugintest.TestImporter(t, APIKey().Importer, map[string]plugintest.ImportCase{
28+
"environment": {
29+
Environment: map[string]string{ // TODO: Check if this is correct
30+
"LOCALSTACK_API_KEY": "SzCEXAMPLE",
31+
},
32+
ExpectedCandidates: []sdk.ImportCandidate{
33+
{
34+
Fields: map[sdk.FieldName]string{
35+
fieldname.APIKey: "SzCEXAMPLE",
36+
},
37+
},
38+
},
39+
},
40+
// TODO: If you implemented a config file importer, add a test file example in localstack/test-fixtures
41+
// and fill the necessary details in the test template below.
42+
"config file": {
43+
Files: map[string]string{
44+
// "~/path/to/config.yml": plugintest.LoadFixture(t, "config.yml"),
45+
},
46+
ExpectedCandidates: []sdk.ImportCandidate{
47+
// {
48+
// Fields: map[sdk.FieldName]string{
49+
// fieldname.Token: "SzCEXAMPLE",
50+
// },
51+
// },
52+
},
53+
},
54+
})
55+
}

plugins/localstack/localstack.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package localstack
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 LocalStackCLI() schema.Executable {
11+
return schema.Executable{
12+
Name: "LocalStack CLI", // TODO: Check if this is correct
13+
Runs: []string{"localstack"},
14+
DocsURL: sdk.URL("https://localstack.com/docs/cli"), // TODO: Replace with actual URL
15+
NeedsAuth: needsauth.IfAll(
16+
needsauth.NotForHelpOrVersion(),
17+
needsauth.NotWithoutArgs(),
18+
),
19+
Uses: []schema.CredentialUsage{
20+
{
21+
Name: credname.APIKey,
22+
},
23+
},
24+
}
25+
}

plugins/localstack/plugin.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package localstack
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: "localstack",
11+
Platform: schema.PlatformInfo{
12+
Name: "LocalStack",
13+
Homepage: sdk.URL("https://localstack.com"), // TODO: Check if this is correct
14+
},
15+
Credentials: []schema.CredentialType{
16+
APIKey(),
17+
},
18+
Executables: []schema.Executable{
19+
LocalStackCLI(),
20+
},
21+
}
22+
}

0 commit comments

Comments
 (0)