From 80b9e8e55f5eb9d46ad2c52f3ee50b7c277387a4 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Mon, 23 Nov 2026 16:57:07 -0700 Subject: [PATCH 1/5] Initial import of `poetry` plugin Initial structure & code generated by Opencode. --- plugins/poetry/api_token.go | 42 +++++++++++++++++++++++++ plugins/poetry/api_token_test.go | 54 ++++++++++++++++++++++++++++++++ plugins/poetry/importer.go | 41 ++++++++++++++++++++++++ plugins/poetry/plugin.go | 22 +++++++++++++ plugins/poetry/poetry.go | 26 +++++++++++++++ plugins/poetry/poetry_test.go | 42 +++++++++++++++++++++++++ plugins/poetry/provisioner.go | 47 +++++++++++++++++++++++++++ 7 files changed, 274 insertions(+) create mode 100644 plugins/poetry/api_token.go create mode 100644 plugins/poetry/api_token_test.go create mode 100644 plugins/poetry/importer.go create mode 100644 plugins/poetry/plugin.go create mode 100644 plugins/poetry/poetry.go create mode 100644 plugins/poetry/poetry_test.go create mode 100644 plugins/poetry/provisioner.go diff --git a/plugins/poetry/api_token.go b/plugins/poetry/api_token.go new file mode 100644 index 00000000..394f2b15 --- /dev/null +++ b/plugins/poetry/api_token.go @@ -0,0 +1,42 @@ +package poetry + +import ( + "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 APIToken() schema.CredentialType { + return schema.CredentialType{ + Name: credname.APIToken, + DocsURL: sdk.URL("https://pypi.org/help/#apitoken"), + ManagementURL: sdk.URL("https://pypi.org/manage/account/#api-tokens"), + Fields: []schema.CredentialField{ + { + Name: fieldname.Token, + MarkdownDescription: "API token used to authenticate to PyPI.", + Secret: true, + Composition: &schema.ValueComposition{ + Prefix: "pypi-", + Charset: schema.Charset{ + Uppercase: true, + Lowercase: true, + Digits: true, + Specific: []rune{'-', '_'}, + }, + }, + }, + { + Name: fieldname.Website, + MarkdownDescription: "Website used to authenticate for Python packages.", + }, + }, + DefaultProvisioner: PoetryProvisioner(), + Importer: importer.TryAll( + importer.TryAllEnvVars(fieldname.Token, "POETRY_PYPI_TOKEN_PYPI", "POETRY_PYPI_TOKEN_TESTPYPI"), + TryPoetryConfigFile(), + ), + } +} diff --git a/plugins/poetry/api_token_test.go b/plugins/poetry/api_token_test.go new file mode 100644 index 00000000..f45bc752 --- /dev/null +++ b/plugins/poetry/api_token_test.go @@ -0,0 +1,54 @@ +package poetry + +import ( + "testing" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/plugintest" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +func TestAPITokenImporter(t *testing.T) { + plugintest.TestImporter(t, APIToken().Importer, map[string]plugintest.ImportCase{ + "POETRY_PYPI_TOKEN_PYPI environment variable": { + Environment: map[string]string{ + "POETRY_PYPI_TOKEN_PYPI": "pypi-AgEIcHlwaS5vcmc", + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.Token: "pypi-AgEIcHlwaS5vcmc", + }, + }, + }, + }, + "POETRY_PYPI_TOKEN_TESTPYPI environment variable": { + Environment: map[string]string{ + "POETRY_PYPI_TOKEN_TESTPYPI": "pypi-flit123abc", + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.Token: "pypi-flit123abc", + }, + }, + }, + }, + }) +} + +func TestAPITokenProvisioner(t *testing.T) { + plugintest.TestProvisioner(t, APIToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{ + "default provisioner sets Poetry env vars": { + ItemFields: map[sdk.FieldName]string{ + fieldname.Token: "pypi-AgEIcHlwaS5vcmc", + }, + ExpectedOutput: sdk.ProvisionOutput{ + Environment: map[string]string{ + "POETRY_PYPI_TOKEN_PYPI": "pypi-AgEIcHlwaS5vcmc", + "POETRY_PYPI_TOKEN_TESTPYPI": "pypi-AgEIcHlwaS5vcmc", + }, + }, + }, + }) +} diff --git a/plugins/poetry/importer.go b/plugins/poetry/importer.go new file mode 100644 index 00000000..23bba6d2 --- /dev/null +++ b/plugins/poetry/importer.go @@ -0,0 +1,41 @@ +package poetry + +import ( + "context" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/importer" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +// TryPoetryConfigFile returns an importer that scans the poetry CLI configuration file for API tokens. +func TryPoetryConfigFile() sdk.Importer { + return importer.TryFile("~/.config/pypoetry/auth.toml", func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) { + var config PoetryAuthConfig + if err := contents.ToTOML(&config); err != nil { + out.AddError(err) + return + } + + for repo, token := range config.PypiToken.TokenFor { + if token == "" { + continue + } + + out.AddCandidate(sdk.ImportCandidate{ + Fields: map[sdk.FieldName]string{ + fieldname.Token: token, + }, + NameHint: importer.SanitizeNameHint(repo), + }) + } + }) +} + +type PoetryPypiTokenConfig struct { + TokenFor map[string]string +} + +type PoetryAuthConfig struct { + PypiToken PoetryPypiTokenConfig `toml:"pypi-token"` +} diff --git a/plugins/poetry/plugin.go b/plugins/poetry/plugin.go new file mode 100644 index 00000000..e15b55f9 --- /dev/null +++ b/plugins/poetry/plugin.go @@ -0,0 +1,22 @@ +package poetry + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/schema" +) + +func New() schema.Plugin { + return schema.Plugin{ + Name: "poetry", + Platform: schema.PlatformInfo{ + Name: "Poetry", + Homepage: sdk.URL("https://python-poetry.org"), + }, + Credentials: []schema.CredentialType{ + APIToken(), + }, + Executables: []schema.Executable{ + PoetryCLI(), + }, + } +} diff --git a/plugins/poetry/poetry.go b/plugins/poetry/poetry.go new file mode 100644 index 00000000..63bfcc4e --- /dev/null +++ b/plugins/poetry/poetry.go @@ -0,0 +1,26 @@ +package poetry + +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 PoetryCLI() schema.Executable { + return schema.Executable{ + Name: "Poetry", + Runs: []string{"poetry"}, + DocsURL: sdk.URL("https://python-poetry.org/docs/"), + NeedsAuth: needsauth.IfAll( + needsauth.NotForHelpOrVersion(), + needsauth.ForCommand("publish"), + ), + Uses: []schema.CredentialUsage{ + { + Name: credname.APIToken, + Provisioner: PoetryProvisioner(), + }, + }, + } +} diff --git a/plugins/poetry/poetry_test.go b/plugins/poetry/poetry_test.go new file mode 100644 index 00000000..2ddf3dd3 --- /dev/null +++ b/plugins/poetry/poetry_test.go @@ -0,0 +1,42 @@ +package poetry + +import ( + "testing" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/plugintest" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +func TestPoetryCLIProvisioner(t *testing.T) { + plugintest.TestProvisioner(t, PoetryCLI().Uses[0].Provisioner, map[string]plugintest.ProvisionCase{ + "sets Poetry env vars": { + ItemFields: map[sdk.FieldName]string{ + fieldname.Token: "pypi-AgEIcHlwaS5vcmc", + }, + ExpectedOutput: sdk.ProvisionOutput{ + Environment: map[string]string{ + "POETRY_PYPI_TOKEN_PYPI": "pypi-AgEIcHlwaS5vcmc", + "POETRY_PYPI_TOKEN_TESTPYPI": "pypi-AgEIcHlwaS5vcmc", + }, + }, + }, + }) +} + +func TestPoetryCLINeedsAuth(t *testing.T) { + plugintest.TestNeedsAuth(t, PoetryCLI().NeedsAuth, map[string]plugintest.NeedsAuthCase{ + "requires auth for publish": { + Args: []string{"publish"}, + ExpectedNeedsAuth: true, + }, + "skips auth for help": { + Args: []string{"--help"}, + ExpectedNeedsAuth: false, + }, + "skips auth for version": { + Args: []string{"--version"}, + ExpectedNeedsAuth: false, + }, + }) +} diff --git a/plugins/poetry/provisioner.go b/plugins/poetry/provisioner.go new file mode 100644 index 00000000..f386986b --- /dev/null +++ b/plugins/poetry/provisioner.go @@ -0,0 +1,47 @@ +package poetry + +import ( + "context" + "fmt" + "strings" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +// poetryTokenEnvVarPrefix is the prefix of the environment variable that the poetry CLI uses to +// provision the API token for a package repository, e.g. "pypi" or "testpypi". +const poetryTokenEnvVarPrefix = "POETRY_PYPI_TOKEN_" + +// PoetryRepositoryNames contains the package repository names that the poetry CLI is provisioned +// for out of the box, e.g. the default PyPI instance and the PyPI test instance. +var PoetryRepositoryNames = []string{"pypi", "testpypi"} + +// poetryTokenEnvVar returns the name of the environment variable that the poetry CLI uses to +// provision the API token for the package repository with the given name, e.g. "pypi" or "testpypi". +func poetryTokenEnvVar(repositoryName string) string { + return fmt.Sprintf("%s%s", poetryTokenEnvVarPrefix, strings.ToUpper(repositoryName)) +} + +type poetryProvisioner struct{} + +// PoetryProvisioner provisions the API token for the supported package repositories via the +// environment variables that the poetry CLI understands. +func PoetryProvisioner() sdk.Provisioner { + return poetryProvisioner{} +} + +func (p poetryProvisioner) Description() string { + return "Provision Poetry API token via POETRY_PYPI_TOKEN_* environment variables" +} + +func (p poetryProvisioner) Provision(ctx context.Context, in sdk.ProvisionInput, out *sdk.ProvisionOutput) { + token := in.ItemFields[fieldname.Token] + for _, repositoryName := range PoetryRepositoryNames { + out.AddEnvVar(poetryTokenEnvVar(repositoryName), token) + } +} + +func (p poetryProvisioner) Deprovision(ctx context.Context, in sdk.DeprovisionInput, out *sdk.DeprovisionOutput) { + // Environment variables are automatically cleaned up when the process ends. +} From d0d1a8f1449252ccef43a2cf919ec1d36f389164 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 1 Dec 2026 11:34:48 -0700 Subject: [PATCH 2/5] Add `repository` field to import & provision This change also fixes the import from `auth.toml` as the initial `struct`s didn't properly unmarshall from the `.toml` file. --- plugins/poetry/api_token.go | 9 ++-- plugins/poetry/api_token_test.go | 58 +++++++++++++++++++++++--- plugins/poetry/importer.go | 54 +++++++++++++++++------- plugins/poetry/poetry_test.go | 6 +-- plugins/poetry/provisioner.go | 9 +--- plugins/poetry/test-fixtures/auth.toml | 7 ++++ sdk/schema/fieldname/names.go | 1 + 7 files changed, 111 insertions(+), 33 deletions(-) create mode 100644 plugins/poetry/test-fixtures/auth.toml diff --git a/plugins/poetry/api_token.go b/plugins/poetry/api_token.go index 394f2b15..e9e5477c 100644 --- a/plugins/poetry/api_token.go +++ b/plugins/poetry/api_token.go @@ -29,14 +29,15 @@ func APIToken() schema.CredentialType { }, }, { - Name: fieldname.Website, - MarkdownDescription: "Website used to authenticate for Python packages.", + Name: fieldname.Repository, + MarkdownDescription: "Poetry repository name", }, }, DefaultProvisioner: PoetryProvisioner(), Importer: importer.TryAll( - importer.TryAllEnvVars(fieldname.Token, "POETRY_PYPI_TOKEN_PYPI", "POETRY_PYPI_TOKEN_TESTPYPI"), - TryPoetryConfigFile(), + TryPoetryEnvVars(), + importer.LinuxOnly(TryPoetryConfigFile("~/.config/pypoetry/auth.toml")), + importer.MacOnly(TryPoetryConfigFile("~/Library/Application Support/pypoetry/auth.toml")), ), } } diff --git a/plugins/poetry/api_token_test.go b/plugins/poetry/api_token_test.go index f45bc752..7faf89f8 100644 --- a/plugins/poetry/api_token_test.go +++ b/plugins/poetry/api_token_test.go @@ -17,8 +17,10 @@ func TestAPITokenImporter(t *testing.T) { ExpectedCandidates: []sdk.ImportCandidate{ { Fields: map[sdk.FieldName]string{ - fieldname.Token: "pypi-AgEIcHlwaS5vcmc", + fieldname.Token: "pypi-AgEIcHlwaS5vcmc", + fieldname.Repository: "pypi", }, + NameHint: "pypi", }, }, }, @@ -29,8 +31,54 @@ func TestAPITokenImporter(t *testing.T) { ExpectedCandidates: []sdk.ImportCandidate{ { Fields: map[sdk.FieldName]string{ - fieldname.Token: "pypi-flit123abc", + fieldname.Token: "pypi-flit123abc", + fieldname.Repository: "testpypi", }, + NameHint: "testpypi", + }, + }, + }, + "config file macos": { + OS: "darwin", + Files: map[string]string{ + "~/Library/Application Support/pypoetry/auth.toml": plugintest.LoadFixture(t, "auth.toml"), + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.Token: "pypi-fake_token_value", + fieldname.Repository: "pypi", + }, + NameHint: "pypi", + }, + { + Fields: map[sdk.FieldName]string{ + fieldname.Token: "pypi-another_fake_token_value", + fieldname.Repository: "testpypi", + }, + NameHint: "testpypi", + }, + }, + }, + "config file linux": { + OS: "linux", + Files: map[string]string{ + "~/.config/pypoetry/auth.toml": plugintest.LoadFixture(t, "auth.toml"), + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.Token: "pypi-fake_token_value", + fieldname.Repository: "pypi", + }, + NameHint: "pypi", + }, + { + Fields: map[sdk.FieldName]string{ + fieldname.Token: "pypi-another_fake_token_value", + fieldname.Repository: "testpypi", + }, + NameHint: "testpypi", }, }, }, @@ -41,12 +89,12 @@ func TestAPITokenProvisioner(t *testing.T) { plugintest.TestProvisioner(t, APIToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{ "default provisioner sets Poetry env vars": { ItemFields: map[sdk.FieldName]string{ - fieldname.Token: "pypi-AgEIcHlwaS5vcmc", + fieldname.Token: "pypi-AgEIcHlwaS5vcmc", + fieldname.Repository: "mysecretpypi", }, ExpectedOutput: sdk.ProvisionOutput{ Environment: map[string]string{ - "POETRY_PYPI_TOKEN_PYPI": "pypi-AgEIcHlwaS5vcmc", - "POETRY_PYPI_TOKEN_TESTPYPI": "pypi-AgEIcHlwaS5vcmc", + "POETRY_PYPI_TOKEN_MYSECRETPYPI": "pypi-AgEIcHlwaS5vcmc", }, }, }, diff --git a/plugins/poetry/importer.go b/plugins/poetry/importer.go index 23bba6d2..c6a40104 100644 --- a/plugins/poetry/importer.go +++ b/plugins/poetry/importer.go @@ -2,40 +2,66 @@ package poetry import ( "context" + "os" + "strings" "github.com/1Password/shell-plugins/sdk" "github.com/1Password/shell-plugins/sdk/importer" "github.com/1Password/shell-plugins/sdk/schema/fieldname" ) +func TryPoetryEnvVars() sdk.Importer { + return func(ctx context.Context, in sdk.ImportInput, out *sdk.ImportOutput) { + prefix := "POETRY_PYPI_TOKEN_" + + for _, envVar := range os.Environ() { + // Split into key and value + key := envVar + value := "" + if before, after, ok := strings.Cut(envVar, "="); ok { + key = before + value = after + } + + if after, ok := strings.CutPrefix(key, prefix); ok { + repo := strings.ToLower(after) + attempt := out.NewAttempt(importer.SourceEnvVars(key)) + attempt.AddCandidate(sdk.ImportCandidate{ + Fields: map[sdk.FieldName]string{ + fieldname.Token: value, + fieldname.Repository: repo, + }, + NameHint: importer.SanitizeNameHint(repo), + }) + } + } + } +} + // TryPoetryConfigFile returns an importer that scans the poetry CLI configuration file for API tokens. -func TryPoetryConfigFile() sdk.Importer { - return importer.TryFile("~/.config/pypoetry/auth.toml", func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) { - var config PoetryAuthConfig +func TryPoetryConfigFile(path string) sdk.Importer { + return importer.TryFile(path, func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) { + var config map[string]interface{} if err := contents.ToTOML(&config); err != nil { out.AddError(err) return } - for repo, token := range config.PypiToken.TokenFor { - if token == "" { + pypiToken := config["pypi-token"].(map[string]interface{}) + + for repo, token := range pypiToken { + tokenStr := token.(string) + if tokenStr == "" { continue } out.AddCandidate(sdk.ImportCandidate{ Fields: map[sdk.FieldName]string{ - fieldname.Token: token, + fieldname.Token: tokenStr, + fieldname.Repository: repo, }, NameHint: importer.SanitizeNameHint(repo), }) } }) } - -type PoetryPypiTokenConfig struct { - TokenFor map[string]string -} - -type PoetryAuthConfig struct { - PypiToken PoetryPypiTokenConfig `toml:"pypi-token"` -} diff --git a/plugins/poetry/poetry_test.go b/plugins/poetry/poetry_test.go index 2ddf3dd3..9319eb02 100644 --- a/plugins/poetry/poetry_test.go +++ b/plugins/poetry/poetry_test.go @@ -12,12 +12,12 @@ func TestPoetryCLIProvisioner(t *testing.T) { plugintest.TestProvisioner(t, PoetryCLI().Uses[0].Provisioner, map[string]plugintest.ProvisionCase{ "sets Poetry env vars": { ItemFields: map[sdk.FieldName]string{ - fieldname.Token: "pypi-AgEIcHlwaS5vcmc", + fieldname.Token: "pypi-AgEIcHlwaS5vcmc", + fieldname.Repository: "pypi", }, ExpectedOutput: sdk.ProvisionOutput{ Environment: map[string]string{ - "POETRY_PYPI_TOKEN_PYPI": "pypi-AgEIcHlwaS5vcmc", - "POETRY_PYPI_TOKEN_TESTPYPI": "pypi-AgEIcHlwaS5vcmc", + "POETRY_PYPI_TOKEN_PYPI": "pypi-AgEIcHlwaS5vcmc", }, }, }, diff --git a/plugins/poetry/provisioner.go b/plugins/poetry/provisioner.go index f386986b..efa02378 100644 --- a/plugins/poetry/provisioner.go +++ b/plugins/poetry/provisioner.go @@ -13,10 +13,6 @@ import ( // provision the API token for a package repository, e.g. "pypi" or "testpypi". const poetryTokenEnvVarPrefix = "POETRY_PYPI_TOKEN_" -// PoetryRepositoryNames contains the package repository names that the poetry CLI is provisioned -// for out of the box, e.g. the default PyPI instance and the PyPI test instance. -var PoetryRepositoryNames = []string{"pypi", "testpypi"} - // poetryTokenEnvVar returns the name of the environment variable that the poetry CLI uses to // provision the API token for the package repository with the given name, e.g. "pypi" or "testpypi". func poetryTokenEnvVar(repositoryName string) string { @@ -37,9 +33,8 @@ func (p poetryProvisioner) Description() string { func (p poetryProvisioner) Provision(ctx context.Context, in sdk.ProvisionInput, out *sdk.ProvisionOutput) { token := in.ItemFields[fieldname.Token] - for _, repositoryName := range PoetryRepositoryNames { - out.AddEnvVar(poetryTokenEnvVar(repositoryName), token) - } + repo := in.ItemFields[fieldname.Repository] + out.AddEnvVar(poetryTokenEnvVar(repo), token) } func (p poetryProvisioner) Deprovision(ctx context.Context, in sdk.DeprovisionInput, out *sdk.DeprovisionOutput) { diff --git a/plugins/poetry/test-fixtures/auth.toml b/plugins/poetry/test-fixtures/auth.toml new file mode 100644 index 00000000..7db60c33 --- /dev/null +++ b/plugins/poetry/test-fixtures/auth.toml @@ -0,0 +1,7 @@ +[pypi-token] +pypi = "pypi-fake_token_value" +testpypi = "pypi-another_fake_token_value" + +[http-basic.mypypi] +username = "fake_user" +password = "fake_password" diff --git a/sdk/schema/fieldname/names.go b/sdk/schema/fieldname/names.go index f2256903..81faa10a 100644 --- a/sdk/schema/fieldname/names.go +++ b/sdk/schema/fieldname/names.go @@ -51,6 +51,7 @@ const ( ProjectID = sdk.FieldName("Project ID") Project = sdk.FieldName("Project") Region = sdk.FieldName("Region") + Repository = sdk.FieldName("Repository") SSOAccountID = sdk.FieldName("SSO Account ID") SSORegion = sdk.FieldName("SSO Region") SSORoleName = sdk.FieldName("SSO Role Name") From 585441d1df1f95ee7eb3478a2be147ffe562ecdf Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 4 Dec 2026 10:15:08 -0700 Subject: [PATCH 3/5] Replace `-` with `_` in token env var. Co-authored-by: rr3khan <65298773+rr3khan@users.noreply.github.com> --- plugins/poetry/provisioner.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/poetry/provisioner.go b/plugins/poetry/provisioner.go index efa02378..be2d43ba 100644 --- a/plugins/poetry/provisioner.go +++ b/plugins/poetry/provisioner.go @@ -16,7 +16,7 @@ const poetryTokenEnvVarPrefix = "POETRY_PYPI_TOKEN_" // poetryTokenEnvVar returns the name of the environment variable that the poetry CLI uses to // provision the API token for the package repository with the given name, e.g. "pypi" or "testpypi". func poetryTokenEnvVar(repositoryName string) string { - return fmt.Sprintf("%s%s", poetryTokenEnvVarPrefix, strings.ToUpper(repositoryName)) + return fmt.Sprintf("%s%s", poetryTokenEnvVarPrefix, strings.ToUpper(strings.ReplaceAll(repositoryName, "-", "_"))) } type poetryProvisioner struct{} From 58ba9d6c398b83834066e8d7b759a8e48360140c Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 4 Dec 2026 10:29:48 -0700 Subject: [PATCH 4/5] Add test recommended in PR review From https://github.com/1Password/shell-plugins/pull/725#discussion_r4795822247 comment --- plugins/poetry/poetry_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/poetry/poetry_test.go b/plugins/poetry/poetry_test.go index 9319eb02..efa520a1 100644 --- a/plugins/poetry/poetry_test.go +++ b/plugins/poetry/poetry_test.go @@ -21,6 +21,17 @@ func TestPoetryCLIProvisioner(t *testing.T) { }, }, }, + "repository name with a dash": { + ItemFields: map[sdk.FieldName]string{ + fieldname.Token: "pypi-AgEIcHlwaS5vcmc", + fieldname.Repository: "my-repo", + }, + ExpectedOutput: sdk.ProvisionOutput{ + Environment: map[string]string{ + "POETRY_PYPI_TOKEN_MY_REPO": "pypi-AgEIcHlwaS5vcmc", + }, + }, + }, }) } From 81f2553d5a60bf12b239b6d1928280773394e48e Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 4 Dec 2026 10:30:20 -0700 Subject: [PATCH 5/5] Add handling of env var import containing underscore It now generates two possible import candidates, one with the underscores and another with the underscores replaced by dashes. --- plugins/poetry/api_token_test.go | 21 +++++++++++++++++++++ plugins/poetry/importer.go | 10 ++++++++++ 2 files changed, 31 insertions(+) diff --git a/plugins/poetry/api_token_test.go b/plugins/poetry/api_token_test.go index 7faf89f8..8061605a 100644 --- a/plugins/poetry/api_token_test.go +++ b/plugins/poetry/api_token_test.go @@ -38,6 +38,27 @@ func TestAPITokenImporter(t *testing.T) { }, }, }, + "environment variable with dash": { + Environment: map[string]string{ + "POETRY_PYPI_TOKEN_MY_REPO": "pypi-flit123abc", + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.Token: "pypi-flit123abc", + fieldname.Repository: "my_repo", + }, + NameHint: "my_repo", + }, + { + Fields: map[sdk.FieldName]string{ + fieldname.Token: "pypi-flit123abc", + fieldname.Repository: "my-repo", + }, + NameHint: "my-repo", + }, + }, + }, "config file macos": { OS: "darwin", Files: map[string]string{ diff --git a/plugins/poetry/importer.go b/plugins/poetry/importer.go index c6a40104..7658cc2e 100644 --- a/plugins/poetry/importer.go +++ b/plugins/poetry/importer.go @@ -33,6 +33,16 @@ func TryPoetryEnvVars() sdk.Importer { }, NameHint: importer.SanitizeNameHint(repo), }) + repoWithDashes := strings.ReplaceAll(repo, "_", "-") + if repoWithDashes != repo { + attempt.AddCandidate(sdk.ImportCandidate{ + Fields: map[sdk.FieldName]string{ + fieldname.Token: value, + fieldname.Repository: repoWithDashes, + }, + NameHint: importer.SanitizeNameHint(repoWithDashes), + }) + } } } }