Skip to content

Commit 11e6a8f

Browse files
author
Jeff McCormick
committed
add pgo show config command
1 parent d005733 commit 11e6a8f

File tree

11 files changed

+297
-9
lines changed

11 files changed

+297
-9
lines changed

README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
image::crunchy_logo.png[Crunchy Data Logo]
22

3-
Latest Release: v3.0, {docdate}
3+
Latest Release: v3.1, {docdate}
44

55
== General
66

apiserver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/crunchydata/postgres-operator/apiserver"
2323
"github.com/crunchydata/postgres-operator/apiserver/backupservice"
2424
"github.com/crunchydata/postgres-operator/apiserver/clusterservice"
25+
"github.com/crunchydata/postgres-operator/apiserver/configservice"
2526
"github.com/crunchydata/postgres-operator/apiserver/dfservice"
2627
"github.com/crunchydata/postgres-operator/apiserver/failoverservice"
2728
"github.com/crunchydata/postgres-operator/apiserver/ingestservice"
@@ -102,6 +103,7 @@ func main() {
102103
r.HandleFunc("/clusters/scale/{name}", clusterservice.ScaleClusterHandler)
103104
r.HandleFunc("/status", statusservice.StatusHandler)
104105
r.HandleFunc("/df/{name}", dfservice.DfHandler)
106+
r.HandleFunc("/config", configservice.ShowConfigHandler)
105107

106108
r.HandleFunc("/backups/{name}", backupservice.ShowBackupHandler).Methods("GET")
107109
//here
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package configservice
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+
log "github.com/Sirupsen/logrus"
20+
"github.com/crunchydata/postgres-operator/apiserver"
21+
msgs "github.com/crunchydata/postgres-operator/apiservermsgs"
22+
)
23+
24+
func ShowConfig() msgs.ShowConfigResponse {
25+
log.Debug("ShowConfig called")
26+
response := msgs.ShowConfigResponse{}
27+
response.Status = msgs.Status{Code: msgs.Ok, Msg: ""}
28+
29+
response.Result = apiserver.Pgo
30+
31+
return response
32+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package configservice
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+
log "github.com/Sirupsen/logrus"
21+
"github.com/crunchydata/postgres-operator/apiserver"
22+
msgs "github.com/crunchydata/postgres-operator/apiservermsgs"
23+
"net/http"
24+
)
25+
26+
// ShowConfigHandler ...
27+
// pgo show config
28+
func ShowConfigHandler(w http.ResponseWriter, r *http.Request) {
29+
log.Debug("configservice.ShowConfigHandler")
30+
31+
clientVersion := r.URL.Query().Get("version")
32+
if clientVersion != "" {
33+
log.Debug("version param was [" + clientVersion + "]")
34+
}
35+
36+
err := apiserver.Authn(apiserver.SHOW_CONFIG_PERM, w, r)
37+
if err != nil {
38+
return
39+
}
40+
41+
w.WriteHeader(http.StatusOK)
42+
w.Header().Set("Content-Type", "application/json")
43+
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
44+
45+
var resp msgs.ShowConfigResponse
46+
if clientVersion != apiserver.VERSION {
47+
resp = msgs.ShowConfigResponse{}
48+
resp.Status = msgs.Status{Code: msgs.Error, Msg: apiserver.VERSION_MISMATCH_ERROR}
49+
} else {
50+
resp = ShowConfig()
51+
}
52+
53+
json.NewEncoder(w).Encode(resp)
54+
}

apiserver/perms.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"strings"
2424
)
2525

26+
const SHOW_CONFIG_PERM = "ShowConfig"
2627
const DF_CLUSTER_PERM = "DfCluster"
2728
const SHOW_CLUSTER_PERM = "ShowCluster"
2829
const CREATE_CLUSTER_PERM = "CreateCluster"
@@ -60,6 +61,7 @@ func InitializePerms() {
6061
PermMap = make(map[string]string)
6162
RoleMap = make(map[string]map[string]string)
6263

64+
PermMap[SHOW_CONFIG_PERM] = "yes"
6365
PermMap[STATUS_PERM] = "yes"
6466
PermMap[DF_CLUSTER_PERM] = "yes"
6567
PermMap[SHOW_CLUSTER_PERM] = "yes"

apiservermsgs/configmsgs.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package apiservermsgs
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+
"github.com/crunchydata/postgres-operator/config"
20+
)
21+
22+
// ShowConfigResponse ...
23+
type ShowConfigResponse struct {
24+
Result config.PgoConfig
25+
Status
26+
}

