Exemple #1
0
func getDetailsFromDockerConfigSecret(secretGetter k8s.SecretGetter, secret string) (map[string]string, error) {
	configSecret, err := secretGetter.Get(secret)
	if err != nil {
		return nil, err
	}
	dockerConfigJSONBytes := configSecret.Data[api.DockerConfigJsonKey]
	var secretData map[string]interface{}
	if err = json.Unmarshal(dockerConfigJSONBytes, &secretData); err != nil {
		return nil, err
	}

	var authdata map[string]interface{}
	var hostname string
	for key, value := range secretData["auths"].(map[string]interface{}) {
		hostname = key
		authdata = value.(map[string]interface{})
	}
	token := authdata["auth"].(string)
	decodedToken, err := base64.StdEncoding.DecodeString(token)
	if err != nil {
		return nil, err
	}
	parts := strings.SplitN(string(decodedToken), ":", 2)
	if len(parts) != 2 {
		return nil, errors.New("Invalid token in docker config secret")
	}
	user := parts[0]
	password := parts[1]
	regDetails := make(map[string]string)
	regDetails["DEIS_REGISTRY_USERNAME"] = user
	regDetails["DEIS_REGISTRY_PASSWORD"] = password
	regDetails["DEIS_REGISTRY_HOSTNAME"] = hostname
	return regDetails, nil
}
Exemple #2
0
func getDetailsFromRegistrySecret(secretGetter k8s.SecretGetter, secret string) (map[string]string, error) {
	regSecret, err := secretGetter.Get(secret)
	if err != nil {
		return nil, err
	}
	regDetails := make(map[string]string)
	for key, value := range regSecret.Data {
		regDetails[key] = string(value)
	}
	return regDetails, nil
}