Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Shopify Themes CLI Plugin (The Second Attempt™️) #434

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
51 changes: 51 additions & 0 deletions plugins/shopify/access_key.go
Original file line number Diff line number Diff line change
@@ -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
jerryzhou196 marked this conversation as resolved.
Show resolved Hide resolved
// 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
}
22 changes: 22 additions & 0 deletions plugins/shopify/access_key_test.go
Original file line number Diff line number Diff line change
@@ -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"},
},
},
})
}
22 changes: 22 additions & 0 deletions plugins/shopify/plugin.go
Original file line number Diff line number Diff line change
@@ -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(),
},
}
}
27 changes: 27 additions & 0 deletions plugins/shopify/theme.go
Original file line number Diff line number Diff line change
@@ -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,
},
},
}
}
5 changes: 4 additions & 1 deletion sdk/importer/no_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
}
}