From 4954b5650d08bc3bfb139e47856d4525e0b4511d Mon Sep 17 00:00:00 2001 From: Tom Proctor Date: Fri, 1 Mar 2024 14:21:54 +0000 Subject: [PATCH 01/13] Move command/config + command/token to api/cliconfig + api/tokenhelper --- {command/config => api/cliconfig}/config.go | 0 {command/config => api/cliconfig}/config_test.go | 0 {command/config => api/cliconfig}/hcp_token.go | 0 {command/config => api/cliconfig}/util.go | 0 {command/config => api/cliconfig}/validate_listener.go | 0 {command/token => api/tokenhelper}/helper.go | 0 {command/token => api/tokenhelper}/helper_external.go | 0 {command/token => api/tokenhelper}/helper_external_test.go | 0 {command/token => api/tokenhelper}/helper_internal.go | 0 {command/token => api/tokenhelper}/helper_internal_test.go | 0 {command/token => api/tokenhelper}/helper_testing.go | 0 {command/token => api/tokenhelper}/testing.go | 0 12 files changed, 0 insertions(+), 0 deletions(-) rename {command/config => api/cliconfig}/config.go (100%) rename {command/config => api/cliconfig}/config_test.go (100%) rename {command/config => api/cliconfig}/hcp_token.go (100%) rename {command/config => api/cliconfig}/util.go (100%) rename {command/config => api/cliconfig}/validate_listener.go (100%) rename {command/token => api/tokenhelper}/helper.go (100%) rename {command/token => api/tokenhelper}/helper_external.go (100%) rename {command/token => api/tokenhelper}/helper_external_test.go (100%) rename {command/token => api/tokenhelper}/helper_internal.go (100%) rename {command/token => api/tokenhelper}/helper_internal_test.go (100%) rename {command/token => api/tokenhelper}/helper_testing.go (100%) rename {command/token => api/tokenhelper}/testing.go (100%) diff --git a/command/config/config.go b/api/cliconfig/config.go similarity index 100% rename from command/config/config.go rename to api/cliconfig/config.go diff --git a/command/config/config_test.go b/api/cliconfig/config_test.go similarity index 100% rename from command/config/config_test.go rename to api/cliconfig/config_test.go diff --git a/command/config/hcp_token.go b/api/cliconfig/hcp_token.go similarity index 100% rename from command/config/hcp_token.go rename to api/cliconfig/hcp_token.go diff --git a/command/config/util.go b/api/cliconfig/util.go similarity index 100% rename from command/config/util.go rename to api/cliconfig/util.go diff --git a/command/config/validate_listener.go b/api/cliconfig/validate_listener.go similarity index 100% rename from command/config/validate_listener.go rename to api/cliconfig/validate_listener.go diff --git a/command/token/helper.go b/api/tokenhelper/helper.go similarity index 100% rename from command/token/helper.go rename to api/tokenhelper/helper.go diff --git a/command/token/helper_external.go b/api/tokenhelper/helper_external.go similarity index 100% rename from command/token/helper_external.go rename to api/tokenhelper/helper_external.go diff --git a/command/token/helper_external_test.go b/api/tokenhelper/helper_external_test.go similarity index 100% rename from command/token/helper_external_test.go rename to api/tokenhelper/helper_external_test.go diff --git a/command/token/helper_internal.go b/api/tokenhelper/helper_internal.go similarity index 100% rename from command/token/helper_internal.go rename to api/tokenhelper/helper_internal.go diff --git a/command/token/helper_internal_test.go b/api/tokenhelper/helper_internal_test.go similarity index 100% rename from command/token/helper_internal_test.go rename to api/tokenhelper/helper_internal_test.go diff --git a/command/token/helper_testing.go b/api/tokenhelper/helper_testing.go similarity index 100% rename from command/token/helper_testing.go rename to api/tokenhelper/helper_testing.go diff --git a/command/token/testing.go b/api/tokenhelper/testing.go similarity index 100% rename from command/token/testing.go rename to api/tokenhelper/testing.go From 8d67cc7bf12a023c4aaa2ce8f163e01104a28513 Mon Sep 17 00:00:00 2001 From: Tom Proctor Date: Fri, 1 Mar 2024 14:29:33 +0000 Subject: [PATCH 02/13] Fix up api package names, go.mod and imports --- api/cliconfig/config.go | 38 +++++++++-- api/cliconfig/config_test.go | 2 +- api/cliconfig/util.go | 12 ++-- api/cliconfig/validate_listener.go | 6 +- api/go.mod | 21 +++++- api/go.sum | 68 +++++++++++++++++++ api/tokenhelper/helper.go | 2 +- api/tokenhelper/helper_external.go | 2 +- api/tokenhelper/helper_external_test.go | 5 +- api/tokenhelper/helper_internal.go | 2 +- api/tokenhelper/helper_internal_test.go | 5 +- api/tokenhelper/helper_testing.go | 2 +- api/tokenhelper/testing.go | 2 +- .../cliconfig => command/config}/hcp_token.go | 0 14 files changed, 136 insertions(+), 31 deletions(-) rename {api/cliconfig => command/config}/hcp_token.go (100%) diff --git a/api/cliconfig/config.go b/api/cliconfig/config.go index 4421226f24ce..0616054f1e0f 100644 --- a/api/cliconfig/config.go +++ b/api/cliconfig/config.go @@ -1,17 +1,16 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: BUSL-1.1 -package config +package cliconfig import ( "fmt" - "io/ioutil" "os" + "github.com/hashicorp/go-multierror" "github.com/hashicorp/hcl" "github.com/hashicorp/hcl/hcl/ast" - "github.com/hashicorp/vault/sdk/helper/hclutil" - homedir "github.com/mitchellh/go-homedir" + "github.com/mitchellh/go-homedir" ) const ( @@ -62,7 +61,7 @@ func LoadConfig(path string) (*DefaultConfig, error) { return nil, fmt.Errorf("error expanding config path %q: %w", path, err) } - contents, err := ioutil.ReadFile(path) + contents, err := os.ReadFile(path) if err != nil && !os.IsNotExist(err) { return nil, err } @@ -91,7 +90,7 @@ func ParseConfig(contents string) (*DefaultConfig, error) { valid := []string{ "token_helper", } - if err := hclutil.CheckHCLKeys(list, valid); err != nil { + if err := checkHCLKeys(list, valid); err != nil { return nil, err } @@ -101,3 +100,30 @@ func ParseConfig(contents string) (*DefaultConfig, error) { } return &c, nil } + +func checkHCLKeys(node ast.Node, valid []string) error { + var list *ast.ObjectList + switch n := node.(type) { + case *ast.ObjectList: + list = n + case *ast.ObjectType: + list = n.List + default: + return fmt.Errorf("cannot check HCL keys of type %T", n) + } + + validMap := make(map[string]struct{}, len(valid)) + for _, v := range valid { + validMap[v] = struct{}{} + } + + var result error + for _, item := range list.Items { + key := item.Keys[0].Token.Value().(string) + if _, ok := validMap[key]; !ok { + result = multierror.Append(result, fmt.Errorf("invalid key %q on line %d", key, item.Assign.Line)) + } + } + + return result +} diff --git a/api/cliconfig/config_test.go b/api/cliconfig/config_test.go index 04cb1be9863f..f9d6a6580e3b 100644 --- a/api/cliconfig/config_test.go +++ b/api/cliconfig/config_test.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: BUSL-1.1 -package config +package cliconfig import ( "path/filepath" diff --git a/api/cliconfig/util.go b/api/cliconfig/util.go index 3c6f7ca6239d..8cf0b97622ca 100644 --- a/api/cliconfig/util.go +++ b/api/cliconfig/util.go @@ -1,15 +1,15 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: BUSL-1.1 -package config +package cliconfig import ( - "github.com/hashicorp/vault/command/token" + "github.com/hashicorp/vault/api/tokenhelper" ) // DefaultTokenHelper returns the token helper that is configured for Vault. // This helper should only be used for non-server CLI commands. -func DefaultTokenHelper() (token.TokenHelper, error) { +func DefaultTokenHelper() (tokenhelper.TokenHelper, error) { config, err := LoadConfig("") if err != nil { return nil, err @@ -17,12 +17,12 @@ func DefaultTokenHelper() (token.TokenHelper, error) { path := config.TokenHelper if path == "" { - return token.NewInternalTokenHelper() + return tokenhelper.NewInternalTokenHelper() } - path, err = token.ExternalTokenHelperPath(path) + path, err = tokenhelper.ExternalTokenHelperPath(path) if err != nil { return nil, err } - return &token.ExternalTokenHelper{BinaryPath: path}, nil + return &tokenhelper.ExternalTokenHelper{BinaryPath: path}, nil } diff --git a/api/cliconfig/validate_listener.go b/api/cliconfig/validate_listener.go index 09123bdc75b3..e77bbf5dede9 100644 --- a/api/cliconfig/validate_listener.go +++ b/api/cliconfig/validate_listener.go @@ -3,10 +3,8 @@ //go:build !fips_140_3 -package config +package cliconfig -import "github.com/hashicorp/vault/internalshared/configutil" - -func IsValidListener(listener *configutil.Listener) error { +func IsValidListener(tlsDisable bool) error { return nil } diff --git a/api/go.mod b/api/go.mod index 74b526cacae5..2c507789b863 100644 --- a/api/go.mod +++ b/api/go.mod @@ -27,15 +27,30 @@ require ( ) require ( + github.com/Masterminds/goutils v1.1.1 // indirect + github.com/Masterminds/semver/v3 v3.2.0 // indirect + github.com/Masterminds/sprig/v3 v3.2.3 // indirect + github.com/armon/go-radix v1.0.0 // indirect + github.com/bgentry/speakeasy v0.1.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/fatih/color v1.7.0 // indirect + github.com/fatih/color v1.16.0 // indirect github.com/google/go-cmp v0.5.7 // indirect + github.com/google/uuid v1.1.2 // indirect + github.com/hashicorp/cli v1.1.6 // indirect github.com/hashicorp/go-sockaddr v1.0.2 // indirect - github.com/mattn/go-colorable v0.1.6 // indirect - github.com/mattn/go-isatty v0.0.12 // indirect + github.com/huandu/xstrings v1.3.3 // indirect + github.com/imdario/mergo v0.3.11 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mitchellh/copystructure v1.0.0 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect + github.com/mitchellh/reflectwalk v1.0.0 // indirect + github.com/natefinch/atomic v1.0.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/posener/complete v1.2.3 // indirect github.com/ryanuber/go-glob v1.0.0 // indirect + github.com/shopspring/decimal v1.2.0 // indirect + github.com/spf13/cast v1.3.1 // indirect golang.org/x/crypto v0.17.0 // indirect golang.org/x/sys v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/api/go.sum b/api/go.sum index 13cac579c031..95eae342f156 100644 --- a/api/go.sum +++ b/api/go.sum @@ -1,4 +1,13 @@ +github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= +github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= +github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g= +github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= +github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA= +github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= +github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c= github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs= @@ -7,6 +16,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= +github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= github.com/go-jose/go-jose/v3 v3.0.1 h1:pWmKFVtt+Jl0vBZTIpz/eAKwsm6LkIxDVVbFHKkchhA= github.com/go-jose/go-jose/v3 v3.0.1/go.mod h1:RNkWWRld676jZEYoV3+XK8L2ZnNSvIsxFMht0mSX+u8= github.com/go-test/deep v1.0.2 h1:onZX1rnHT3Wv6cqNgYyFOOlgVKJrksuCMCRvJStbMYw= @@ -14,6 +25,11 @@ github.com/go-test/deep v1.0.2/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3a github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/hashicorp/cli v1.1.6 h1:CMOV+/LJfL1tXCOKrgAX0uRKnzjj/mpmqNXloRSy2K8= +github.com/hashicorp/cli v1.1.6/go.mod h1:MPon5QYlgjjo0BSoAiN0ESeT5fRzDjVRp+uioJ0piz4= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -39,41 +55,74 @@ github.com/hashicorp/go-sockaddr v1.0.2 h1:ztczhD1jLxIRjVejw8gFomI1BQZOe2WoVOu0S github.com/hashicorp/go-sockaddr v1.0.2/go.mod h1:rB4wwRAUzs07qva3c5SdrY/NEtAUjGlgmH/UkBUC97A= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4= +github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= +github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA= +github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE= github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= +github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= +github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY= +github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/natefinch/atomic v1.0.1 h1:ZPYKxkqQOx3KZ+RsbnP/YsgvxWQPGxjC0oBt2AhwV0A= +github.com/natefinch/atomic v1.0.1/go.mod h1:N/D/ELrljoqDyT3rZrsUmtsuzvHkeB/wWjHV22AZRbM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= +github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= +github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk= github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= +github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= +github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= +github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= +github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -81,16 +130,35 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI= golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/api/tokenhelper/helper.go b/api/tokenhelper/helper.go index a4bf1fa0f866..c6ff7dd7ebb8 100644 --- a/api/tokenhelper/helper.go +++ b/api/tokenhelper/helper.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: BUSL-1.1 -package token +package tokenhelper // TokenHelper is an interface that contains basic operations that must be // implemented by a token helper diff --git a/api/tokenhelper/helper_external.go b/api/tokenhelper/helper_external.go index 26e7f44ee8e9..b1e562e0d8a1 100644 --- a/api/tokenhelper/helper_external.go +++ b/api/tokenhelper/helper_external.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: BUSL-1.1 -package token +package tokenhelper import ( "bytes" diff --git a/api/tokenhelper/helper_external_test.go b/api/tokenhelper/helper_external_test.go index d7b03236022d..e965e965af00 100644 --- a/api/tokenhelper/helper_external_test.go +++ b/api/tokenhelper/helper_external_test.go @@ -1,12 +1,11 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: BUSL-1.1 -package token +package tokenhelper import ( "fmt" "io" - "io/ioutil" "os" "runtime" "strings" @@ -73,7 +72,7 @@ func helperPath(s ...string) string { func helperEnv() []string { var env []string - tf, err := ioutil.TempFile("", "vault") + tf, err := os.CreateTemp("", "vault") if err != nil { panic(err) } diff --git a/api/tokenhelper/helper_internal.go b/api/tokenhelper/helper_internal.go index 866ff1880e10..8b4605ea8ac2 100644 --- a/api/tokenhelper/helper_internal.go +++ b/api/tokenhelper/helper_internal.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: BUSL-1.1 -package token +package tokenhelper import ( "bytes" diff --git a/api/tokenhelper/helper_internal_test.go b/api/tokenhelper/helper_internal_test.go index 10a7a0cc974f..282b0b7443ee 100644 --- a/api/tokenhelper/helper_internal_test.go +++ b/api/tokenhelper/helper_internal_test.go @@ -1,10 +1,9 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: BUSL-1.1 -package token +package tokenhelper import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -21,7 +20,7 @@ func TestCommand(t *testing.T) { } func TestInternalHelperFilePerms(t *testing.T) { - tmpDir, err := ioutil.TempDir("", t.Name()) + tmpDir, err := os.MkdirTemp("", t.Name()) if err != nil { t.Fatal(err) } diff --git a/api/tokenhelper/helper_testing.go b/api/tokenhelper/helper_testing.go index e948092f4506..d1e2d17c77bf 100644 --- a/api/tokenhelper/helper_testing.go +++ b/api/tokenhelper/helper_testing.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: BUSL-1.1 -package token +package tokenhelper import ( "sync" diff --git a/api/tokenhelper/testing.go b/api/tokenhelper/testing.go index 24dc3258e511..a740dd14f440 100644 --- a/api/tokenhelper/testing.go +++ b/api/tokenhelper/testing.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: BUSL-1.1 -package token +package tokenhelper import ( "fmt" diff --git a/api/cliconfig/hcp_token.go b/command/config/hcp_token.go similarity index 100% rename from api/cliconfig/hcp_token.go rename to command/config/hcp_token.go From 9d289fd2a4fb513fb8c40bd2ab5025f93fd2b493 Mon Sep 17 00:00:00 2001 From: Tom Proctor Date: Fri, 1 Mar 2024 14:32:53 +0000 Subject: [PATCH 03/13] Remove unused functions and unused import --- api/go.mod | 18 +------ api/go.sum | 64 ------------------------- api/tokenhelper/helper_external_test.go | 2 +- api/tokenhelper/helper_internal_test.go | 2 +- api/tokenhelper/testing.go | 47 +----------------- 5 files changed, 6 insertions(+), 127 deletions(-) diff --git a/api/go.mod b/api/go.mod index 2c507789b863..2338fe9cf65c 100644 --- a/api/go.mod +++ b/api/go.mod @@ -20,37 +20,23 @@ require ( github.com/hashicorp/go-secure-stdlib/parseutil v0.1.6 github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 github.com/hashicorp/hcl v1.0.0 + github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/mapstructure v1.5.0 + github.com/natefinch/atomic v1.0.1 github.com/stretchr/testify v1.8.4 golang.org/x/net v0.17.0 golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 ) require ( - github.com/Masterminds/goutils v1.1.1 // indirect - github.com/Masterminds/semver/v3 v3.2.0 // indirect - github.com/Masterminds/sprig/v3 v3.2.3 // indirect - github.com/armon/go-radix v1.0.0 // indirect - github.com/bgentry/speakeasy v0.1.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.16.0 // indirect github.com/google/go-cmp v0.5.7 // indirect - github.com/google/uuid v1.1.2 // indirect - github.com/hashicorp/cli v1.1.6 // indirect github.com/hashicorp/go-sockaddr v1.0.2 // indirect - github.com/huandu/xstrings v1.3.3 // indirect - github.com/imdario/mergo v0.3.11 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mitchellh/copystructure v1.0.0 // indirect - github.com/mitchellh/go-homedir v1.1.0 // indirect - github.com/mitchellh/reflectwalk v1.0.0 // indirect - github.com/natefinch/atomic v1.0.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/posener/complete v1.2.3 // indirect github.com/ryanuber/go-glob v1.0.0 // indirect - github.com/shopspring/decimal v1.2.0 // indirect - github.com/spf13/cast v1.3.1 // indirect golang.org/x/crypto v0.17.0 // indirect golang.org/x/sys v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/api/go.sum b/api/go.sum index 95eae342f156..d231b4b37912 100644 --- a/api/go.sum +++ b/api/go.sum @@ -1,20 +1,10 @@ -github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= -github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= -github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g= -github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= -github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA= -github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= -github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c= github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= @@ -25,11 +15,6 @@ github.com/go-test/deep v1.0.2/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3a github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= -github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/hashicorp/cli v1.1.6 h1:CMOV+/LJfL1tXCOKrgAX0uRKnzjj/mpmqNXloRSy2K8= -github.com/hashicorp/cli v1.1.6/go.mod h1:MPon5QYlgjjo0BSoAiN0ESeT5fRzDjVRp+uioJ0piz4= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -55,110 +40,61 @@ github.com/hashicorp/go-sockaddr v1.0.2 h1:ztczhD1jLxIRjVejw8gFomI1BQZOe2WoVOu0S github.com/hashicorp/go-sockaddr v1.0.2/go.mod h1:rB4wwRAUzs07qva3c5SdrY/NEtAUjGlgmH/UkBUC97A= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4= -github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= -github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA= -github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE= -github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= -github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= -github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY= -github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/natefinch/atomic v1.0.1 h1:ZPYKxkqQOx3KZ+RsbnP/YsgvxWQPGxjC0oBt2AhwV0A= github.com/natefinch/atomic v1.0.1/go.mod h1:N/D/ELrljoqDyT3rZrsUmtsuzvHkeB/wWjHV22AZRbM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= -github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= -github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk= github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= -github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= -github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= -github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI= golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/api/tokenhelper/helper_external_test.go b/api/tokenhelper/helper_external_test.go index e965e965af00..8508a1630e12 100644 --- a/api/tokenhelper/helper_external_test.go +++ b/api/tokenhelper/helper_external_test.go @@ -53,7 +53,7 @@ func TestExternalTokenHelperPath(t *testing.T) { } func TestExternalTokenHelper(t *testing.T) { - Test(t, testExternalTokenHelper(t)) + test(t, testExternalTokenHelper(t)) } func testExternalTokenHelper(t *testing.T) *ExternalTokenHelper { diff --git a/api/tokenhelper/helper_internal_test.go b/api/tokenhelper/helper_internal_test.go index 282b0b7443ee..47bf73803323 100644 --- a/api/tokenhelper/helper_internal_test.go +++ b/api/tokenhelper/helper_internal_test.go @@ -16,7 +16,7 @@ func TestCommand(t *testing.T) { if err != nil { t.Fatal(err) } - Test(t, helper) + test(t, helper) } func TestInternalHelperFilePerms(t *testing.T) { diff --git a/api/tokenhelper/testing.go b/api/tokenhelper/testing.go index a740dd14f440..dd5040f51592 100644 --- a/api/tokenhelper/testing.go +++ b/api/tokenhelper/testing.go @@ -4,17 +4,12 @@ package tokenhelper import ( - "fmt" - "os" - "strings" "testing" - - "github.com/hashicorp/cli" ) -// Test is a public function that can be used in other tests to +// test is a public function that can be used in other tests to // test that a helper is functioning properly. -func Test(t *testing.T, h TokenHelper) { +func test(t *testing.T, h TokenHelper) { if err := h.Store("foo"); err != nil { t.Fatalf("err: %s", err) } @@ -41,41 +36,3 @@ func Test(t *testing.T, h TokenHelper) { t.Fatalf("bad: %#v", v) } } - -// TestProcess is used to re-execute this test in order to use it as the -// helper process. For this to work, the TestExternalTokenHelperProcess function must -// exist. -func TestProcess(t *testing.T, s ...string) { - h := &ExternalTokenHelper{BinaryPath: TestProcessPath(t, s...)} - Test(t, h) -} - -// TestProcessPath returns the path to the test process. -func TestProcessPath(t *testing.T, s ...string) string { - cs := []string{"-test.run=TestExternalTokenHelperProcess", "--", "GO_WANT_HELPER_PROCESS"} - cs = append(cs, s...) - return fmt.Sprintf( - "%s %s", - os.Args[0], - strings.Join(cs, " ")) -} - -// TestExternalTokenHelperProcessCLI can be called to implement TestExternalTokenHelperProcess -// for TestProcess that just executes a CLI command. -func TestExternalTokenHelperProcessCLI(t *testing.T, cmd cli.Command) { - args := os.Args - for len(args) > 0 { - if args[0] == "--" { - args = args[1:] - break - } - - args = args[1:] - } - if len(args) == 0 || args[0] != "GO_WANT_HELPER_PROCESS" { - return - } - args = args[1:] - - os.Exit(cmd.Run(args)) -} From 5c767744961273e7eb641009b2374146c1aff006 Mon Sep 17 00:00:00 2001 From: Tom Proctor Date: Fri, 1 Mar 2024 14:44:01 +0000 Subject: [PATCH 04/13] Fix Vault imports + package names --- command/auth_test.go | 4 ++-- command/base.go | 11 ++++++----- command/base_predict.go | 3 ++- command/config.go | 20 ++++++++++---------- command/login_test.go | 4 ++-- command/main.go | 4 ++-- command/server.go | 4 ++-- command/util.go | 8 ++++---- go.mod | 2 +- go.sum | 4 ++-- 10 files changed, 33 insertions(+), 31 deletions(-) diff --git a/command/auth_test.go b/command/auth_test.go index e6c895df8fe1..615bc46aecab 100644 --- a/command/auth_test.go +++ b/command/auth_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/hashicorp/cli" - "github.com/hashicorp/vault/command/token" + "github.com/hashicorp/vault/api/tokenhelper" ) func testAuthCommand(tb testing.TB) (*cli.MockUi, *AuthCommand) { @@ -19,7 +19,7 @@ func testAuthCommand(tb testing.TB) (*cli.MockUi, *AuthCommand) { UI: ui, // Override to our own token helper - tokenHelper: token.NewTestingTokenHelper(), + tokenHelper: tokenhelper.NewTestingTokenHelper(), }, } } diff --git a/command/base.go b/command/base.go index 5acd2227fa4f..ed9c76b82689 100644 --- a/command/base.go +++ b/command/base.go @@ -19,8 +19,9 @@ import ( "github.com/hashicorp/cli" hcpvlib "github.com/hashicorp/vault-hcp-lib" "github.com/hashicorp/vault/api" + "github.com/hashicorp/vault/api/cliconfig" + "github.com/hashicorp/vault/api/tokenhelper" "github.com/hashicorp/vault/command/config" - "github.com/hashicorp/vault/command/token" "github.com/hashicorp/vault/helper/namespace" "github.com/mattn/go-isatty" "github.com/pkg/errors" @@ -72,7 +73,7 @@ type BaseCommand struct { flagHeader map[string]string - tokenHelper token.TokenHelper + tokenHelper tokenhelper.TokenHelper hcpTokenHelper hcpvlib.HCPTokenHelper client *api.Client @@ -248,17 +249,17 @@ func (c *BaseCommand) SetAddress(addr string) { } // SetTokenHelper sets the token helper on the command. -func (c *BaseCommand) SetTokenHelper(th token.TokenHelper) { +func (c *BaseCommand) SetTokenHelper(th tokenhelper.TokenHelper) { c.tokenHelper = th } // TokenHelper returns the token helper attached to the command. -func (c *BaseCommand) TokenHelper() (token.TokenHelper, error) { +func (c *BaseCommand) TokenHelper() (tokenhelper.TokenHelper, error) { if c.tokenHelper != nil { return c.tokenHelper, nil } - helper, err := DefaultTokenHelper() + helper, err := cliconfig.DefaultTokenHelper() if err != nil { return nil, err } diff --git a/command/base_predict.go b/command/base_predict.go index 72ba402fe97f..ed3edfa30f91 100644 --- a/command/base_predict.go +++ b/command/base_predict.go @@ -10,6 +10,7 @@ import ( "sync" "github.com/hashicorp/vault/api" + "github.com/hashicorp/vault/api/cliconfig" "github.com/posener/complete" ) @@ -28,7 +29,7 @@ func (p *Predict) Client() *api.Client { client, _ := api.NewClient(nil) if client.Token() == "" { - helper, err := DefaultTokenHelper() + helper, err := cliconfig.DefaultTokenHelper() if err != nil { return } diff --git a/command/config.go b/command/config.go index 9a5ee7ac5700..11b7e863692f 100644 --- a/command/config.go +++ b/command/config.go @@ -4,7 +4,7 @@ package command import ( - "github.com/hashicorp/vault/command/config" + "github.com/hashicorp/vault/api/cliconfig" ) const ( @@ -31,9 +31,9 @@ type DefaultConfig struct { // // Config just calls into config.Config for backwards compatibility purposes. // Use config.Config instead. -func Config() (*DefaultConfig, error) { - conf, err := config.Config() - return (*DefaultConfig)(conf), err +func Config() (*cliconfig.DefaultConfig, error) { + conf, err := cliconfig.Config() + return (*cliconfig.DefaultConfig)(conf), err } // LoadConfig reads the configuration from the given path. If path is @@ -42,16 +42,16 @@ func Config() (*DefaultConfig, error) { // // LoadConfig just calls into config.LoadConfig for backwards compatibility // purposes. Use config.LoadConfig instead. -func LoadConfig(path string) (*DefaultConfig, error) { - conf, err := config.LoadConfig(path) - return (*DefaultConfig)(conf), err +func LoadConfig(path string) (*cliconfig.DefaultConfig, error) { + conf, err := cliconfig.LoadConfig(path) + return (*cliconfig.DefaultConfig)(conf), err } // ParseConfig parses the given configuration as a string. // // ParseConfig just calls into config.ParseConfig for backwards compatibility // purposes. Use config.ParseConfig instead. -func ParseConfig(contents string) (*DefaultConfig, error) { - conf, err := config.ParseConfig(contents) - return (*DefaultConfig)(conf), err +func ParseConfig(contents string) (*cliconfig.DefaultConfig, error) { + conf, err := cliconfig.ParseConfig(contents) + return (*cliconfig.DefaultConfig)(conf), err } diff --git a/command/login_test.go b/command/login_test.go index 3f7c01d3c86e..238f93a4e481 100644 --- a/command/login_test.go +++ b/command/login_test.go @@ -12,9 +12,9 @@ import ( "github.com/hashicorp/cli" "github.com/hashicorp/vault/api" + "github.com/hashicorp/vault/api/tokenhelper" credToken "github.com/hashicorp/vault/builtin/credential/token" credUserpass "github.com/hashicorp/vault/builtin/credential/userpass" - "github.com/hashicorp/vault/command/token" "github.com/hashicorp/vault/helper/testhelpers" "github.com/hashicorp/vault/vault" ) @@ -33,7 +33,7 @@ func testLoginCommand(tb testing.TB) (*cli.MockUi, *LoginCommand) { UI: ui, // Override to our own token helper - tokenHelper: token.NewTestingTokenHelper(), + tokenHelper: tokenhelper.NewTestingTokenHelper(), }, Handlers: map[string]LoginHandler{ "token": &credToken.CLIHandler{}, diff --git a/command/main.go b/command/main.go index d6fad4b6c9ae..465ec5e6e864 100644 --- a/command/main.go +++ b/command/main.go @@ -18,7 +18,7 @@ import ( "github.com/hashicorp/cli" hcpvlib "github.com/hashicorp/vault-hcp-lib" "github.com/hashicorp/vault/api" - "github.com/hashicorp/vault/command/token" + "github.com/hashicorp/vault/api/tokenhelper" "github.com/mattn/go-colorable" ) @@ -135,7 +135,7 @@ func getGlobalFlagValue(arg string) string { } type RunOptions struct { - TokenHelper token.TokenHelper + TokenHelper tokenhelper.TokenHelper HCPTokenHelper hcpvlib.HCPTokenHelper Stdout io.Writer Stderr io.Writer diff --git a/command/server.go b/command/server.go index 6b79e405861f..28079258c716 100644 --- a/command/server.go +++ b/command/server.go @@ -38,8 +38,8 @@ import ( "github.com/hashicorp/go-secure-stdlib/mlock" "github.com/hashicorp/go-secure-stdlib/parseutil" "github.com/hashicorp/go-secure-stdlib/reloadutil" + "github.com/hashicorp/vault/api/cliconfig" "github.com/hashicorp/vault/audit" - config2 "github.com/hashicorp/vault/command/config" "github.com/hashicorp/vault/command/server" "github.com/hashicorp/vault/helper/builtinplugins" "github.com/hashicorp/vault/helper/constants" @@ -3293,7 +3293,7 @@ func startHttpServers(c *ServerCommand, core *vault.Core, config *server.Config, return fmt.Errorf("Found nil listener config after parsing") } - if err := config2.IsValidListener(ln.Config); err != nil { + if err := cliconfig.IsValidListener(ln.Config.TLSDisable); err != nil { return err } diff --git a/command/util.go b/command/util.go index 717191025d24..26fd38000b42 100644 --- a/command/util.go +++ b/command/util.go @@ -15,14 +15,14 @@ import ( "github.com/hashicorp/cli" "github.com/hashicorp/go-cleanhttp" "github.com/hashicorp/vault/api" - "github.com/hashicorp/vault/command/config" - "github.com/hashicorp/vault/command/token" + "github.com/hashicorp/vault/api/cliconfig" + "github.com/hashicorp/vault/api/tokenhelper" ) // DefaultTokenHelper returns the token helper that is configured for Vault. // This helper should only be used for non-server CLI commands. -func DefaultTokenHelper() (token.TokenHelper, error) { - return config.DefaultTokenHelper() +func DefaultTokenHelper() (tokenhelper.TokenHelper, error) { + return cliconfig.DefaultTokenHelper() } // RawField extracts the raw field from the given data and returns it as a diff --git a/go.mod b/go.mod index 24b1790990f9..cf91ee14f4b4 100644 --- a/go.mod +++ b/go.mod @@ -188,7 +188,6 @@ require ( github.com/mitchellh/go-wordwrap v1.0.1 github.com/mitchellh/mapstructure v1.5.0 github.com/mitchellh/reflectwalk v1.0.2 - github.com/natefinch/atomic v0.0.0-20150920032501-a62ce929ffcc github.com/ncw/swift v1.0.47 github.com/oklog/run v1.1.0 github.com/okta/okta-sdk-golang/v2 v2.12.1 @@ -464,6 +463,7 @@ require ( github.com/montanaflynn/stats v0.7.0 // indirect github.com/mtibben/percent v0.2.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/natefinch/atomic v1.0.1 // indirect github.com/nicolai86/scaleway-sdk v1.10.2-0.20180628010248-798f60e20bb2 // indirect github.com/nwaples/rardecode v1.1.2 // indirect github.com/oklog/ulid v1.3.1 // indirect diff --git a/go.sum b/go.sum index d00da7b5adcc..af80468fb531 100644 --- a/go.sum +++ b/go.sum @@ -2969,8 +2969,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= -github.com/natefinch/atomic v0.0.0-20150920032501-a62ce929ffcc h1:7xGrl4tTpBQu5Zjll08WupHyq+Sp0Z/adtyf1cfk3Q8= -github.com/natefinch/atomic v0.0.0-20150920032501-a62ce929ffcc/go.mod h1:1rLVY/DWf3U6vSZgH16S7pymfrhK2lcUlXjgGglw/lY= +github.com/natefinch/atomic v1.0.1 h1:ZPYKxkqQOx3KZ+RsbnP/YsgvxWQPGxjC0oBt2AhwV0A= +github.com/natefinch/atomic v1.0.1/go.mod h1:N/D/ELrljoqDyT3rZrsUmtsuzvHkeB/wWjHV22AZRbM= github.com/ncw/swift v1.0.47 h1:4DQRPj35Y41WogBxyhOXlrI37nzGlyEcsforeudyYPQ= github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM= github.com/networkplumbing/go-nft v0.2.0/go.mod h1:HnnM+tYvlGAsMU7yoYwXEVLLiDW9gdMmb5HoGcwpuQs= From b429d8aa362bda5feea060fb509aad5753273311 Mon Sep 17 00:00:00 2001 From: Tom Proctor Date: Fri, 1 Mar 2024 14:49:34 +0000 Subject: [PATCH 05/13] Fix cliconfig tests --- api/cliconfig/config_test.go | 4 +--- api/tokenhelper/helper_external_test.go | 4 ++-- command/test-fixtures/config.hcl | 4 ---- 3 files changed, 3 insertions(+), 9 deletions(-) delete mode 100644 command/test-fixtures/config.hcl diff --git a/api/cliconfig/config_test.go b/api/cliconfig/config_test.go index f9d6a6580e3b..163f1773997a 100644 --- a/api/cliconfig/config_test.go +++ b/api/cliconfig/config_test.go @@ -10,10 +10,8 @@ import ( "testing" ) -const FixturePath = "../test-fixtures" - func TestLoadConfig(t *testing.T) { - config, err := LoadConfig(filepath.Join(FixturePath, "config.hcl")) + config, err := LoadConfig(filepath.Join("testdata", "config.hcl")) if err != nil { t.Fatalf("err: %s", err) } diff --git a/api/tokenhelper/helper_external_test.go b/api/tokenhelper/helper_external_test.go index 8508a1630e12..c3ca6a595d51 100644 --- a/api/tokenhelper/helper_external_test.go +++ b/api/tokenhelper/helper_external_test.go @@ -53,10 +53,10 @@ func TestExternalTokenHelperPath(t *testing.T) { } func TestExternalTokenHelper(t *testing.T) { - test(t, testExternalTokenHelper(t)) + test(t, testExternalTokenHelper()) } -func testExternalTokenHelper(t *testing.T) *ExternalTokenHelper { +func testExternalTokenHelper() *ExternalTokenHelper { return &ExternalTokenHelper{BinaryPath: helperPath("helper"), Env: helperEnv()} } diff --git a/command/test-fixtures/config.hcl b/command/test-fixtures/config.hcl deleted file mode 100644 index 9161fff4520b..000000000000 --- a/command/test-fixtures/config.hcl +++ /dev/null @@ -1,4 +0,0 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: BUSL-1.1 - -token_helper = "foo" From b5fe43782299d4d09bc1962703d2a3a6e09ac305 Mon Sep 17 00:00:00 2001 From: Tom Proctor Date: Fri, 1 Mar 2024 15:03:38 +0000 Subject: [PATCH 06/13] Simplify and inline function copied from SDK --- api/cliconfig/config.go | 46 +++++++++++++---------------------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/api/cliconfig/config.go b/api/cliconfig/config.go index 0616054f1e0f..06066e4b5ced 100644 --- a/api/cliconfig/config.go +++ b/api/cliconfig/config.go @@ -68,7 +68,7 @@ func LoadConfig(path string) (*DefaultConfig, error) { conf, err := ParseConfig(string(contents)) if err != nil { - return nil, fmt.Errorf("error parsing config file at %q: %w; ensure that the file is valid; Ansible Vault is known to conflict with it.", path, err) + return nil, fmt.Errorf("error parsing config file at %q: %w; ensure that the file is valid; Ansible Vault is known to conflict with it", path, err) } return conf, nil @@ -87,11 +87,20 @@ func ParseConfig(contents string) (*DefaultConfig, error) { return nil, fmt.Errorf("failed to parse config; does not contain a root object") } - valid := []string{ - "token_helper", + valid := map[string]struct{}{ + "token_helper": {}, } - if err := checkHCLKeys(list, valid); err != nil { - return nil, err + + var validationErrors error + for _, item := range list.Items { + key := item.Keys[0].Token.Value().(string) + if _, ok := valid[key]; !ok { + validationErrors = multierror.Append(validationErrors, fmt.Errorf("invalid key %q on line %d", key, item.Assign.Line)) + } + } + + if validationErrors != nil { + return nil, validationErrors } var c DefaultConfig @@ -100,30 +109,3 @@ func ParseConfig(contents string) (*DefaultConfig, error) { } return &c, nil } - -func checkHCLKeys(node ast.Node, valid []string) error { - var list *ast.ObjectList - switch n := node.(type) { - case *ast.ObjectList: - list = n - case *ast.ObjectType: - list = n.List - default: - return fmt.Errorf("cannot check HCL keys of type %T", n) - } - - validMap := make(map[string]struct{}, len(valid)) - for _, v := range valid { - validMap[v] = struct{}{} - } - - var result error - for _, item := range list.Items { - key := item.Keys[0].Token.Value().(string) - if _, ok := validMap[key]; !ok { - result = multierror.Append(result, fmt.Errorf("invalid key %q on line %d", key, item.Assign.Line)) - } - } - - return result -} From d8afe6e7a4e5a92b684be3a333bd04fe8ce59c55 Mon Sep 17 00:00:00 2001 From: Tom Proctor Date: Fri, 1 Mar 2024 15:29:39 +0000 Subject: [PATCH 07/13] Delete unused duplicated/forwarding config implementation from command package --- command/config.go | 57 ------------------------------------------ command/config_test.go | 52 -------------------------------------- 2 files changed, 109 deletions(-) delete mode 100644 command/config.go delete mode 100644 command/config_test.go diff --git a/command/config.go b/command/config.go deleted file mode 100644 index 11b7e863692f..000000000000 --- a/command/config.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: BUSL-1.1 - -package command - -import ( - "github.com/hashicorp/vault/api/cliconfig" -) - -const ( - // DefaultConfigPath is the default path to the configuration file - DefaultConfigPath = "~/.vault" - - // ConfigPathEnv is the environment variable that can be used to - // override where the Vault configuration is. - ConfigPathEnv = "VAULT_CONFIG_PATH" -) - -// Config is the CLI configuration for Vault that can be specified via -// a `$HOME/.vault` file which is HCL-formatted (therefore HCL or JSON). -type DefaultConfig struct { - // TokenHelper is the executable/command that is executed for storing - // and retrieving the authentication token for the Vault CLI. If this - // is not specified, then vault's internal token store will be used, which - // stores the token on disk unencrypted. - TokenHelper string `hcl:"token_helper"` -} - -// Config loads the configuration and returns it. If the configuration -// is already loaded, it is returned. -// -// Config just calls into config.Config for backwards compatibility purposes. -// Use config.Config instead. -func Config() (*cliconfig.DefaultConfig, error) { - conf, err := cliconfig.Config() - return (*cliconfig.DefaultConfig)(conf), err -} - -// LoadConfig reads the configuration from the given path. If path is -// empty, then the default path will be used, or the environment variable -// if set. -// -// LoadConfig just calls into config.LoadConfig for backwards compatibility -// purposes. Use config.LoadConfig instead. -func LoadConfig(path string) (*cliconfig.DefaultConfig, error) { - conf, err := cliconfig.LoadConfig(path) - return (*cliconfig.DefaultConfig)(conf), err -} - -// ParseConfig parses the given configuration as a string. -// -// ParseConfig just calls into config.ParseConfig for backwards compatibility -// purposes. Use config.ParseConfig instead. -func ParseConfig(contents string) (*cliconfig.DefaultConfig, error) { - conf, err := cliconfig.ParseConfig(contents) - return (*cliconfig.DefaultConfig)(conf), err -} diff --git a/command/config_test.go b/command/config_test.go deleted file mode 100644 index 187d4ce8b4be..000000000000 --- a/command/config_test.go +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: BUSL-1.1 - -package command - -import ( - "path/filepath" - "reflect" - "strings" - "testing" -) - -const FixturePath = "./test-fixtures" - -func TestLoadConfig(t *testing.T) { - config, err := LoadConfig(filepath.Join(FixturePath, "config.hcl")) - if err != nil { - t.Fatalf("err: %s", err) - } - - expected := &DefaultConfig{ - TokenHelper: "foo", - } - if !reflect.DeepEqual(expected, config) { - t.Fatalf("bad: %#v", config) - } -} - -func TestLoadConfig_noExist(t *testing.T) { - config, err := LoadConfig("nope/not-once/.never") - if err != nil { - t.Fatal(err) - } - - if config.TokenHelper != "" { - t.Errorf("expected %q to be %q", config.TokenHelper, "") - } -} - -func TestParseConfig_badKeys(t *testing.T) { - _, err := ParseConfig(` -token_helper = "/token" -nope = "true" -`) - if err == nil { - t.Fatal("expected error") - } - - if !strings.Contains(err.Error(), `invalid key "nope" on line 3`) { - t.Errorf("bad error: %s", err.Error()) - } -} From e888f6d8103bdc7fe77f72b72fd126c9c9adc1f9 Mon Sep 17 00:00:00 2001 From: Tom Proctor Date: Mon, 4 Mar 2024 16:23:18 +0000 Subject: [PATCH 08/13] Move IsValidListener back to command/config --- api/cliconfig/validate_listener.go | 10 ---------- command/config/validate_listener.go | 12 ++++++++++++ command/server.go | 4 ++-- 3 files changed, 14 insertions(+), 12 deletions(-) delete mode 100644 api/cliconfig/validate_listener.go create mode 100644 command/config/validate_listener.go diff --git a/api/cliconfig/validate_listener.go b/api/cliconfig/validate_listener.go deleted file mode 100644 index e77bbf5dede9..000000000000 --- a/api/cliconfig/validate_listener.go +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: BUSL-1.1 - -//go:build !fips_140_3 - -package cliconfig - -func IsValidListener(tlsDisable bool) error { - return nil -} diff --git a/command/config/validate_listener.go b/command/config/validate_listener.go new file mode 100644 index 000000000000..09123bdc75b3 --- /dev/null +++ b/command/config/validate_listener.go @@ -0,0 +1,12 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + +//go:build !fips_140_3 + +package config + +import "github.com/hashicorp/vault/internalshared/configutil" + +func IsValidListener(listener *configutil.Listener) error { + return nil +} diff --git a/command/server.go b/command/server.go index 28079258c716..6b79e405861f 100644 --- a/command/server.go +++ b/command/server.go @@ -38,8 +38,8 @@ import ( "github.com/hashicorp/go-secure-stdlib/mlock" "github.com/hashicorp/go-secure-stdlib/parseutil" "github.com/hashicorp/go-secure-stdlib/reloadutil" - "github.com/hashicorp/vault/api/cliconfig" "github.com/hashicorp/vault/audit" + config2 "github.com/hashicorp/vault/command/config" "github.com/hashicorp/vault/command/server" "github.com/hashicorp/vault/helper/builtinplugins" "github.com/hashicorp/vault/helper/constants" @@ -3293,7 +3293,7 @@ func startHttpServers(c *ServerCommand, core *vault.Core, config *server.Config, return fmt.Errorf("Found nil listener config after parsing") } - if err := cliconfig.IsValidListener(ln.Config.TLSDisable); err != nil { + if err := config2.IsValidListener(ln.Config); err != nil { return err } From d598ee61f6014dca9008b475852357d9a5ef916b Mon Sep 17 00:00:00 2001 From: Tom Proctor Date: Mon, 4 Mar 2024 16:38:25 +0000 Subject: [PATCH 09/13] Delete unused code, unexport API surface that's only used internally to the package --- api/cliconfig/config.go | 38 +++++++++---------------- api/cliconfig/config_test.go | 8 +++--- api/cliconfig/util.go | 2 +- api/tokenhelper/helper_external.go | 6 ++-- api/tokenhelper/helper_testing.go | 45 ------------------------------ 5 files changed, 21 insertions(+), 78 deletions(-) delete mode 100644 api/tokenhelper/helper_testing.go diff --git a/api/cliconfig/config.go b/api/cliconfig/config.go index 06066e4b5ced..f81f7c22b3c3 100644 --- a/api/cliconfig/config.go +++ b/api/cliconfig/config.go @@ -14,17 +14,17 @@ import ( ) const ( - // DefaultConfigPath is the default path to the configuration file - DefaultConfigPath = "~/.vault" + // defaultConfigPath is the default path to the configuration file + defaultConfigPath = "~/.vault" - // ConfigPathEnv is the environment variable that can be used to + // configPathEnv is the environment variable that can be used to // override where the Vault configuration is. - ConfigPathEnv = "VAULT_CONFIG_PATH" + configPathEnv = "VAULT_CONFIG_PATH" ) // Config is the CLI configuration for Vault that can be specified via // a `$HOME/.vault` file which is HCL-formatted (therefore HCL or JSON). -type DefaultConfig struct { +type defaultConfig struct { // TokenHelper is the executable/command that is executed for storing // and retrieving the authentication token for the Vault CLI. If this // is not specified, then vault's internal token store will be used, which @@ -32,26 +32,14 @@ type DefaultConfig struct { TokenHelper string `hcl:"token_helper"` } -// Config loads the configuration and returns it. If the configuration -// is already loaded, it is returned. -func Config() (*DefaultConfig, error) { - var err error - config, err := LoadConfig("") - if err != nil { - return nil, err - } - - return config, nil -} - -// LoadConfig reads the configuration from the given path. If path is +// loadConfig reads the configuration from the given path. If path is // empty, then the default path will be used, or the environment variable // if set. -func LoadConfig(path string) (*DefaultConfig, error) { +func loadConfig(path string) (*defaultConfig, error) { if path == "" { - path = DefaultConfigPath + path = defaultConfigPath } - if v := os.Getenv(ConfigPathEnv); v != "" { + if v := os.Getenv(configPathEnv); v != "" { path = v } @@ -66,7 +54,7 @@ func LoadConfig(path string) (*DefaultConfig, error) { return nil, err } - conf, err := ParseConfig(string(contents)) + conf, err := parseConfig(string(contents)) if err != nil { return nil, fmt.Errorf("error parsing config file at %q: %w; ensure that the file is valid; Ansible Vault is known to conflict with it", path, err) } @@ -74,8 +62,8 @@ func LoadConfig(path string) (*DefaultConfig, error) { return conf, nil } -// ParseConfig parses the given configuration as a string. -func ParseConfig(contents string) (*DefaultConfig, error) { +// parseConfig parses the given configuration as a string. +func parseConfig(contents string) (*defaultConfig, error) { root, err := hcl.Parse(contents) if err != nil { return nil, err @@ -103,7 +91,7 @@ func ParseConfig(contents string) (*DefaultConfig, error) { return nil, validationErrors } - var c DefaultConfig + var c defaultConfig if err := hcl.DecodeObject(&c, list); err != nil { return nil, err } diff --git a/api/cliconfig/config_test.go b/api/cliconfig/config_test.go index 163f1773997a..1c2b2f7dc224 100644 --- a/api/cliconfig/config_test.go +++ b/api/cliconfig/config_test.go @@ -11,12 +11,12 @@ import ( ) func TestLoadConfig(t *testing.T) { - config, err := LoadConfig(filepath.Join("testdata", "config.hcl")) + config, err := loadConfig(filepath.Join("testdata", "config.hcl")) if err != nil { t.Fatalf("err: %s", err) } - expected := &DefaultConfig{ + expected := &defaultConfig{ TokenHelper: "foo", } if !reflect.DeepEqual(expected, config) { @@ -25,7 +25,7 @@ func TestLoadConfig(t *testing.T) { } func TestLoadConfig_noExist(t *testing.T) { - config, err := LoadConfig("nope/not-once/.never") + config, err := loadConfig("nope/not-once/.never") if err != nil { t.Fatal(err) } @@ -36,7 +36,7 @@ func TestLoadConfig_noExist(t *testing.T) { } func TestParseConfig_badKeys(t *testing.T) { - _, err := ParseConfig(` + _, err := parseConfig(` token_helper = "/token" nope = "true" `) diff --git a/api/cliconfig/util.go b/api/cliconfig/util.go index 8cf0b97622ca..e7db3d6034a2 100644 --- a/api/cliconfig/util.go +++ b/api/cliconfig/util.go @@ -10,7 +10,7 @@ import ( // DefaultTokenHelper returns the token helper that is configured for Vault. // This helper should only be used for non-server CLI commands. func DefaultTokenHelper() (tokenhelper.TokenHelper, error) { - config, err := LoadConfig("") + config, err := loadConfig("") if err != nil { return nil, err } diff --git a/api/tokenhelper/helper_external.go b/api/tokenhelper/helper_external.go index b1e562e0d8a1..ff761230fabb 100644 --- a/api/tokenhelper/helper_external.go +++ b/api/tokenhelper/helper_external.go @@ -110,7 +110,7 @@ func (h *ExternalTokenHelper) Path() string { func (h *ExternalTokenHelper) cmd(op string) (*exec.Cmd, error) { script := strings.ReplaceAll(h.BinaryPath, "\\", "\\\\") + " " + op - cmd, err := ExecScript(script) + cmd, err := execScript(script) if err != nil { return nil, err } @@ -118,8 +118,8 @@ func (h *ExternalTokenHelper) cmd(op string) (*exec.Cmd, error) { return cmd, nil } -// ExecScript returns a command to execute a script -func ExecScript(script string) (*exec.Cmd, error) { +// execScript returns a command to execute a script +func execScript(script string) (*exec.Cmd, error) { var shell, flag string if runtime.GOOS == "windows" { shell = "cmd" diff --git a/api/tokenhelper/helper_testing.go b/api/tokenhelper/helper_testing.go deleted file mode 100644 index d1e2d17c77bf..000000000000 --- a/api/tokenhelper/helper_testing.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: BUSL-1.1 - -package tokenhelper - -import ( - "sync" -) - -var _ TokenHelper = (*TestingTokenHelper)(nil) - -// TestingTokenHelper implements token.TokenHelper which runs entirely -// in-memory. This should not be used outside of testing. -type TestingTokenHelper struct { - lock sync.RWMutex - token string -} - -func NewTestingTokenHelper() *TestingTokenHelper { - return &TestingTokenHelper{} -} - -func (t *TestingTokenHelper) Erase() error { - t.lock.Lock() - defer t.lock.Unlock() - t.token = "" - return nil -} - -func (t *TestingTokenHelper) Get() (string, error) { - t.lock.RLock() - defer t.lock.RUnlock() - return t.token, nil -} - -func (t *TestingTokenHelper) Path() string { - return "" -} - -func (t *TestingTokenHelper) Store(token string) error { - t.lock.Lock() - defer t.lock.Unlock() - t.token = token - return nil -} From f05f3fd65ff908b57a989ddb6537461de3d11487 Mon Sep 17 00:00:00 2001 From: Tom Proctor Date: Mon, 4 Mar 2024 16:40:38 +0000 Subject: [PATCH 10/13] Fix up license headers --- api/cliconfig/config.go | 2 +- api/cliconfig/config_test.go | 2 +- api/cliconfig/util.go | 2 +- api/tokenhelper/helper.go | 2 +- api/tokenhelper/helper_external.go | 2 +- api/tokenhelper/helper_external_test.go | 2 +- api/tokenhelper/helper_internal.go | 2 +- api/tokenhelper/helper_internal_test.go | 2 +- api/tokenhelper/testing.go | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/api/cliconfig/config.go b/api/cliconfig/config.go index f81f7c22b3c3..f918f24395f8 100644 --- a/api/cliconfig/config.go +++ b/api/cliconfig/config.go @@ -1,5 +1,5 @@ // Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: BUSL-1.1 +// SPDX-License-Identifier: MPL-2.0 package cliconfig diff --git a/api/cliconfig/config_test.go b/api/cliconfig/config_test.go index 1c2b2f7dc224..5e2dedeaeb0a 100644 --- a/api/cliconfig/config_test.go +++ b/api/cliconfig/config_test.go @@ -1,5 +1,5 @@ // Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: BUSL-1.1 +// SPDX-License-Identifier: MPL-2.0 package cliconfig diff --git a/api/cliconfig/util.go b/api/cliconfig/util.go index e7db3d6034a2..e492ccb03857 100644 --- a/api/cliconfig/util.go +++ b/api/cliconfig/util.go @@ -1,5 +1,5 @@ // Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: BUSL-1.1 +// SPDX-License-Identifier: MPL-2.0 package cliconfig diff --git a/api/tokenhelper/helper.go b/api/tokenhelper/helper.go index c6ff7dd7ebb8..a70d3e20a22f 100644 --- a/api/tokenhelper/helper.go +++ b/api/tokenhelper/helper.go @@ -1,5 +1,5 @@ // Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: BUSL-1.1 +// SPDX-License-Identifier: MPL-2.0 package tokenhelper diff --git a/api/tokenhelper/helper_external.go b/api/tokenhelper/helper_external.go index ff761230fabb..e9bfb18b8c59 100644 --- a/api/tokenhelper/helper_external.go +++ b/api/tokenhelper/helper_external.go @@ -1,5 +1,5 @@ // Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: BUSL-1.1 +// SPDX-License-Identifier: MPL-2.0 package tokenhelper diff --git a/api/tokenhelper/helper_external_test.go b/api/tokenhelper/helper_external_test.go index c3ca6a595d51..8928c004026e 100644 --- a/api/tokenhelper/helper_external_test.go +++ b/api/tokenhelper/helper_external_test.go @@ -1,5 +1,5 @@ // Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: BUSL-1.1 +// SPDX-License-Identifier: MPL-2.0 package tokenhelper diff --git a/api/tokenhelper/helper_internal.go b/api/tokenhelper/helper_internal.go index 8b4605ea8ac2..ce95aef07ce4 100644 --- a/api/tokenhelper/helper_internal.go +++ b/api/tokenhelper/helper_internal.go @@ -1,5 +1,5 @@ // Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: BUSL-1.1 +// SPDX-License-Identifier: MPL-2.0 package tokenhelper diff --git a/api/tokenhelper/helper_internal_test.go b/api/tokenhelper/helper_internal_test.go index 47bf73803323..5250da014e2c 100644 --- a/api/tokenhelper/helper_internal_test.go +++ b/api/tokenhelper/helper_internal_test.go @@ -1,5 +1,5 @@ // Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: BUSL-1.1 +// SPDX-License-Identifier: MPL-2.0 package tokenhelper diff --git a/api/tokenhelper/testing.go b/api/tokenhelper/testing.go index dd5040f51592..577b4940f325 100644 --- a/api/tokenhelper/testing.go +++ b/api/tokenhelper/testing.go @@ -1,5 +1,5 @@ // Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: BUSL-1.1 +// SPDX-License-Identifier: MPL-2.0 package tokenhelper From 2cf0053e0d7e4d2167399e2a729caab82a3a0047 Mon Sep 17 00:00:00 2001 From: Tom Proctor Date: Mon, 4 Mar 2024 16:48:21 +0000 Subject: [PATCH 11/13] Add changelog --- changelog/25744.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/25744.txt diff --git a/changelog/25744.txt b/changelog/25744.txt new file mode 100644 index 000000000000..274b228bc208 --- /dev/null +++ b/changelog/25744.txt @@ -0,0 +1,3 @@ +```release-note:improvement +api: Move CLI token helper functions to importable packages in `api` module. +``` From 07027b3ee103074480d0000d37f82313fd9adbef Mon Sep 17 00:00:00 2001 From: Tom Proctor Date: Mon, 4 Mar 2024 16:51:24 +0000 Subject: [PATCH 12/13] Tweak .gitignore to track hcl files in testdata/ folders --- .gitignore | 1 + api/cliconfig/testdata/config.hcl | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 api/cliconfig/testdata/config.hcl diff --git a/.gitignore b/.gitignore index 95e675edf57b..1675763341e1 100644 --- a/.gitignore +++ b/.gitignore @@ -58,6 +58,7 @@ Vagrantfile !command/agent/config/test-fixtures/*.hcl !command/server/test-fixtures/**/*.hcl !enos/**/*.hcl +!**/testdata/*.hcl # Enos .enos diff --git a/api/cliconfig/testdata/config.hcl b/api/cliconfig/testdata/config.hcl new file mode 100644 index 000000000000..164acd29cc80 --- /dev/null +++ b/api/cliconfig/testdata/config.hcl @@ -0,0 +1,4 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +token_helper = "foo" From 7a5f78e380f294ae95fe250fbde408ad7ce0b23a Mon Sep 17 00:00:00 2001 From: Tom Proctor Date: Mon, 4 Mar 2024 17:19:42 +0000 Subject: [PATCH 13/13] Reinstate testing token helper but in original command/token package --- command/auth_test.go | 4 +-- command/login_test.go | 4 +-- command/token/helper_testing.go | 47 +++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 command/token/helper_testing.go diff --git a/command/auth_test.go b/command/auth_test.go index 615bc46aecab..e6c895df8fe1 100644 --- a/command/auth_test.go +++ b/command/auth_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/hashicorp/cli" - "github.com/hashicorp/vault/api/tokenhelper" + "github.com/hashicorp/vault/command/token" ) func testAuthCommand(tb testing.TB) (*cli.MockUi, *AuthCommand) { @@ -19,7 +19,7 @@ func testAuthCommand(tb testing.TB) (*cli.MockUi, *AuthCommand) { UI: ui, // Override to our own token helper - tokenHelper: tokenhelper.NewTestingTokenHelper(), + tokenHelper: token.NewTestingTokenHelper(), }, } } diff --git a/command/login_test.go b/command/login_test.go index 238f93a4e481..3f7c01d3c86e 100644 --- a/command/login_test.go +++ b/command/login_test.go @@ -12,9 +12,9 @@ import ( "github.com/hashicorp/cli" "github.com/hashicorp/vault/api" - "github.com/hashicorp/vault/api/tokenhelper" credToken "github.com/hashicorp/vault/builtin/credential/token" credUserpass "github.com/hashicorp/vault/builtin/credential/userpass" + "github.com/hashicorp/vault/command/token" "github.com/hashicorp/vault/helper/testhelpers" "github.com/hashicorp/vault/vault" ) @@ -33,7 +33,7 @@ func testLoginCommand(tb testing.TB) (*cli.MockUi, *LoginCommand) { UI: ui, // Override to our own token helper - tokenHelper: tokenhelper.NewTestingTokenHelper(), + tokenHelper: token.NewTestingTokenHelper(), }, Handlers: map[string]LoginHandler{ "token": &credToken.CLIHandler{}, diff --git a/command/token/helper_testing.go b/command/token/helper_testing.go new file mode 100644 index 000000000000..a536c3c3cc52 --- /dev/null +++ b/command/token/helper_testing.go @@ -0,0 +1,47 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + +package token + +import ( + "sync" + + "github.com/hashicorp/vault/api/tokenhelper" +) + +var _ tokenhelper.TokenHelper = (*TestingTokenHelper)(nil) + +// TestingTokenHelper implements token.TokenHelper which runs entirely +// in-memory. This should not be used outside of testing. +type TestingTokenHelper struct { + lock sync.RWMutex + token string +} + +func NewTestingTokenHelper() *TestingTokenHelper { + return &TestingTokenHelper{} +} + +func (t *TestingTokenHelper) Erase() error { + t.lock.Lock() + defer t.lock.Unlock() + t.token = "" + return nil +} + +func (t *TestingTokenHelper) Get() (string, error) { + t.lock.RLock() + defer t.lock.RUnlock() + return t.token, nil +} + +func (t *TestingTokenHelper) Path() string { + return "" +} + +func (t *TestingTokenHelper) Store(token string) error { + t.lock.Lock() + defer t.lock.Unlock() + t.token = token + return nil +}