diff --git a/plugins/shopify/access_key.go b/plugins/shopify/access_key.go new file mode 100644 index 000000000..ba4cd3ff2 --- /dev/null +++ b/plugins/shopify/access_key.go @@ -0,0 +1,51 @@ +package shopify + +import ( + "context" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/importer" + "github.com/1Password/shell-plugins/sdk/schema" + "github.com/1Password/shell-plugins/sdk/schema/credname" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +func AccessKey() schema.CredentialType { + return schema.CredentialType{ + Name: credname.CLIToken, + DocsURL: sdk.URL("https://admin.shopify.com/store/{YOUR_STORE_ID}/apps/theme-kit-access"), + Fields: []schema.CredentialField{ + { + Name: fieldname.Token, + MarkdownDescription: "Token used to authenticate to Shopify Themes.", + Secret: true, + Composition: &schema.ValueComposition{ + Length: 39, + Prefix: "shptka_", + Charset: schema.Charset{ + Lowercase: true, + Digits: true, + }, + }, + }, + }, + // Can't Implement Shopify environment parsing as the files are stored by project directory instead of a fixed location + // See: https://shopify.dev/docs/themes/tools/cli/environments + Importer: importer.NoOp(), + DefaultProvisioner: shopifyThemeProvisioner{}, + } +} + +type shopifyThemeProvisioner struct{} + +func (v shopifyThemeProvisioner) Description() string { + return "Shopify Theme CLI password provisioner" +} + +func (v shopifyThemeProvisioner) Provision(ctx context.Context, input sdk.ProvisionInput, output *sdk.ProvisionOutput) { + output.AddArgs("--password", input.ItemFields[fieldname.Token]) +} + +func (v shopifyThemeProvisioner) Deprovision(ctx context.Context, input sdk.DeprovisionInput, output *sdk.DeprovisionOutput) { + // No Operator +} diff --git a/plugins/shopify/access_key_test.go b/plugins/shopify/access_key_test.go new file mode 100644 index 000000000..64ead8745 --- /dev/null +++ b/plugins/shopify/access_key_test.go @@ -0,0 +1,22 @@ +package shopify + +import ( + "testing" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/plugintest" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +func TestCLITokenProvisioner(t *testing.T) { + plugintest.TestProvisioner(t, AccessKey().DefaultProvisioner, map[string]plugintest.ProvisionCase{ + "default": { + ItemFields: map[sdk.FieldName]string{ + fieldname.Token: "shptka_ql5v31c1kcuozk8lfdfqvuvfzexample", + }, + ExpectedOutput: sdk.ProvisionOutput{ + CommandLine: []string{"--password", "shptka_ql5v31c1kcuozk8lfdfqvuvfzexample"}, + }, + }, + }) +} diff --git a/plugins/shopify/plugin.go b/plugins/shopify/plugin.go new file mode 100644 index 000000000..b9eb99975 --- /dev/null +++ b/plugins/shopify/plugin.go @@ -0,0 +1,22 @@ +package shopify + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/schema" +) + +func New() schema.Plugin { + return schema.Plugin{ + Name: "shopify", + Platform: schema.PlatformInfo{ + Name: "Shopify", + Homepage: sdk.URL("https://shopify.com"), + }, + Credentials: []schema.CredentialType{ + AccessKey(), + }, + Executables: []schema.Executable{ + ShopifyThemeCLI(), + }, + } +} diff --git a/plugins/shopify/theme.go b/plugins/shopify/theme.go new file mode 100644 index 000000000..61cc90ae8 --- /dev/null +++ b/plugins/shopify/theme.go @@ -0,0 +1,27 @@ +package shopify + +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 ShopifyThemeCLI() schema.Executable { + return schema.Executable{ + Name: "Shopify CLI", + Runs: []string{"shopify"}, + DocsURL: sdk.URL("https://github.com/Shopify/cli/blob/main/packages/cli/README.md#commands"), + NeedsAuth: needsauth.IfAll( + needsauth.ForCommand("theme"), + needsauth.NotForHelpOrVersion(), + needsauth.NotWhenContainsArgs("--password"), + needsauth.NotWithoutArgs(), + ), + Uses: []schema.CredentialUsage{ + { + Name: credname.CLIToken, + }, + }, + } +} diff --git a/sdk/importer/no_op.go b/sdk/importer/no_op.go index c792c2412..e7f224f00 100644 --- a/sdk/importer/no_op.go +++ b/sdk/importer/no_op.go @@ -8,5 +8,8 @@ import ( // NoOp can be used as an importer stub while developing plugins. func NoOp() sdk.Importer { - return func(ctx context.Context, in sdk.ImportInput, out *sdk.ImportOutput) {} + return func(ctx context.Context, in sdk.ImportInput, out *sdk.ImportOutput) { + attempt := out.NewAttempt(SourceEnvVars("")) + attempt.AddCandidate(sdk.ImportCandidate{}) + } }