|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright 2017 Crunchy Data Solutions, Inc. |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +# this is a script used to upgrade a database user credential from |
| 17 | +# the old pre-2.5 release format to the 2.5 post format |
| 18 | +# it will prompt the user along the way |
| 19 | + |
| 20 | +echo -n "enter the cluster name:" |
| 21 | +read CLUSTER |
| 22 | + |
| 23 | +echo "you entered " $CLUSTER |
| 24 | + |
| 25 | +CURRENT_POSTGRES_PASSWORD=`kubectl get secret $CLUSTER-root-secret -o jsonpath="{.data.password}"` |
| 26 | +echo "current decoded postgres password is..." |
| 27 | +POSTGRES_PASSWORD=`echo -n $CURRENT_POSTGRES_PASSWORD | base64 --decode` |
| 28 | +echo $POSTGRES_PASSWORD |
| 29 | + |
| 30 | +USERNAME=postgres |
| 31 | + |
| 32 | +kubectl create secret generic $CLUSTER-$USERNAME-secret \ |
| 33 | + --from-literal=username=$USERNAME \ |
| 34 | + --from-literal=password=$POSTGRES_PASSWORD |
| 35 | + |
| 36 | +kubectl label secret $CLUSTER-$USERNAME-secret pg-database=$CLUSTER |
| 37 | + |
| 38 | +# do the same for the primaryuser |
| 39 | + |
| 40 | +CURRENT_PASSWORD=`kubectl get secret $CLUSTER-primary-secret -o jsonpath="{.data.password}"` |
| 41 | +echo "current decoded primaryuser password is..." |
| 42 | +POSTGRES_PASSWORD=`echo -n $CURRENT_PASSWORD | base64 --decode` |
| 43 | +echo $POSTGRES_PASSWORD |
| 44 | + |
| 45 | +USERNAME=primaryuser |
| 46 | + |
| 47 | +kubectl create secret generic $CLUSTER-$USERNAME-secret \ |
| 48 | + --from-literal=username=$USERNAME \ |
| 49 | + --from-literal=password=$POSTGRES_PASSWORD |
| 50 | + |
| 51 | +kubectl label secret $CLUSTER-$USERNAME-secret pg-database=$CLUSTER |
| 52 | + |
| 53 | +# do the same for the testuser |
| 54 | + |
| 55 | +USERNAME=testuser |
| 56 | + |
| 57 | +CURRENT_PASSWORD=`kubectl get secret $CLUSTER-user-secret -o jsonpath="{.data.password}"` |
| 58 | +echo "current decoded testuser password is..." |
| 59 | +POSTGRES_PASSWORD=`echo -n $CURRENT_PASSWORD | base64 --decode` |
| 60 | +echo $POSTGRES_PASSWORD |
| 61 | + |
| 62 | +kubectl create secret generic $CLUSTER-$USERNAME-secret \ |
| 63 | + --from-literal=username=$USERNAME \ |
| 64 | + --from-literal=password=$POSTGRES_PASSWORD |
| 65 | + |
| 66 | +kubectl label secret $CLUSTER-$USERNAME-secret pg-database=$CLUSTER |
| 67 | + |
0 commit comments