From 320fb8516acfa1d44a64146f29df17ac9d6c70ec Mon Sep 17 00:00:00 2001 From: Martijn Gastkemper Date: Wed, 23 Sep 2026 18:37:26 +0200 Subject: [PATCH 1/2] Add template plugin for Stackhero --- plugins/stackhero/access_token.go | 69 ++++++++++++++++++++++++++ plugins/stackhero/access_token_test.go | 55 ++++++++++++++++++++ plugins/stackhero/plugin.go | 22 ++++++++ plugins/stackhero/stackhero.go | 25 ++++++++++ 4 files changed, 171 insertions(+) create mode 100644 plugins/stackhero/access_token.go create mode 100644 plugins/stackhero/access_token_test.go create mode 100644 plugins/stackhero/plugin.go create mode 100644 plugins/stackhero/stackhero.go diff --git a/plugins/stackhero/access_token.go b/plugins/stackhero/access_token.go new file mode 100644 index 00000000..1d6bcddf --- /dev/null +++ b/plugins/stackhero/access_token.go @@ -0,0 +1,69 @@ +package stackhero + +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 AccessToken() schema.CredentialType { + return schema.CredentialType{ + Name: credname.AccessToken, + DocsURL: sdk.URL("https://stackhero.com/docs/access_token"), // TODO: Replace with actual URL + ManagementURL: sdk.URL("https://console.stackhero.com/user/security/tokens"), // TODO: Replace with actual URL + Fields: []schema.CredentialField{ + { + Name: fieldname.Token, + MarkdownDescription: "Token used to authenticate to Stackhero.", + Secret: true, + Composition: &schema.ValueComposition{ + Length: 21, + Prefix: "usr-", // TODO: Check if this is correct + Charset: schema.Charset{ + Lowercase: true, + }, + }, + }, + }, + DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), + Importer: importer.TryAll( + importer.TryEnvVarPair(defaultEnvVarMapping), + TryStackheroConfigFile(), + )} +} + +var defaultEnvVarMapping = map[string]sdk.FieldName{ + "STACKHERO_TOKEN": fieldname.Token, // TODO: Check if this is correct +} + +// TODO: Check if the platform stores the Access Token in a local config file, and if so, +// implement the function below to add support for importing it. +func TryStackheroConfigFile() 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 +// } diff --git a/plugins/stackhero/access_token_test.go b/plugins/stackhero/access_token_test.go new file mode 100644 index 00000000..abe5c067 --- /dev/null +++ b/plugins/stackhero/access_token_test.go @@ -0,0 +1,55 @@ +package stackhero + +import ( + "testing" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/plugintest" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +func TestAccessTokenProvisioner(t *testing.T) { + plugintest.TestProvisioner(t, AccessToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{ + "default": { + ItemFields: map[sdk.FieldName]string{ // TODO: Check if this is correct + fieldname.Token: "usr-eqovniewliexample", + }, + ExpectedOutput: sdk.ProvisionOutput{ + Environment: map[string]string{ + "STACKHERO_TOKEN": "usr-eqovniewliexample", + }, + }, + }, + }) +} + +func TestAccessTokenImporter(t *testing.T) { + plugintest.TestImporter(t, AccessToken().Importer, map[string]plugintest.ImportCase{ + "environment": { + Environment: map[string]string{ // TODO: Check if this is correct + "STACKHERO_TOKEN": "usr-eqovniewliexample", + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.Token: "usr-eqovniewliexample", + }, + }, + }, + }, + // TODO: If you implemented a config file importer, add a test file example in stackhero/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: "usr-eqovniewliexample", + // }, + // }, + }, + }, + }) +} diff --git a/plugins/stackhero/plugin.go b/plugins/stackhero/plugin.go new file mode 100644 index 00000000..02ce7f79 --- /dev/null +++ b/plugins/stackhero/plugin.go @@ -0,0 +1,22 @@ +package stackhero + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/schema" +) + +func New() schema.Plugin { + return schema.Plugin{ + Name: "stackhero", + Platform: schema.PlatformInfo{ + Name: "Stackhero", + Homepage: sdk.URL("https://stackhero.com"), // TODO: Check if this is correct + }, + Credentials: []schema.CredentialType{ + AccessToken(), + }, + Executables: []schema.Executable{ + StackheroCLI(), + }, + } +} diff --git a/plugins/stackhero/stackhero.go b/plugins/stackhero/stackhero.go new file mode 100644 index 00000000..3c46d6df --- /dev/null +++ b/plugins/stackhero/stackhero.go @@ -0,0 +1,25 @@ +package stackhero + +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 StackheroCLI() schema.Executable { + return schema.Executable{ + Name: "Stackhero CLI", // TODO: Check if this is correct + Runs: []string{"stackhero"}, + DocsURL: sdk.URL("https://stackhero.com/docs/cli"), // TODO: Replace with actual URL + NeedsAuth: needsauth.IfAll( + needsauth.NotForHelpOrVersion(), + needsauth.NotWithoutArgs(), + ), + Uses: []schema.CredentialUsage{ + { + Name: credname.AccessToken, + }, + }, + } +} From 4a42cf29bda39d4bd3a8b46701ad6b7e71c03178 Mon Sep 17 00:00:00 2001 From: Martijn Gastkemper Date: Wed, 23 Sep 2026 18:38:19 +0200 Subject: [PATCH 2/2] Implement plugin for stackhero.io CLI --- plugins/stackhero/access_token.go | 38 +++----------------------- plugins/stackhero/access_token_test.go | 22 +++------------ plugins/stackhero/plugin.go | 2 +- plugins/stackhero/stackhero.go | 10 +++++-- 4 files changed, 16 insertions(+), 56 deletions(-) diff --git a/plugins/stackhero/access_token.go b/plugins/stackhero/access_token.go index 1d6bcddf..e7764930 100644 --- a/plugins/stackhero/access_token.go +++ b/plugins/stackhero/access_token.go @@ -1,8 +1,6 @@ package stackhero import ( - "context" - "github.com/1Password/shell-plugins/sdk" "github.com/1Password/shell-plugins/sdk/importer" "github.com/1Password/shell-plugins/sdk/provision" @@ -14,8 +12,8 @@ import ( func AccessToken() schema.CredentialType { return schema.CredentialType{ Name: credname.AccessToken, - DocsURL: sdk.URL("https://stackhero.com/docs/access_token"), // TODO: Replace with actual URL - ManagementURL: sdk.URL("https://console.stackhero.com/user/security/tokens"), // TODO: Replace with actual URL + DocsURL: sdk.URL("https://www.stackhero.io/stackhero/documentations/Use-the-CLI#Non-interactive-authentication-for-scripts-CI-and-automation"), + ManagementURL: sdk.URL("https://dashboard.stackhero.io/account/"), Fields: []schema.CredentialField{ { Name: fieldname.Token, @@ -23,7 +21,7 @@ func AccessToken() schema.CredentialType { Secret: true, Composition: &schema.ValueComposition{ Length: 21, - Prefix: "usr-", // TODO: Check if this is correct + Prefix: "usr-", Charset: schema.Charset{ Lowercase: true, }, @@ -33,37 +31,9 @@ func AccessToken() schema.CredentialType { DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), Importer: importer.TryAll( importer.TryEnvVarPair(defaultEnvVarMapping), - TryStackheroConfigFile(), )} } var defaultEnvVarMapping = map[string]sdk.FieldName{ - "STACKHERO_TOKEN": fieldname.Token, // TODO: Check if this is correct -} - -// TODO: Check if the platform stores the Access Token in a local config file, and if so, -// implement the function below to add support for importing it. -func TryStackheroConfigFile() 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, - // }, - // }) - }) + "STACKHERO_TOKEN": fieldname.Token, } - -// TODO: Implement the config file schema -// type Config struct { -// Token string -// } diff --git a/plugins/stackhero/access_token_test.go b/plugins/stackhero/access_token_test.go index abe5c067..99d41982 100644 --- a/plugins/stackhero/access_token_test.go +++ b/plugins/stackhero/access_token_test.go @@ -2,16 +2,16 @@ package stackhero import ( "testing" - + "github.com/1Password/shell-plugins/sdk" "github.com/1Password/shell-plugins/sdk/plugintest" "github.com/1Password/shell-plugins/sdk/schema/fieldname" ) - + func TestAccessTokenProvisioner(t *testing.T) { plugintest.TestProvisioner(t, AccessToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{ "default": { - ItemFields: map[sdk.FieldName]string{ // TODO: Check if this is correct + ItemFields: map[sdk.FieldName]string{ fieldname.Token: "usr-eqovniewliexample", }, ExpectedOutput: sdk.ProvisionOutput{ @@ -26,7 +26,7 @@ func TestAccessTokenProvisioner(t *testing.T) { func TestAccessTokenImporter(t *testing.T) { plugintest.TestImporter(t, AccessToken().Importer, map[string]plugintest.ImportCase{ "environment": { - Environment: map[string]string{ // TODO: Check if this is correct + Environment: map[string]string{ "STACKHERO_TOKEN": "usr-eqovniewliexample", }, ExpectedCandidates: []sdk.ImportCandidate{ @@ -37,19 +37,5 @@ func TestAccessTokenImporter(t *testing.T) { }, }, }, - // TODO: If you implemented a config file importer, add a test file example in stackhero/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: "usr-eqovniewliexample", - // }, - // }, - }, - }, }) } diff --git a/plugins/stackhero/plugin.go b/plugins/stackhero/plugin.go index 02ce7f79..dd37cdec 100644 --- a/plugins/stackhero/plugin.go +++ b/plugins/stackhero/plugin.go @@ -10,7 +10,7 @@ func New() schema.Plugin { Name: "stackhero", Platform: schema.PlatformInfo{ Name: "Stackhero", - Homepage: sdk.URL("https://stackhero.com"), // TODO: Check if this is correct + Homepage: sdk.URL("https://www.stackhero.io/"), }, Credentials: []schema.CredentialType{ AccessToken(), diff --git a/plugins/stackhero/stackhero.go b/plugins/stackhero/stackhero.go index 3c46d6df..97cf6735 100644 --- a/plugins/stackhero/stackhero.go +++ b/plugins/stackhero/stackhero.go @@ -9,11 +9,15 @@ import ( func StackheroCLI() schema.Executable { return schema.Executable{ - Name: "Stackhero CLI", // TODO: Check if this is correct - Runs: []string{"stackhero"}, - DocsURL: sdk.URL("https://stackhero.com/docs/cli"), // TODO: Replace with actual URL + Name: "Stackhero CLI", + Runs: []string{"stackhero"}, + DocsURL: sdk.URL("https://www.stackhero.io/stackhero/documentations/Use-the-CLI"), NeedsAuth: needsauth.IfAll( + needsauth.NotForCommand("login"), + needsauth.NotForCommand("logout"), + needsauth.NotForCommand("self-update"), needsauth.NotForHelpOrVersion(), + needsauth.NotWhenContainsArgs("--help-agents"), needsauth.NotWithoutArgs(), ), Uses: []schema.CredentialUsage{