mirror of
https://github.com/helm/helm.git
synced 2026-04-15 21:59:50 -04:00
Merge pull request #11226 from programmer04/fix-user-agent
Fix User-Agent header in requests made by Helm
This commit is contained in:
commit
162d93f72b
4 changed files with 23 additions and 4 deletions
|
|
@ -14,7 +14,8 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*Package cli describes the operating environment for the Helm CLI.
|
||||
/*
|
||||
Package cli describes the operating environment for the Helm CLI.
|
||||
|
||||
Helm's environment encapsulates all of the service dependencies Helm has.
|
||||
These dependencies are expressed as interfaces so that alternate implementations
|
||||
|
|
@ -33,6 +34,7 @@ import (
|
|||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
"k8s.io/client-go/rest"
|
||||
|
||||
"helm.sh/helm/v3/internal/version"
|
||||
"helm.sh/helm/v3/pkg/helmpath"
|
||||
)
|
||||
|
||||
|
|
@ -120,6 +122,7 @@ func New() *EnvSettings {
|
|||
config.Wrap(func(rt http.RoundTripper) http.RoundTripper {
|
||||
return &retryingRoundTripper{wrapped: rt}
|
||||
})
|
||||
config.UserAgent = version.GetUserAgent()
|
||||
return config
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
"helm.sh/helm/v3/internal/version"
|
||||
)
|
||||
|
||||
func TestSetNamespace(t *testing.T) {
|
||||
|
|
@ -231,6 +233,21 @@ func TestEnvOrBool(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestUserAgentHeaderInK8sRESTClientConfig(t *testing.T) {
|
||||
defer resetEnv()()
|
||||
|
||||
settings := New()
|
||||
restConfig, err := settings.RESTClientGetter().ToRESTConfig()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expectedUserAgent := version.GetUserAgent()
|
||||
if restConfig.UserAgent != expectedUserAgent {
|
||||
t.Errorf("expected User-Agent header %q in K8s REST client config, got %q", expectedUserAgent, restConfig.UserAgent)
|
||||
}
|
||||
}
|
||||
|
||||
func resetEnv() func() {
|
||||
origEnv := os.Environ()
|
||||
|
||||
|
|
|
|||
|
|
@ -155,9 +155,8 @@ func TestHTTPGetter(t *testing.T) {
|
|||
|
||||
func TestDownload(t *testing.T) {
|
||||
expect := "Call me Ishmael"
|
||||
expectedUserAgent := "I am Groot"
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
defaultUserAgent := "Helm/" + strings.TrimPrefix(version.GetVersion(), "v")
|
||||
defaultUserAgent := version.GetUserAgent()
|
||||
if r.UserAgent() != defaultUserAgent {
|
||||
t.Errorf("Expected '%s', got '%s'", defaultUserAgent, r.UserAgent())
|
||||
}
|
||||
|
|
@ -179,6 +178,7 @@ func TestDownload(t *testing.T) {
|
|||
}
|
||||
|
||||
// test with http server
|
||||
const expectedUserAgent = "I am Groot"
|
||||
basicAuthSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
username, password, ok := r.BasicAuth()
|
||||
if !ok || username != "username" || password != "password" {
|
||||
|
|
|
|||
|
|
@ -120,7 +120,6 @@ func (r *ChartRepository) DownloadIndexFile() (string, error) {
|
|||
return "", err
|
||||
}
|
||||
|
||||
// TODO add user-agent
|
||||
resp, err := r.Client.Get(indexURL,
|
||||
getter.WithURL(r.Config.URL),
|
||||
getter.WithInsecureSkipVerifyTLS(r.Config.InsecureSkipTLSverify),
|
||||
|
|
|
|||
Loading…
Reference in a new issue