sct 1.11.3 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/henk/lib/henk/commands_generator.rb +1 -2
- data/henk/lib/henk/runner.rb +64 -84
- data/sct/lib/sct/version.rb +1 -1
- data/sct_core/lib/sct_core/command_executor.rb +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8ebb6543f329c7409b5f0c07026826c4530ecc1862da704fd829cd3ee15d0f90
|
|
4
|
+
data.tar.gz: 57f8d6eff3e2eba63bf31c959793aad4bc3036c0195ece0bc43544a600ff8409
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ed0317fb42edb91e0955e2d08f187bb9c31ea8e841e644dd9de4f742d6773e11cc1c14e5bcbaf680d03df9282caf8cde6a7df5923d902e563fbe18767cdd6249
|
|
7
|
+
data.tar.gz: 2f0ee40fdc170606d75f9caa3969cb971999c6890041131fd9c09368c4bcd5728a6de92b7917460c825206b87920c790cfbc5b5c3076ea64ce9adfee34df1a7c
|
|
@@ -28,8 +28,7 @@ module Henk
|
|
|
28
28
|
c.syntax = 'sct henk create'
|
|
29
29
|
c.description = 'Create a client in your local development.'
|
|
30
30
|
c.required_option '--domain DOMAIN', 'The domain name of the new customer.'
|
|
31
|
-
c.required_option '--
|
|
32
|
-
c.required_option '--modules MODULES', 'Allowed modules. ex: 01, 02, 03, ...'
|
|
31
|
+
c.required_option '--organization_name ORGANIZATION_NAME', 'The name of the organization.'
|
|
33
32
|
|
|
34
33
|
c.action do |args, options|
|
|
35
34
|
c.validate options
|
data/henk/lib/henk/runner.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'pp'
|
|
2
|
+
require 'tmpdir'
|
|
2
3
|
|
|
3
4
|
module Henk
|
|
4
5
|
class Runner
|
|
@@ -24,30 +25,17 @@ module Henk
|
|
|
24
25
|
|
|
25
26
|
def initialize
|
|
26
27
|
@options_mapping = {
|
|
27
|
-
"
|
|
28
|
-
"
|
|
28
|
+
"create" => {
|
|
29
|
+
"domain" => "domain",
|
|
30
|
+
"organization_name" => "organization_name",
|
|
29
31
|
},
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
32
|
+
"copy" => {
|
|
33
|
+
"domain" => "export",
|
|
34
|
+
"target_environment" => "target",
|
|
33
35
|
},
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
"target_domain" => {
|
|
38
|
-
"name" => "target-domain"
|
|
39
|
-
},
|
|
40
|
-
"copy_data" => {
|
|
41
|
-
"name" => "copy-data"
|
|
42
|
-
},
|
|
43
|
-
"source_environment" => {
|
|
44
|
-
"name" => "source-environment"
|
|
45
|
-
},
|
|
46
|
-
"target_environment" => {
|
|
47
|
-
"name" => "target-environment"
|
|
48
|
-
},
|
|
49
|
-
"user_email" => {
|
|
50
|
-
"name" => "user-email"
|
|
36
|
+
"remove" => {
|
|
37
|
+
"domain" => "domain",
|
|
38
|
+
"user_email" => "creator",
|
|
51
39
|
}
|
|
52
40
|
}
|
|
53
41
|
end
|
|
@@ -83,24 +71,42 @@ module Henk
|
|
|
83
71
|
end
|
|
84
72
|
|
|
85
73
|
def henk command, options = {}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
74
|
+
volumes = get_volumes_string
|
|
75
|
+
image = "eu.gcr.io/dev-pasc-vcdm/henk-core-tasks:latest"
|
|
76
|
+
verbose = options.verbose
|
|
77
|
+
env_file = create_env_file
|
|
90
78
|
|
|
91
|
-
|
|
92
|
-
|
|
79
|
+
options = options_to_string command, options
|
|
80
|
+
to_run = "docker run -it --rm --network spend-cloud -w /app -v #{env_file}:/app/.env:ro #{volumes} #{image} ./henk-#{command} #{options}"
|
|
93
81
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
self.run to_run
|
|
82
|
+
if verbose
|
|
83
|
+
puts "Running: #{to_run.green}"
|
|
99
84
|
end
|
|
85
|
+
|
|
86
|
+
self.run to_run
|
|
87
|
+
ensure
|
|
88
|
+
File.delete(env_file) if env_file && File.exist?(env_file)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def create_env_file
|
|
92
|
+
content = <<~ENV
|
|
93
|
+
APP_ENV=local
|
|
94
|
+
DB_SERVICES_HOST=mysql-service
|
|
95
|
+
DB_PORT=3306
|
|
96
|
+
DB_DATABASE=spend-cloud-config
|
|
97
|
+
DB_USERNAME=admin
|
|
98
|
+
DB_PASSWORD=
|
|
99
|
+
DB_GRANTS_USERNAME=admin
|
|
100
|
+
DB_GRANTS_PASSWORD=
|
|
101
|
+
APPLICATION_TOKEN=applicationtoken
|
|
102
|
+
ENV
|
|
103
|
+
path = File.join(Dir.tmpdir, "henk-#{Time.now.to_i}-#{$$}.env")
|
|
104
|
+
File.write(path, content)
|
|
105
|
+
path
|
|
100
106
|
end
|
|
101
107
|
|
|
102
108
|
def list_clients
|
|
103
|
-
self.run "docker exec -it mysql-service mysql -u
|
|
109
|
+
self.run "docker exec -it mysql-service mysql -u admin -sN -e 'SELECT `043` FROM `spend-cloud-config`.`00_settings` ORDER BY `043` ASC'"
|
|
104
110
|
end
|
|
105
111
|
|
|
106
112
|
def encrypt_config_data domain
|
|
@@ -117,73 +123,39 @@ module Henk
|
|
|
117
123
|
self.run command
|
|
118
124
|
end
|
|
119
125
|
|
|
120
|
-
def
|
|
121
|
-
latest_version = `gcloud container images list-tags eu.gcr.io/dev-pasc-vcdm/henk-app --limit 1 --format=\"json\" | jq -r '[.[0].tags | sort_by(length)[] | select(match(\"^[0-9]+$\"))] | first'`
|
|
122
|
-
return "eu.gcr.io/dev-pasc-vcdm/henk-app:#{latest_version.strip}"
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def get_volumes_string dev = false
|
|
126
|
+
def get_volumes_string
|
|
126
127
|
volumes = {
|
|
127
128
|
"spend-cloud_shared-storage" => "/data"
|
|
128
129
|
}
|
|
129
130
|
|
|
130
|
-
if dev
|
|
131
|
-
repoPath = Sct::Helper.homePath + "/development/henk"
|
|
132
|
-
|
|
133
|
-
if not Dir.exists?(repoPath)
|
|
134
|
-
puts "Warning: ".yellow + "To run in development mode you need a checkout for the Henk repository. Continuing in normal mode."
|
|
135
|
-
else
|
|
136
|
-
dev_volumes = {
|
|
137
|
-
repoPath + "/modules" => "/var/scripts/modules",
|
|
138
|
-
repoPath + "/client.py" => "/var/scripts/client.py",
|
|
139
|
-
repoPath + "/environment_mapping.json" => "/var/scripts/environment_mapping.json",
|
|
140
|
-
repoPath + "/logging-config.json" => "/var/scripts/logging-config.json",
|
|
141
|
-
repoPath + "/schemas" => "/var/scripts/schemas",
|
|
142
|
-
repoPath + "/resources" => "/var/local"
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
volumes = volumes.merge(dev_volumes)
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
|
|
149
131
|
return volumes.map{|k,v| "-v #{k}:#{v}"}.join(' ')
|
|
150
132
|
end
|
|
151
133
|
|
|
152
|
-
def options_to_string options = {}
|
|
134
|
+
def options_to_string command, options = {}
|
|
153
135
|
options_str = ''
|
|
154
136
|
|
|
155
|
-
if options.verbose
|
|
156
|
-
options_str += '--verbose '
|
|
157
|
-
end
|
|
158
|
-
|
|
159
137
|
if options.overwrite
|
|
160
|
-
options_str += '
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
if options.copy_data
|
|
164
|
-
options_str += '--copy-data '
|
|
138
|
+
options_str += '-overwrite '
|
|
165
139
|
end
|
|
166
140
|
|
|
167
141
|
options = options.__hash__
|
|
168
142
|
|
|
169
|
-
options.delete(:dev)
|
|
170
143
|
options.delete(:verbose)
|
|
171
144
|
options.delete(:overwrite)
|
|
172
145
|
options.delete(:copy_data)
|
|
146
|
+
options.delete(:source_environment)
|
|
147
|
+
options.delete(:database_source)
|
|
148
|
+
options.delete(:target_domain)
|
|
149
|
+
|
|
150
|
+
command_mapping = self.options_mapping[command] || {}
|
|
173
151
|
|
|
174
152
|
parsed_options = []
|
|
175
153
|
|
|
176
154
|
options.each do |k,v|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if mapping['type'] == "array"
|
|
182
|
-
v = v.split(',').join(' ')
|
|
183
|
-
end
|
|
155
|
+
key = k.to_s
|
|
156
|
+
if command_mapping[key]
|
|
157
|
+
parsed_options << "-#{command_mapping[key]} #{v}"
|
|
184
158
|
end
|
|
185
|
-
|
|
186
|
-
parsed_options << "--#{k} #{v}"
|
|
187
159
|
end
|
|
188
160
|
|
|
189
161
|
options_str += parsed_options.join(' ')
|
|
@@ -255,7 +227,8 @@ module Henk
|
|
|
255
227
|
|
|
256
228
|
def remove_customer_from_config_database customer
|
|
257
229
|
puts "Finding client_id for #{customer}...".blue
|
|
258
|
-
|
|
230
|
+
escaped = escape_sql_string(customer)
|
|
231
|
+
client_id_result = `docker exec mysql-service mysql -u admin -sN -e 'SELECT client_id FROM \`spend-cloud-config\`.\`00_settings\` WHERE \`043\` = "#{escaped}"'`.strip
|
|
259
232
|
|
|
260
233
|
if !client_id_result.empty?
|
|
261
234
|
client_id = client_id_result.to_i
|
|
@@ -270,7 +243,7 @@ module Henk
|
|
|
270
243
|
puts "Removed all config database entries".green
|
|
271
244
|
else
|
|
272
245
|
puts "Warning: ".yellow + "Could not find client_id in config database, attempting cleanup with domain name only"
|
|
273
|
-
run_query "DELETE FROM `00_settings` WHERE `043` = \"#{customer}\"", database: "spend-cloud-config"
|
|
246
|
+
run_query "DELETE FROM `00_settings` WHERE `043` = \"#{escape_sql_string(customer)}\"", database: "spend-cloud-config"
|
|
274
247
|
end
|
|
275
248
|
end
|
|
276
249
|
|
|
@@ -288,8 +261,11 @@ module Henk
|
|
|
288
261
|
end
|
|
289
262
|
|
|
290
263
|
def copy_db_encryption_key customer, dir
|
|
264
|
+
uid = Process.uid
|
|
265
|
+
gid = Process.gid
|
|
266
|
+
|
|
291
267
|
run "docker exec proactive-config mkdir -p /data/#{customer}"
|
|
292
|
-
run "docker exec proactive-config chown
|
|
268
|
+
run "docker exec proactive-config chown #{uid}:#{gid} /data/#{customer}"
|
|
293
269
|
run "docker cp #{dir}/db_encryption.key proactive-config:/data/#{customer}/"
|
|
294
270
|
|
|
295
271
|
puts "Copied db_encryption.key to proactive-config:/data/#{customer}/".green
|
|
@@ -321,7 +297,7 @@ module Henk
|
|
|
321
297
|
end
|
|
322
298
|
|
|
323
299
|
def update_and_encrypt_customer_config customer, customer_database
|
|
324
|
-
dsn = "mysql:host=mysql-service;user=
|
|
300
|
+
dsn = "mysql:host=mysql-service;user=admin;dbname=#{customer_database};config=proactive-php;config-path=cfg/db;"
|
|
325
301
|
|
|
326
302
|
website_application = "https://#{customer}.dev.spend.cloud"
|
|
327
303
|
|
|
@@ -329,7 +305,7 @@ module Henk
|
|
|
329
305
|
|
|
330
306
|
debug_email_address = "noreply@dev.spend.cloud"
|
|
331
307
|
|
|
332
|
-
query = "UPDATE `00_settings` SET `045` = \"#{dsn}\", `029` = \"#{website_application}\", `002` = \"#{email_administrator}\", `031` = \"#{debug_email_address}\" WHERE `043` = \"#{customer}\""
|
|
308
|
+
query = "UPDATE `00_settings` SET `045` = \"#{escape_sql_string(dsn)}\", `029` = \"#{escape_sql_string(website_application)}\", `002` = \"#{escape_sql_string(email_administrator)}\", `031` = \"#{escape_sql_string(debug_email_address)}\" WHERE `043` = \"#{escape_sql_string(customer)}\""
|
|
333
309
|
|
|
334
310
|
run_query query, database: "spend-cloud-config"
|
|
335
311
|
|
|
@@ -340,6 +316,10 @@ module Henk
|
|
|
340
316
|
puts "Encrypted config values".green
|
|
341
317
|
end
|
|
342
318
|
|
|
319
|
+
def escape_sql_string(value)
|
|
320
|
+
value.gsub('\\') { '\\\\' }.gsub('"') { '\\"' }
|
|
321
|
+
end
|
|
322
|
+
|
|
343
323
|
def run_query query, database: nil, volume: nil
|
|
344
324
|
command = "docker run --rm --network container:mysql-service"
|
|
345
325
|
|
data/sct/lib/sct/version.rb
CHANGED
|
@@ -12,6 +12,9 @@ module SctCore
|
|
|
12
12
|
#
|
|
13
13
|
# Derived from https://stackoverflow.com/a/5471032/3005
|
|
14
14
|
def which(cmd)
|
|
15
|
+
raise ArgumentError, "Invalid command name: #{cmd}" if cmd.nil? || cmd.empty?
|
|
16
|
+
raise ArgumentError, "Invalid command name: #{cmd}" if cmd.include?('/') || cmd.include?('\\') || cmd.include?('..')
|
|
17
|
+
|
|
15
18
|
# PATHEXT contains the list of file extensions that Windows considers executable, semicolon separated.
|
|
16
19
|
# e.g. ".COM;.EXE;.BAT;.CMD"
|
|
17
20
|
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : []
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sct
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.13.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Reshad Farid
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-05-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: colored
|