sct 1.12.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 302ce929b08b3ac37dfa71a25b453e404f9e5319937db70f015590268d230dda
4
- data.tar.gz: f91fab564523f09cb65f31ae20a9a6cd7f688cbf0d4892de83a43ec13e33d4a1
3
+ metadata.gz: 8ebb6543f329c7409b5f0c07026826c4530ecc1862da704fd829cd3ee15d0f90
4
+ data.tar.gz: 57f8d6eff3e2eba63bf31c959793aad4bc3036c0195ece0bc43544a600ff8409
5
5
  SHA512:
6
- metadata.gz: 9842bced944a9663767c93065f30518e38fdd463bf5f5320f0787026fea5e1fb4f75aaccb6cd9a9bf3261431f037752cded942574d796a45530aa7c5feac3ed7
7
- data.tar.gz: 65b29d44f3f24c643da48bf489ed6377663e75b362a15f5ff14a3aaa0e726af60f221aee4069e770b3c62fbb53a598b7573cdd1c631f7ba723216c8724fafa2d
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 '--organization-name ORGANIZATION_NAME', 'The name of the organization.'
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
@@ -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
- "organization_name" => {
28
- "name" => "organization-name"
28
+ "create" => {
29
+ "domain" => "domain",
30
+ "organization_name" => "organization_name",
29
31
  },
30
- "modules" => {
31
- "name" => "modules",
32
- "type" => "array"
32
+ "copy" => {
33
+ "domain" => "export",
34
+ "target_environment" => "target",
33
35
  },
34
- "database_source" => {
35
- "name" => "database-source"
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
- begin
87
- volumes = get_volumes_string(options.dev)
88
- image = get_latest_image
89
- verbose = options.verbose
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
- options = options_to_string options
92
- to_run = "docker run -it --rm --network spend-cloud #{volumes} #{image} #{command} #{options}"
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
- if verbose
95
- puts "Running: #{to_run.green}"
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 root -sN -e 'SELECT `043` FROM `spend-cloud-config`.`00_settings` ORDER BY `043` ASC'"
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 get_latest_image
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 += '--overwrite '
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
- if self.options_mapping["#{k}"]
178
- mapping = self.options_mapping["#{k}"]
179
- k = mapping['name']
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
- client_id_result = `docker exec mysql-service mysql -u root -sN -e 'SELECT client_id FROM \`spend-cloud-config\`.\`00_settings\` WHERE \`043\` = "#{customer}"'`.strip
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
 
@@ -324,7 +297,7 @@ module Henk
324
297
  end
325
298
 
326
299
  def update_and_encrypt_customer_config customer, customer_database
327
- dsn = "mysql:host=mysql-service;user=root;dbname=#{customer_database};config=proactive-php;config-path=cfg/db;"
300
+ dsn = "mysql:host=mysql-service;user=admin;dbname=#{customer_database};config=proactive-php;config-path=cfg/db;"
328
301
 
329
302
  website_application = "https://#{customer}.dev.spend.cloud"
330
303
 
@@ -332,7 +305,7 @@ module Henk
332
305
 
333
306
  debug_email_address = "noreply@dev.spend.cloud"
334
307
 
335
- 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)}\""
336
309
 
337
310
  run_query query, database: "spend-cloud-config"
338
311
 
@@ -343,6 +316,10 @@ module Henk
343
316
  puts "Encrypted config values".green
344
317
  end
345
318
 
319
+ def escape_sql_string(value)
320
+ value.gsub('\\') { '\\\\' }.gsub('"') { '\\"' }
321
+ end
322
+
346
323
  def run_query query, database: nil, volume: nil
347
324
  command = "docker run --rm --network container:mysql-service"
348
325
 
@@ -1,3 +1,3 @@
1
1
  module Sct
2
- VERSION = "1.12.0"
2
+ VERSION = "1.13.0"
3
3
  end
@@ -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.12.0
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: 2025-11-04 00:00:00.000000000 Z
11
+ date: 2026-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored