代码拉取完成,页面将自动刷新
package httpproxy
import (
"fmt"
"github.com/rancher/rancher/pkg/namespace"
"github.com/rancher/types/apis/core/v1"
"strings"
)
func getAuthData(auth string, secrets v1.SecretInterface, fields []string) (map[string]string, map[string]string, error) {
data := getRequestParams(auth)
if !requiredFieldsExist(data, fields) {
return data, nil, fmt.Errorf("required fields %s not set", fields)
}
if data["credID"] == "" {
return data, nil, nil
}
secret, err := getCredential(data["credID"], secrets)
if err != nil {
return data, nil, err
}
return data, secret, nil
}
func getRequestParams(auth string) map[string]string {
params := map[string]string{}
if auth != "" {
splitAuth := strings.Split(auth, " ")
for _, term := range splitAuth[1:] {
splitTerm := strings.SplitN(term, "=", 2)
params[splitTerm[0]] = splitTerm[1]
}
}
return params
}
func requiredFieldsExist(data map[string]string, fields []string) bool {
for _, field := range fields {
if val, ok := data[field]; !ok || val == "" {
return false
}
}
return true
}
func getCredential(credentialID string, credentials v1.SecretInterface) (map[string]string, error) {
split := strings.SplitN(credentialID, ":", 2)
if len(split) != 2 || split[0] == "" || split[1] == "" {
return nil, fmt.Errorf("invalid credential id %s", credentialID)
}
cred, err := credentials.Controller().Lister().Get(namespace.GlobalNamespace, split[1])
if err != nil {
return nil, err
}
ans := map[string]string{}
for key, val := range cred.Data {
splitKeys := strings.Split(key, "-")
if len(splitKeys) == 2 && strings.HasSuffix(splitKeys[0], "Config") {
ans[splitKeys[1]] = string(val)
}
}
return ans, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。