mirror of
https://github.com/rancher/cli.git
synced 2026-02-05 18:48:50 +01:00
fix yaml keys
This commit is contained in:
committed by
Alena Prokharchyk
parent
5139832ec2
commit
8fdf66aff3
@@ -772,6 +772,10 @@ func getRKEConfig(ctx *cli.Context) (*managementClient.RancherKubernetesEngineCo
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bytes, err = fixTopLevelKeys(bytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(bytes, &rkeConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
"github.com/rancher/cli/config"
|
||||
"github.com/rancher/norman/clientbase"
|
||||
ntypes "github.com/rancher/norman/types"
|
||||
"github.com/rancher/norman/types/convert"
|
||||
managementClient "github.com/rancher/types/client/management/v3"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
@@ -501,6 +502,23 @@ func parseClusterAndProjectID(id string) (string, string, error) {
|
||||
return "", "", fmt.Errorf("Unable to extract clusterid and projectid from [%s]", id)
|
||||
}
|
||||
|
||||
func fixTopLevelKeys(bytes []byte) ([]byte, error) {
|
||||
old := map[string]interface{}{}
|
||||
new := map[string]interface{}{}
|
||||
|
||||
err := json.Unmarshal(bytes, &old)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error unmarshalling: %v", err)
|
||||
}
|
||||
|
||||
for key, val := range old {
|
||||
newKey := convert.ToJSONKey(key)
|
||||
new[newKey] = val
|
||||
}
|
||||
|
||||
return json.Marshal(new)
|
||||
}
|
||||
|
||||
// Return a JSON blob of the file at path
|
||||
func readFileReturnJSON(path string) ([]byte, error) {
|
||||
file, err := ioutil.ReadFile(path)
|
||||
|
||||
Reference in New Issue
Block a user