seira 0.5.7 → 0.5.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/lib/helpers.rb +8 -2
- data/lib/seira/db/create.rb +27 -0
- data/lib/seira/db.rb +8 -1
- data/lib/seira/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00e2bc628518db4932766efa514535604cffe9983b4d5ebb949fa6c932388da9
|
4
|
+
data.tar.gz: affbd9c3db26d811993872d7cfabf71606c3e5cf3f2562a1513c55eec15525c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59e85f167e6d0c2930d90d440d21a5afe23041b09228371c2f4db6726b86da91fe0695e149837439681dc5bcf3a5d9d15071d9d3fa7606955e882bc8e50b1d62
|
7
|
+
data.tar.gz: df264bd54d20926b5fe00bc3d4059006e4f813ff1a3a318b567e45b413c7cf81688eac79e8f973d300892e55fb34f480b054872da4d1b3b1a54ed8c95ab55aaf
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.6.3
|
data/lib/helpers.rb
CHANGED
@@ -49,10 +49,16 @@ module Seira
|
|
49
49
|
def sql_ips(name, context:)
|
50
50
|
describe_command = "sql instances describe #{name}"
|
51
51
|
json = JSON.parse(Seira::Commands.gcloud(describe_command, context: context, format: :json))
|
52
|
-
private_ip = json['ipAddresses'].find { |address| address['type'] == 'PRIVATE' }
|
53
|
-
public_ip = json['ipAddresses'].find { |address| address['type'] == 'PRIMARY' }
|
52
|
+
private_ip = extract_ip_if_present(json['ipAddresses'].find { |address| address['type'] == 'PRIVATE' })
|
53
|
+
public_ip = extract_ip_if_present(json['ipAddresses'].find { |address| address['type'] == 'PRIMARY' })
|
54
54
|
{ private: private_ip, public: public_ip }
|
55
55
|
end
|
56
|
+
|
57
|
+
def extract_ip_if_present(ip_address)
|
58
|
+
return nil if ip_address.nil?
|
59
|
+
|
60
|
+
ip_address['ipAddress']
|
61
|
+
end
|
56
62
|
end
|
57
63
|
end
|
58
64
|
end
|
data/lib/seira/db/create.rb
CHANGED
@@ -7,6 +7,7 @@ module Seira
|
|
7
7
|
|
8
8
|
attr_reader :name, :version, :cpu, :memory, :storage, :replica_for, :make_highly_available
|
9
9
|
attr_reader :root_password, :proxyuser_password
|
10
|
+
attr_reader :prefix
|
10
11
|
|
11
12
|
def initialize(app:, action:, args:, context:)
|
12
13
|
@app = app
|
@@ -46,6 +47,31 @@ module Seira
|
|
46
47
|
puts "To make this database the primary, promote it using the CLI and update the DATABASE_URL."
|
47
48
|
end
|
48
49
|
|
50
|
+
def add(existing_instances)
|
51
|
+
if !args.empty? && (args[0].start_with? '--prefix=')
|
52
|
+
@prefix = args[0].split('=')[1]
|
53
|
+
end
|
54
|
+
|
55
|
+
if prefix.nil?
|
56
|
+
puts "missing --prefix= for add command. Must be the first argument."
|
57
|
+
exit(1)
|
58
|
+
end
|
59
|
+
|
60
|
+
# remove prefix from the head of the list since we don't want to pass it to gcloud
|
61
|
+
args.pop
|
62
|
+
|
63
|
+
@name = "#{app}-#{prefix}-#{Seira::Random.unique_name(existing_instances)}"
|
64
|
+
puts "Attempting to create #{name}"
|
65
|
+
run_create_command
|
66
|
+
|
67
|
+
update_root_password
|
68
|
+
create_proxy_user
|
69
|
+
|
70
|
+
secrets_name = "#{name}-credentials"
|
71
|
+
kubectl("create secret generic #{secrets_name} --from-literal=ROOT_PASSWORD=#{root_password} --from-literal=PROXYUSER_PASSWORD=#{proxyuser_password}", context: context)
|
72
|
+
puts "Credentials were saved in #{secrets_name}"
|
73
|
+
end
|
74
|
+
|
49
75
|
private
|
50
76
|
|
51
77
|
def run_create_command
|
@@ -82,6 +108,7 @@ module Seira
|
|
82
108
|
# Basic configs
|
83
109
|
create_command += " --database-version=#{version}"
|
84
110
|
create_command += " --network=default" # allow network to be configurable?
|
111
|
+
create_command += " --no-assign-ip" # don't assign public ip
|
85
112
|
|
86
113
|
# A read replica cannot have HA, inherits the cpu, mem and storage of its primary
|
87
114
|
if replica_for.nil?
|
data/lib/seira/db.rb
CHANGED
@@ -8,7 +8,7 @@ module Seira
|
|
8
8
|
class Db
|
9
9
|
include Seira::Commands
|
10
10
|
|
11
|
-
VALID_ACTIONS = %w[help create delete list restart connect ps kill analyze create-readonly-user psql table-sizes index-sizes vacuum unused-indexes unused-indices user-connections info alter-proxyuser-roles].freeze
|
11
|
+
VALID_ACTIONS = %w[help create delete list restart connect ps kill analyze create-readonly-user psql table-sizes index-sizes vacuum unused-indexes unused-indices user-connections info alter-proxyuser-roles add].freeze
|
12
12
|
SUMMARY = "Manage your Cloud SQL Postgres databases.".freeze
|
13
13
|
|
14
14
|
attr_reader :app, :action, :args, :context
|
@@ -26,6 +26,8 @@ module Seira
|
|
26
26
|
run_help
|
27
27
|
when 'create'
|
28
28
|
run_create
|
29
|
+
when 'add'
|
30
|
+
run_add
|
29
31
|
when 'delete'
|
30
32
|
run_delete
|
31
33
|
when 'list'
|
@@ -84,6 +86,7 @@ module Seira
|
|
84
86
|
analyze: Display database performance information
|
85
87
|
connect: Open a psql command prompt via gcloud connect. You will be shown the password needed before the prompt opens.
|
86
88
|
create: Create a new postgres instance in cloud sql. Supports creating replicas and other numerous flags.
|
89
|
+
add: Adds a new database to the given project. Requires --prefix=my-prefix to prefix the random name
|
87
90
|
create-readonly-user: Create a database user named by --username=<name> with only SELECT access privileges
|
88
91
|
delete: Delete a postgres instance from cloud sql. Use with caution, and remove all kubernetes configs first.
|
89
92
|
index-sizes: List sizes of all indexes in the database
|
@@ -105,6 +108,10 @@ module Seira
|
|
105
108
|
Seira::Db::Create.new(app: app, action: action, args: args, context: context).run(existing_instances)
|
106
109
|
end
|
107
110
|
|
111
|
+
def run_add
|
112
|
+
Seira::Db::Create.new(app: app, action: action, args: args, context: context).add(existing_instances)
|
113
|
+
end
|
114
|
+
|
108
115
|
def run_alter_proxyuser_roles
|
109
116
|
Seira::Db::AlterProxyuserRoles.new(app: app, action: action, args: args, context: context).run
|
110
117
|
end
|
data/lib/seira/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seira
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Ringwelski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -157,8 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
157
|
- !ruby/object:Gem::Version
|
158
158
|
version: '0'
|
159
159
|
requirements: []
|
160
|
-
|
161
|
-
rubygems_version: 2.7.6
|
160
|
+
rubygems_version: 3.0.3
|
162
161
|
signing_key:
|
163
162
|
specification_version: 4
|
164
163
|
summary: An opinionated library for building applications on Kubernetes.
|