forked from 1Password/shell-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 1Password#201 Adding shopify plugin
- Loading branch information
Showing
4 changed files
with
172 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,70 @@ | ||
package shopify | ||
|
||
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 CLIToken() schema.CredentialType { | ||
return schema.CredentialType{ | ||
Name: credname.CLIToken, | ||
DocsURL: sdk.URL("https://shopify.com/docs/cli_token"), // TODO: Replace with actual URL | ||
ManagementURL: sdk.URL("https://console.shopify.com/user/security/tokens"), // TODO: Replace with actual URL | ||
Fields: []schema.CredentialField{ | ||
{ | ||
Name: fieldname.Token, | ||
MarkdownDescription: "Token used to authenticate to Shopify.", | ||
Secret: true, | ||
Composition: &schema.ValueComposition{ | ||
Length: 69, | ||
Prefix: "atkn_", // TODO: Check if this is correct | ||
Charset: schema.Charset{ | ||
Lowercase: true, | ||
Digits: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), | ||
Importer: importer.TryAll( | ||
importer.TryEnvVarPair(defaultEnvVarMapping), | ||
TryShopifyConfigFile(), | ||
)} | ||
} | ||
|
||
var defaultEnvVarMapping = map[string]sdk.FieldName{ | ||
"SHOPIFY_TOKEN": fieldname.Token, // TODO: Check if this is correct | ||
} | ||
|
||
// TODO: Check if the platform stores the CLI Token in a local config file, and if so, | ||
// implement the function below to add support for importing it. | ||
func TryShopifyConfigFile() 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.Token == "" { | ||
// return | ||
// } | ||
|
||
// out.AddCandidate(sdk.ImportCandidate{ | ||
// Fields: map[sdk.FieldName]string{ | ||
// fieldname.Token: config.Token, | ||
// }, | ||
// }) | ||
}) | ||
} | ||
|
||
// TODO: Implement the config file schema | ||
// type Config struct { | ||
// Token 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 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, CLIToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{ | ||
"default": { | ||
ItemFields: map[sdk.FieldName]string{ // TODO: Check if this is correct | ||
fieldname.Token: "atkn_0mgpyi6brmpxduriv7ukpp9r3lcjgsld7357svtw5fey5vlyriyauwxhgexample", | ||
}, | ||
ExpectedOutput: sdk.ProvisionOutput{ | ||
Environment: map[string]string{ | ||
"SHOPIFY_TOKEN": "atkn_0mgpyi6brmpxduriv7ukpp9r3lcjgsld7357svtw5fey5vlyriyauwxhgexample", | ||
}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestCLITokenImporter(t *testing.T) { | ||
plugintest.TestImporter(t, CLIToken().Importer, map[string]plugintest.ImportCase{ | ||
"environment": { | ||
Environment: map[string]string{ // TODO: Check if this is correct | ||
"SHOPIFY_TOKEN": "atkn_0mgpyi6brmpxduriv7ukpp9r3lcjgsld7357svtw5fey5vlyriyauwxhgexample", | ||
}, | ||
ExpectedCandidates: []sdk.ImportCandidate{ | ||
{ | ||
Fields: map[sdk.FieldName]string{ | ||
fieldname.Token: "atkn_0mgpyi6brmpxduriv7ukpp9r3lcjgsld7357svtw5fey5vlyriyauwxhgexample", | ||
}, | ||
}, | ||
}, | ||
}, | ||
// TODO: If you implemented a config file importer, add a test file example in shopify/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: "atkn_0mgpyi6brmpxduriv7ukpp9r3lcjgsld7357svtw5fey5vlyriyauwxhgexample", | ||
// }, | ||
// }, | ||
}, | ||
}, | ||
}) | ||
} |
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 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"), // TODO: Check if this is correct | ||
}, | ||
Credentials: []schema.CredentialType{ | ||
CLIToken(), | ||
}, | ||
Executables: []schema.Executable{ | ||
ShopifyCLI(), | ||
}, | ||
} | ||
} |
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 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 ShopifyCLI() schema.Executable { | ||
return schema.Executable{ | ||
Name: "Shopify CLI", | ||
Runs: []string{"shopify"}, | ||
DocsURL: sdk.URL("https://github.com/shopify/cli#readme"), | ||
NeedsAuth: needsauth.IfAll( | ||
needsauth.NotForHelpOrVersion(), | ||
needsauth.NotWithoutArgs(), | ||
), | ||
Uses: []schema.CredentialUsage{ | ||
{ | ||
Name: credname.CLIToken, | ||
}, | ||
}, | ||
} | ||
} |