Skip to content

Commit 4ec53df

Browse files
author
Jeff McCormick
committed
add psw command stub
1 parent 90a9cb1 commit 4ec53df

File tree

6 files changed

+200
-3
lines changed

6 files changed

+200
-3
lines changed

backupservice/backupservice.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package backupservice
2+
3+
import (
4+
"encoding/json"
5+
log "github.com/Sirupsen/logrus"
6+
"github.com/gorilla/mux"
7+
"net/http"
8+
)
9+
10+
type BackupDetail struct {
11+
Name string
12+
}
13+
type ShowBackupResponse struct {
14+
Items []BackupDetail
15+
}
16+
17+
type CreateBackupRequest struct {
18+
Name string
19+
}
20+
21+
// pgo backup mycluster
22+
// parameters secretfrom
23+
func CreateBackupHandler(w http.ResponseWriter, r *http.Request) {
24+
log.Infoln("backupservice.CreateBackupHandler called")
25+
var request CreateBackupRequest
26+
_ = json.NewDecoder(r.Body).Decode(&request)
27+
28+
log.Infoln("backupservice.CreateBackupHandler got request " + request.Name)
29+
}
30+
31+
// pgo backup mycluster
32+
// pgo delete backup mycluster
33+
// parameters showsecrets
34+
// parameters selector
35+
// parameters namespace
36+
// parameters postgresversion
37+
// returns a ShowClusterResponse
38+
func ShowBackupHandler(w http.ResponseWriter, r *http.Request) {
39+
log.Infoln("backupservice.ShowBackupHandler called")
40+
vars := mux.Vars(r)
41+
log.Infof(" vars are %v\n", vars)
42+
43+
switch r.Method {
44+
case "GET":
45+
log.Infoln("backupservice.ShowBackupHandler GET called")
46+
case "DELETE":
47+
log.Infoln("backupservice.ShowBackupHandler DELETE called")
48+
}
49+
50+
w.WriteHeader(http.StatusOK)
51+
w.Header().Set("Content-Type", "application/json")
52+
53+
resp := new(ShowBackupResponse)
54+
resp.Items = []BackupDetail{}
55+
c := BackupDetail{}
56+
c.Name = "somecluster"
57+
resp.Items = append(resp.Items, c)
58+
59+
json.NewEncoder(w).Encode(resp)
60+
}

client/cmd/apply.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ import (
2020
"github.com/spf13/cobra"
2121
)
2222

23-
var Selector string
24-
var DryRun bool
25-
2623
var applyCmd = &cobra.Command{
2724
Use: "apply",
2825
Short: "apply a Policy",

client/cmd/psw.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
Copyright 2017 Crunchy Data Solutions, Inc.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
16+
package cmd
17+
18+
import (
19+
"fmt"
20+
log "github.com/Sirupsen/logrus"
21+
//"github.com/crunchydata/postgres-operator/operator/util"
22+
//"github.com/crunchydata/postgres-operator/tpr"
23+
"github.com/spf13/cobra"
24+
//"github.com/spf13/viper"
25+
//"io/ioutil"
26+
//kerrors "k8s.io/apimachinery/pkg/api/errors"
27+
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
//"os/user"
29+
//"strings"
30+
)
31+
32+
var pswCmd = &cobra.Command{
33+
Use: "psw",
34+
Short: "manage passwords",
35+
Long: `PSW allows you to manage passwords across a set of clusters
36+
For example:
37+
38+
pgo psw --selector=name=mycluster --update
39+
pgo psw --dry-run --selector=someotherpolicy
40+
.`,
41+
Run: func(cmd *cobra.Command, args []string) {
42+
log.Debug("psw called")
43+
updatePasswords()
44+
},
45+
}
46+
47+
func init() {
48+
RootCmd.AddCommand(pswCmd)
49+
50+
pswCmd.Flags().StringVarP(&Selector, "selector", "s", "", "The selector to use for cluster filtering ")
51+
pswCmd.Flags().BoolVarP(&DryRun, "dry-run", "d", false, "--dry-run shows clusters and passwords that would be updated to but does not actually apply them")
52+
53+
}
54+
55+
func updatePasswords() {
56+
//build the selector based on the selector parameter
57+
//get the clusters list
58+
59+
//get filtered list of Deployments
60+
var sel string
61+
if Selector != "" {
62+
sel = Selector + ",pg-cluster,!replica"
63+
} else {
64+
sel = "pg-cluster,!replica"
65+
}
66+
log.Infoln("selector string=[" + sel + "]")
67+
68+
lo := meta_v1.ListOptions{LabelSelector: sel}
69+
deployments, err := Clientset.ExtensionsV1beta1().Deployments(Namespace).List(lo)
70+
if err != nil {
71+
log.Error("error getting list of deployments" + err.Error())
72+
return
73+
}
74+
75+
if DryRun {
76+
fmt.Println("dry run only....")
77+
}
78+
79+
for _, d := range deployments.Items {
80+
fmt.Println("deployment : " + d.ObjectMeta.Name)
81+
if !DryRun {
82+
}
83+
84+
}
85+
86+
}

client/cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ var KubeconfigPath string
3535
var Labelselector string
3636
var DebugFlag bool
3737
var Namespace string
38+
var Selector string
39+
var DryRun bool
3840

3941
// RootCmd represents the base command when called without any subcommands
4042
var RootCmd = &cobra.Command{

cloneservice/cloneservice.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package cloneservice
2+
3+
import (
4+
"encoding/json"
5+
log "github.com/Sirupsen/logrus"
6+
//"github.com/crunchydata/postgres-operator/tpr"
7+
//"github.com/gorilla/mux"
8+
"net/http"
9+
)
10+
11+
type CloneResults struct {
12+
Results []string
13+
}
14+
15+
type CreateCloneRequest struct {
16+
Name string
17+
}
18+
19+
// pgo create clone
20+
// parameters secretfrom
21+
func CreateCloneHandler(w http.ResponseWriter, r *http.Request) {
22+
log.Infoln("cloneservice.CreateCloneHandler called")
23+
var request CreateCloneRequest
24+
_ = json.NewDecoder(r.Body).Decode(&request)
25+
26+
log.Infoln("cloneservice.CreateCloneHandler got request " + request.Name)
27+
}

examples/operator/show-tpr.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash -x
2+
# Copyright 2016 Crunchy Data Solutions, Inc.
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
16+
17+
source $DIR/setup.sh
18+
19+
$CO_CMD get pgbackups
20+
$CO_CMD get pgclones
21+
$CO_CMD get pgclusters
22+
$CO_CMD get pgpolicies
23+
$CO_CMD get pgpolicylogs
24+
$CO_CMD get pgupgrades
25+

0 commit comments

Comments
 (0)