File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ cloudsql_instance_exists () {
4
+ local project=" ${1} "
5
+ local instance=" ${2} "
6
+
7
+ if [[ -z " ${project} " ]] || [[ -z " ${instance} " ]]; then
8
+ echo
9
+ echo " Usage: cloudsql_instance_exists <project> <instance>"
10
+ echo
11
+ exit 1
12
+ fi
13
+
14
+ gcloud sql instances describe " ${instance} " --project=" ${project} " --no-user-output-enabled & > /dev/null
15
+ echo $?
16
+ }
17
+
18
+ cloudsql_user_exists () {
19
+ local project=" ${1} "
20
+ local instance=" ${2} "
21
+ local user=" ${3} "
22
+
23
+ if [[ -z " ${project} " ]] || [[ -z " ${instance} " ]] || [[ -z " ${user} " ]]; then
24
+ echo
25
+ echo " Usage: cloudsql_user_exists <project> <instance> <user>"
26
+ echo
27
+ exit 1
28
+ fi
29
+
30
+ gcloud sql users list --instance=" ${instance} " --project=" ${project} " --no-user-output-enabled | grep " ${user} " & > /dev/null
31
+ echo $?
32
+ }
33
+
34
+ cloudsql_create_superuser () {
35
+ local project=" ${1} "
36
+ local instance=" ${2} "
37
+ local username=" ${3} "
38
+ local hostspec=" ${4:-% } "
39
+
40
+ if [[ -z " ${project} " ]] || [[ -z " ${instance} " ]] || [[ -z " ${username} " ]]; then
41
+ echo
42
+ echo " Usage: cloudsql_create_user <project> <instance> <username> [hostspec]"
43
+ echo " Default hostspec = %"
44
+ echo
45
+ fi
46
+
47
+ gcloud sql users create " ${username} " --host=" ${hostspec} " --instance=" ${instance} " --project=" ${project} " --password=" $( generate_password ) " --no-user-output-enabled & > /dev/null
48
+
49
+ if [[ $? -eq 0 ]]; then
50
+ echo " User created successfully."
51
+ else
52
+ echo " User creation failed."
53
+ fi
54
+ }
You can’t perform that action at this time.
0 commit comments