|
| 1 | +package cmd |
| 2 | + |
| 3 | +/* |
| 4 | + Copyright 2017-2018 Crunchy Data Solutions, Inc. |
| 5 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + you may not use this file except in compliance with the License. |
| 7 | + You may obtain a copy of the License at |
| 8 | +
|
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | + Unless required by applicable law or agreed to in writing, software |
| 12 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + See the License for the specific language governing permissions and |
| 15 | + limitations under the License. |
| 16 | +*/ |
| 17 | + |
| 18 | +import ( |
| 19 | + "encoding/json" |
| 20 | + "fmt" |
| 21 | + log "github.com/Sirupsen/logrus" |
| 22 | + msgs "github.com/crunchydata/postgres-operator/apiservermsgs" |
| 23 | + "net/http" |
| 24 | + "os" |
| 25 | +) |
| 26 | + |
| 27 | +func showConfig(args []string) { |
| 28 | + |
| 29 | + log.Debugf("showConfig called %v\n", args) |
| 30 | + |
| 31 | + url := APIServerURL + "/config?version=" + ClientVersion |
| 32 | + log.Debug(url) |
| 33 | + |
| 34 | + req, err := http.NewRequest("GET", url, nil) |
| 35 | + if err != nil { |
| 36 | + log.Fatal("NewRequest: ", err) |
| 37 | + return |
| 38 | + } |
| 39 | + |
| 40 | + req.Header.Set("Content-Type", "application/json") |
| 41 | + req.SetBasicAuth(BasicAuthUsername, BasicAuthPassword) |
| 42 | + |
| 43 | + resp, err := httpclient.Do(req) |
| 44 | + if err != nil { |
| 45 | + log.Fatal("Do: ", err) |
| 46 | + return |
| 47 | + } |
| 48 | + log.Debugf("%v\n", resp) |
| 49 | + StatusCheck(resp) |
| 50 | + |
| 51 | + defer resp.Body.Close() |
| 52 | + |
| 53 | + var response msgs.ShowConfigResponse |
| 54 | + |
| 55 | + if err := json.NewDecoder(resp.Body).Decode(&response); err != nil { |
| 56 | + log.Printf("%v\n", resp.Body) |
| 57 | + log.Error(err) |
| 58 | + log.Println(err) |
| 59 | + return |
| 60 | + } |
| 61 | + |
| 62 | + if response.Status.Code != msgs.Ok { |
| 63 | + log.Error(RED(response.Status.Msg)) |
| 64 | + os.Exit(2) |
| 65 | + } |
| 66 | + |
| 67 | + if OutputFormat == "json" { |
| 68 | + b, err := json.MarshalIndent(response, "", " ") |
| 69 | + if err != nil { |
| 70 | + fmt.Println("error:", err) |
| 71 | + } |
| 72 | + fmt.Println(string(b)) |
| 73 | + return |
| 74 | + } |
| 75 | + |
| 76 | + pgo := response.Result |
| 77 | + |
| 78 | + fmt.Printf("%s%s\n", "BasicAuth: ", pgo.BasicAuth) |
| 79 | + fmt.Printf("%s\n", "Cluster:") |
| 80 | + fmt.Printf("%s%s\n", " CCPImagePrefix: ", pgo.Cluster.CCPImagePrefix) |
| 81 | + fmt.Printf("%s%s\n", " CCPImageTag: ", pgo.Cluster.CCPImageTag) |
| 82 | + fmt.Printf("%s%s\n", " Policies: ", pgo.Cluster.Policies) |
| 83 | + fmt.Printf("%s%s\n", " Port: ", pgo.Cluster.Port) |
| 84 | + fmt.Printf("%s%s\n", " ArchiveTimeout: ", pgo.Cluster.ArchiveTimeout) |
| 85 | + fmt.Printf("%s%s\n", " ArchiveMode: ", pgo.Cluster.ArchiveMode) |
| 86 | + fmt.Printf("%s%s\n", " User: ", pgo.Cluster.User) |
| 87 | + fmt.Printf("%s%s\n", " Database: ", pgo.Cluster.Database) |
| 88 | + fmt.Printf("%s%s\n", " PasswordAgeDays: ", pgo.Cluster.PasswordAgeDays) |
| 89 | + fmt.Printf("%s%s\n", " PasswordLength: ", pgo.Cluster.PasswordLength) |
| 90 | + fmt.Printf("%s%s\n", " Strategy: ", pgo.Cluster.Strategy) |
| 91 | + fmt.Printf("%s%s\n", " Replicas: ", pgo.Cluster.Replicas) |
| 92 | + |
| 93 | + fmt.Printf("%s%s\n", "PrimaryStorage: ", pgo.PrimaryStorage) |
| 94 | + fmt.Printf("%s%s\n", "BackupStorage: ", pgo.BackupStorage) |
| 95 | + fmt.Printf("%s%s\n", "ReplicaStorage: ", pgo.ReplicaStorage) |
| 96 | + fmt.Printf("%s\n", "Storage:") |
| 97 | + for k, v := range pgo.Storage { |
| 98 | + fmt.Printf(" %s:\n", k) |
| 99 | + fmt.Printf("%s%s\n", " AccessMode: ", v.AccessMode) |
| 100 | + fmt.Printf("%s%s\n", " Size: ", v.Size) |
| 101 | + fmt.Printf("%s%s\n", " StorageType: ", v.StorageType) |
| 102 | + fmt.Printf("%s%s\n", " StorageClass: ", v.StorageClass) |
| 103 | + fmt.Printf("%s%s\n", " Fsgroup: ", v.Fsgroup) |
| 104 | + fmt.Printf("%s%s\n", " SupplementalGroups: ", v.SupplementalGroups) |
| 105 | + } |
| 106 | + |
| 107 | + fmt.Printf("%s%s\n", "DefaultContainerResources:", pgo.DefaultContainerResources) |
| 108 | + fmt.Printf("%s\n", "ContainerResources:") |
| 109 | + for k, v := range pgo.ContainerResources { |
| 110 | + fmt.Printf(" %s:\n", k) |
| 111 | + fmt.Printf("%s%s\n", " RequestsMemory: ", v.RequestsMemory) |
| 112 | + fmt.Printf("%s%s\n", " RequestsCPU: ", v.RequestsCPU) |
| 113 | + fmt.Printf("%s%s\n", " LimitsMemory: ", v.LimitsMemory) |
| 114 | + fmt.Printf("%s%s\n", " LimitsCPU: ", v.LimitsCPU) |
| 115 | + } |
| 116 | + |
| 117 | + fmt.Printf("%s\n", "Pgo:") |
| 118 | + fmt.Printf("%s%s\n", " AutofailSleepSeconds: ", pgo.Pgo.AutofailSleepSeconds) |
| 119 | + fmt.Printf("%s%t\n", " Audit: ", pgo.Pgo.Audit) |
| 120 | + fmt.Printf("%s%t\n", " Metrics: ", pgo.Pgo.Metrics) |
| 121 | + fmt.Printf("%s%s\n", " LSPVCTemplate: ", pgo.Pgo.LSPVCTemplate) |
| 122 | + fmt.Printf("%s%s\n", " LoadTemplate: ", pgo.Pgo.LoadTemplate) |
| 123 | + fmt.Printf("%s%s\n", " COImagePrefix: ", pgo.Pgo.COImagePrefix) |
| 124 | + fmt.Printf("%s%s\n", " COImageTag: ", pgo.Pgo.COImageTag) |
| 125 | + |
| 126 | + fmt.Println("") |
| 127 | + |
| 128 | +} |
0 commit comments