From fcf1e683963879596d53b42e6065267d4ee93d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Thu, 16 Jul 2026 17:46:40 -0600 Subject: [PATCH] Add shell plugin for Netlify CLI --- plugins/netlify/netlify.go | 30 ++++++++++++++ plugins/netlify/personal_access_token.go | 31 ++++++++++++++ plugins/netlify/personal_access_token_test.go | 41 +++++++++++++++++++ plugins/netlify/plugin.go | 22 ++++++++++ 4 files changed, 124 insertions(+) create mode 100644 plugins/netlify/netlify.go create mode 100644 plugins/netlify/personal_access_token.go create mode 100644 plugins/netlify/personal_access_token_test.go create mode 100644 plugins/netlify/plugin.go diff --git a/plugins/netlify/netlify.go b/plugins/netlify/netlify.go new file mode 100644 index 000000000..eb122895d --- /dev/null +++ b/plugins/netlify/netlify.go @@ -0,0 +1,30 @@ +package netlify + +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 NetlifyCLI() schema.Executable { + return schema.Executable{ + Name: "Netlify CLI", + Runs: []string{"netlify"}, + DocsURL: sdk.URL("https://cli.netlify.com"), + NeedsAuth: needsauth.IfAll( + needsauth.NotForHelpOrVersion(), + needsauth.NotWithoutArgs(), + needsauth.NotWhenContainsArgs("login"), + needsauth.NotForExactArgs("logout"), + needsauth.NotWhenContainsArgs("switch"), + needsauth.NotWhenContainsArgs("completion"), + needsauth.NotWhenContainsArgs("unlink"), + ), + Uses: []schema.CredentialUsage{ + { + Name: credname.PersonalAccessToken, + }, + }, + } +} diff --git a/plugins/netlify/personal_access_token.go b/plugins/netlify/personal_access_token.go new file mode 100644 index 000000000..660b99717 --- /dev/null +++ b/plugins/netlify/personal_access_token.go @@ -0,0 +1,31 @@ +package netlify + +import ( + "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 PersonalAccessToken() schema.CredentialType { + return schema.CredentialType{ + Name: credname.PersonalAccessToken, + DocsURL: sdk.URL("https://docs.netlify.com/api-and-cli-guides/cli-guides/get-started-with-cli"), + ManagementURL: sdk.URL("https://app.netlify.com/user/applications#personal-access-tokens"), + Fields: []schema.CredentialField{ + { + Name: fieldname.Token, + MarkdownDescription: "Token used to authenticate to Netlify.", + Secret: true, + }, + }, + DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), + Importer: importer.TryEnvVarPair(defaultEnvVarMapping), + } +} + +var defaultEnvVarMapping = map[string]sdk.FieldName{ + "NETLIFY_AUTH_TOKEN": fieldname.Token, +} diff --git a/plugins/netlify/personal_access_token_test.go b/plugins/netlify/personal_access_token_test.go new file mode 100644 index 000000000..598570059 --- /dev/null +++ b/plugins/netlify/personal_access_token_test.go @@ -0,0 +1,41 @@ +package netlify + +import ( + "testing" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/plugintest" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +func TestPersonalAccessTokenProvisioner(t *testing.T) { + plugintest.TestProvisioner(t, PersonalAccessToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{ + "default": { + ItemFields: map[sdk.FieldName]string{ + fieldname.Token: "kV9wTq3ZtN0aB4cD7eF1gH5iJ8kL2mN6oP0qR4sT8uV", + }, + ExpectedOutput: sdk.ProvisionOutput{ + Environment: map[string]string{ + "NETLIFY_AUTH_TOKEN": "kV9wTq3ZtN0aB4cD7eF1gH5iJ8kL2mN6oP0qR4sT8uV", + }, + }, + }, + }) +} + +func TestPersonalAccessTokenImporter(t *testing.T) { + plugintest.TestImporter(t, PersonalAccessToken().Importer, map[string]plugintest.ImportCase{ + "environment": { + Environment: map[string]string{ + "NETLIFY_AUTH_TOKEN": "kV9wTq3ZtN0aB4cD7eF1gH5iJ8kL2mN6oP0qR4sT8uV", + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.Token: "kV9wTq3ZtN0aB4cD7eF1gH5iJ8kL2mN6oP0qR4sT8uV", + }, + }, + }, + }, + }) +} diff --git a/plugins/netlify/plugin.go b/plugins/netlify/plugin.go new file mode 100644 index 000000000..a70fb068d --- /dev/null +++ b/plugins/netlify/plugin.go @@ -0,0 +1,22 @@ +package netlify + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/schema" +) + +func New() schema.Plugin { + return schema.Plugin{ + Name: "netlify", + Platform: schema.PlatformInfo{ + Name: "Netlify", + Homepage: sdk.URL("https://netlify.com"), + }, + Credentials: []schema.CredentialType{ + PersonalAccessToken(), + }, + Executables: []schema.Executable{ + NetlifyCLI(), + }, + } +}