Skip to content

Commit

Permalink
Merge pull request #565 from l1b0k/feat/header
Browse files Browse the repository at this point in the history
feat: custom header
  • Loading branch information
BSWANG authored Jan 25, 2024
2 parents 4e63320 + 73b2eef commit 45e96b9
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion pkg/aliyun/credential/aliyun_client_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,37 @@ var (
tokenReSyncPeriod = 5 * time.Minute
)

type headerTransport struct {
headers map[string]string
}

func (m *headerTransport) RoundTrip(req *http.Request) (*http.Response, error) {
for k, v := range m.headers {
req.Header.Set(k, v)
}
return http.DefaultTransport.RoundTrip(req)
}

func clientCfg() *sdk.Config {
scheme := "HTTPS"
if os.Getenv("ALICLOUD_CLIENT_SCHEME") == "HTTP" {
scheme = "HTTP"
}
return &sdk.Config{
s := &sdk.Config{
Timeout: 20 * time.Second,
Transport: http.DefaultTransport,
UserAgent: kubernetesAlicloudIdentity,
Scheme: scheme,
}
if os.Getenv("X-ACSPROXY-ASCM-CONTEXT") != "" {
s.Transport = &headerTransport{
headers: map[string]string{
"x-acsproxy-ascm-context": os.Getenv("X-ACSPROXY-ASCM-CONTEXT"),
},
}
}

return s
}

// ClientMgr manager of aliyun openapi clientset
Expand Down

0 comments on commit 45e96b9

Please sign in to comment.