conf/apiserver/pgorole

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
pgoadmin: Status, DfCluster, DeleteCluster, ShowCluster, CreateCluster, TestCluster, ShowBackup, DeleteBackup, CreateBackup, Label, Load, CreatePolicy, DeletePolicy, ShowPolicy, ApplyPolicy, ShowPVC, CreateUpgrade, ShowUpgrade, DeleteUpgrade, CreateUser, DeleteUser, User, Version, CreateIngest, ShowIngest, DeleteIngest, CreateFailover
1+
pgoadmin: ShowConfig, Status, DfCluster, DeleteCluster, ShowCluster, CreateCluster, TestCluster, ShowBackup, DeleteBackup, CreateBackup, Label, Load, CreatePolicy, DeletePolicy, ShowPolicy, ApplyPolicy, ShowPVC, CreateUpgrade, ShowUpgrade, DeleteUpgrade, CreateUser, DeleteUser, User, Version, CreateIngest, ShowIngest, DeleteIngest, CreateFailover
22

3-
pgoreader: Status, DfCluster, ShowCluster, TestCluster, ShowBackup, ShowPolicy, ShowPVC, ShowUpgrade, Version
3+
pgoreader: Status, ShowConfig, DfCluster, ShowCluster, TestCluster, ShowBackup, ShowPolicy, ShowPVC, ShowUpgrade, Version

examples/pgo-bash-completion

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ _pgo_backup()
262262
flags+=("--no-prompt")
263263
flags+=("-n")
264264
local_nonpersistent_flags+=("--no-prompt")
265+
flags+=("--pvc-name=")
266+
local_nonpersistent_flags+=("--pvc-name=")
265267
flags+=("--selector=")
266268
two_word_flags+=("-s")
267269
local_nonpersistent_flags+=("--selector=")
@@ -288,6 +290,8 @@ _pgo_create_cluster()
288290

289291
flags+=("--archive")
290292
local_nonpersistent_flags+=("--archive")
293+
flags+=("--autofail")
294+
local_nonpersistent_flags+=("--autofail")
291295
flags+=("--backup-path=")
292296
two_word_flags+=("-x")
293297
local_nonpersistent_flags+=("--backup-path=")
@@ -782,6 +786,28 @@ _pgo_show_cluster()
782786
noun_aliases=()
783787
}
784788

789+
_pgo_show_config()
790+
{
791+
last_command="pgo_show_config"
792+
commands=()
793+
794+
flags=()
795+
two_word_flags=()
796+
local_nonpersistent_flags=()
797+
flags_with_completion=()
798+
flags_completion=()
799+
800+
flags+=("--help")
801+
flags+=("-h")
802+
local_nonpersistent_flags+=("--help")
803+
flags+=("--apiserver-url=")
804+
flags+=("--debug")
805+
806+
must_have_one_flag=()
807+
must_have_one_noun=()
808+
noun_aliases=()
809+
}
810+
785811
_pgo_show_ingest()
786812
{
787813
last_command="pgo_show_ingest"
@@ -867,6 +893,7 @@ _pgo_show()
867893
commands=()
868894
commands+=("backup")
869895
commands+=("cluster")
896+
commands+=("config")
870897
commands+=("ingest")
871898
commands+=("policy")
872899
commands+=("pvc")
@@ -975,9 +1002,6 @@ _pgo_user()
9751002
flags+=("--db=")
9761003
two_word_flags+=("-b")
9771004
local_nonpersistent_flags+=("--db=")
978-
flags+=("--delete-user=")
979-
two_word_flags+=("-d")
980-
local_nonpersistent_flags+=("--delete-user=")
9811005
flags+=("--expired=")
9821006
two_word_flags+=("-e")
9831007
local_nonpersistent_flags+=("--expired=")
@@ -1012,9 +1036,6 @@ _pgo_version()
10121036
flags_with_completion=()
10131037
flags_completion=()
10141038

1015-
flags+=("--help")
1016-
flags+=("-h")
1017-
local_nonpersistent_flags+=("--help")
10181039
flags+=("--apiserver-url=")
10191040
flags+=("--debug")
10201041

hugo/content/getting-started/_index.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ running, use the following -
2727
pgo version
2828
....
2929

30+
=== pgo show config
31+
32+
To see what configuration you are running against within the Operator, use the following -
33+
....
34+
pgo show config
35+
....
36+
3037
=== pgo create cluster
3138

3239
To create a database, use the following -

pgo/cmd/config.go

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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

Comments
 (0)