sct 1.0.7 → 1.1.1
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.rb +5 -0
- data/henk/lib/henk/commands_generator.rb +136 -0
- data/henk/lib/henk/module.rb +7 -0
- data/henk/lib/henk/runner.rb +175 -0
- data/sct/lib/sct/commands/databasepull.rb +50 -0
- data/sct/lib/sct/commands_generator.rb +13 -0
- data/sct/lib/sct/tools.rb +2 -1
- data/sct/lib/sct/version.rb +1 -1
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7b7da8359137491424793ea19a9ae9d845bb11cb84a8df92b2c0135fe335948
|
4
|
+
data.tar.gz: 6ebe428263d46c7fd9d36f43c7503c6b640ed6d2ce30f5ef32204e12d50a771e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fca4bbe727e063bd35b3676a7a98c1c2349b05d69517b9c2104871358b17a1571077c3735dc4967157580a1e6d5a83a3515b6fe833b1b5c13a82189e06af1af0
|
7
|
+
data.tar.gz: f03408e6083a32af44de9f65784dee6d3b74deb9f72915babc3f3c8a50713eaf312697da77e50826391ab58f3990c7c81cbcb49cc881d3e231fa213fe50da61f
|
data/henk/lib/henk.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'commander'
|
2
|
+
require_relative 'runner'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
module Henk
|
6
|
+
class CommandsGenerator
|
7
|
+
include Commander::Methods
|
8
|
+
|
9
|
+
def self.start
|
10
|
+
self.new.run
|
11
|
+
end
|
12
|
+
|
13
|
+
def run
|
14
|
+
add_commander_methods
|
15
|
+
|
16
|
+
Henk::Runner.new.verify_cluster_active
|
17
|
+
|
18
|
+
program :name, 'henk'
|
19
|
+
program :version, Sct::VERSION
|
20
|
+
program :description, 'CLI for \'henk\' - Interact with Henk 3.0 to be able to create/copy/delete customers'
|
21
|
+
|
22
|
+
$dev = false
|
23
|
+
$verbose = false
|
24
|
+
global_option('--dev') { $dev = true }
|
25
|
+
global_option('--verbose') { $verbose = true }
|
26
|
+
|
27
|
+
command :create do |c|
|
28
|
+
c.syntax = 'sct henk create'
|
29
|
+
c.description = 'Create a client in your local development.'
|
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, ...'
|
33
|
+
|
34
|
+
c.action do |args, options|
|
35
|
+
c.validate options
|
36
|
+
|
37
|
+
options.dev = $dev
|
38
|
+
options.verbose = $verbose
|
39
|
+
Henk::Runner.new.henk "create", options
|
40
|
+
Henk::Runner.new.encrypt_config_data options.domain
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
command :copy do |c|
|
45
|
+
c.syntax = 'sct henk copy'
|
46
|
+
c.description = 'Copy a client from another environment to your local environment'
|
47
|
+
c.required_option '--domain DOMAIN', 'The domain to copy.'
|
48
|
+
c.option '--source-environment SOURCE_ENVIRONMENT', 'The name of the source environment (currently only local allowed).'
|
49
|
+
c.option '--target-domain DOMAIN', 'The name of the domain on the local environment. When making a local copy it cannot be the same name'
|
50
|
+
c.option '--overwrite', 'Set this flag if you want to overwrite an existing target-domain.'
|
51
|
+
c.option '--copy-data', 'Set this flag if you want to copy the data of the source client'
|
52
|
+
|
53
|
+
# Specify command options here
|
54
|
+
c.action do |args, options|
|
55
|
+
c.validate options
|
56
|
+
|
57
|
+
unless options.source_environment
|
58
|
+
options.source_environment = "local"
|
59
|
+
end
|
60
|
+
|
61
|
+
# Temporary provision until we can copy environments from Accept
|
62
|
+
if options.source_environment != "local"
|
63
|
+
raise ArgumentError.new("It's currently not possible to copy an cloud environment.".yellow)
|
64
|
+
end
|
65
|
+
|
66
|
+
options.target_environment = "local"
|
67
|
+
|
68
|
+
unless options.target_domain
|
69
|
+
options.target_domain = options.domain
|
70
|
+
end
|
71
|
+
|
72
|
+
if options.source_environment == options.target_environment \
|
73
|
+
and options.domain == options.target_domain
|
74
|
+
raise ArgumentError.new("The source and target domains cannot be the same.")
|
75
|
+
end
|
76
|
+
|
77
|
+
options.dev = $dev
|
78
|
+
options.verbose = $verbose
|
79
|
+
Henk::Runner.new.henk "copy", options
|
80
|
+
Henk::Runner.new.encrypt_config_data options.target_domain
|
81
|
+
Henk::Runner.new.synchronize_employees options.target_domain
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
command :remove do |c|
|
86
|
+
c.syntax = 'sct henk remove'
|
87
|
+
c.description = 'Remove a client from your local environment.'
|
88
|
+
c.required_option '--domain DOMAIN', 'The domain to remove.'
|
89
|
+
c.option '--user-email EMAIL', 'The email address of the user removing the customer'
|
90
|
+
|
91
|
+
c.action do |args, options|
|
92
|
+
c.validate options
|
93
|
+
options.dev = $dev
|
94
|
+
options.verbose = $verbose
|
95
|
+
Henk::Runner.new.henk 'remove', options
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
command :"list-clients" do |c|
|
100
|
+
c.syntax = 'sct henk list-clients'
|
101
|
+
c.description = 'List all clients that are available on the dev environment'
|
102
|
+
|
103
|
+
c.action do |args, options|
|
104
|
+
Henk::Runner.new.list_clients
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
run!
|
109
|
+
end
|
110
|
+
|
111
|
+
# Ruben's suggestion but still need some workaround
|
112
|
+
def add_commander_methods
|
113
|
+
Commander::Command.class_eval {
|
114
|
+
attr_accessor :required
|
115
|
+
|
116
|
+
def required_option(*arg, &block)
|
117
|
+
unless self.required
|
118
|
+
@required = []
|
119
|
+
end
|
120
|
+
|
121
|
+
option = arg.select{|item| item.start_with?('--')}.map{|a| a.gsub(/\-\-([^\s]*)(.*)/, '\1')}.shift
|
122
|
+
self.required << option.to_s.tr('-', '_')
|
123
|
+
self.option(*arg)
|
124
|
+
end
|
125
|
+
|
126
|
+
def validate options
|
127
|
+
self.required.each do |option|
|
128
|
+
if options.__hash__[:"#{option}"].nil? || options.__hash__[:"#{option}"] == ''
|
129
|
+
raise ArgumentError.new("The --#{option} argument is a required argument")
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
}
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
require 'pp'
|
2
|
+
|
3
|
+
module Henk
|
4
|
+
class Runner
|
5
|
+
attr_accessor :options_mapping
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@options_mapping = {
|
9
|
+
"organization_name" => {
|
10
|
+
"name" => "organization-name"
|
11
|
+
},
|
12
|
+
"modules" => {
|
13
|
+
"name" => "modules",
|
14
|
+
"type" => "array"
|
15
|
+
},
|
16
|
+
"database_source" => {
|
17
|
+
"name" => "database-source"
|
18
|
+
},
|
19
|
+
"target_domain" => {
|
20
|
+
"name" => "target-domain"
|
21
|
+
},
|
22
|
+
"copy_data" => {
|
23
|
+
"name" => "copy-data"
|
24
|
+
},
|
25
|
+
"source_environment" => {
|
26
|
+
"name" => "source-environment"
|
27
|
+
},
|
28
|
+
"target_environment" => {
|
29
|
+
"name" => "target-environment"
|
30
|
+
},
|
31
|
+
"user_email" => {
|
32
|
+
"name" => "user-email"
|
33
|
+
}
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def run command
|
38
|
+
if !system command
|
39
|
+
raise command.red
|
40
|
+
end
|
41
|
+
|
42
|
+
rescue Interrupt
|
43
|
+
end
|
44
|
+
|
45
|
+
def verify_cluster_active
|
46
|
+
required_containers = [
|
47
|
+
"proactive-config",
|
48
|
+
"proactive-frame",
|
49
|
+
"mysql-service"
|
50
|
+
]
|
51
|
+
|
52
|
+
if !system "docker network inspect spend-cloud > /dev/null"
|
53
|
+
puts "Error: ".red + "The local spend-cloud cluster doesn't seem to be running."
|
54
|
+
exit(1)
|
55
|
+
end
|
56
|
+
|
57
|
+
connected_to_network = `docker network inspect spend-cloud | jq '.[0] | .Containers | map(select((.Name | test("^#{required_containers.join('|^')}")))) | length'`
|
58
|
+
|
59
|
+
if connected_to_network.to_s.strip! != "3"
|
60
|
+
puts "Error: ".red + "Not all required services are running or connected to the cluster (#{connected_to_network}/3)"
|
61
|
+
exit(1)
|
62
|
+
end
|
63
|
+
|
64
|
+
return true
|
65
|
+
end
|
66
|
+
|
67
|
+
def henk command, options = {}
|
68
|
+
begin
|
69
|
+
volumes = get_volumes_string(options.dev)
|
70
|
+
image = get_latest_image
|
71
|
+
verbose = options.verbose
|
72
|
+
|
73
|
+
options = options_to_string options
|
74
|
+
to_run = "docker run -it --rm --network spend-cloud #{volumes} #{image} #{command} #{options}"
|
75
|
+
|
76
|
+
if verbose
|
77
|
+
puts "Running: #{to_run.green}"
|
78
|
+
end
|
79
|
+
|
80
|
+
self.run to_run
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def list_clients
|
85
|
+
self.run "docker exec -it mysql-service mysql -u root -sN -e 'SELECT `043` FROM `spend-cloud-config`.`00_settings` ORDER BY `043` ASC'"
|
86
|
+
end
|
87
|
+
|
88
|
+
def encrypt_config_data domain
|
89
|
+
puts "Manually encrypting config data for #{domain}".green
|
90
|
+
php_command = "php /var/www/scripts/encryptConfigData.php -c='#{domain}' --execute"
|
91
|
+
command = 'docker exec -it proactive-config bash -c "#{php_command}"'
|
92
|
+
self.run command
|
93
|
+
end
|
94
|
+
|
95
|
+
def synchronize_employees domain
|
96
|
+
puts "Manually synchronizing employees with shared storage for #{domain}".green
|
97
|
+
php_command = "php /var/www/scripts/syncEmployees.php --client='#{domain}'"
|
98
|
+
command = 'docker exec -it proactive-frame bash -c "#{php_command}"'
|
99
|
+
self.run command
|
100
|
+
end
|
101
|
+
|
102
|
+
def get_latest_image
|
103
|
+
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'`
|
104
|
+
return "eu.gcr.io/dev-pasc-vcdm/henk-app:#{latest_version.strip}"
|
105
|
+
end
|
106
|
+
|
107
|
+
def get_volumes_string dev = false
|
108
|
+
volumes = {
|
109
|
+
"spend-cloud_shared-storage" => "/data"
|
110
|
+
}
|
111
|
+
|
112
|
+
if dev
|
113
|
+
repoPath = Sct::Helper.homePath + "/development/henk"
|
114
|
+
|
115
|
+
if not Dir.exists?(repoPath)
|
116
|
+
puts "Warning: ".yellow + "To run in development mode you need a checkout for the Henk repository. Continuing in normal mode."
|
117
|
+
else
|
118
|
+
dev_volumes = {
|
119
|
+
repoPath + "/modules" => "/var/scripts/modules",
|
120
|
+
repoPath + "/client.py" => "/var/scripts/client.py",
|
121
|
+
repoPath + "/environment_mapping.json" => "/var/scripts/environment_mapping.json",
|
122
|
+
repoPath + "/logging-config.json" => "/var/scripts/logging-config.json",
|
123
|
+
repoPath + "/schemas" => "/var/scripts/schemas",
|
124
|
+
repoPath + "/resources" => "/var/local"
|
125
|
+
}
|
126
|
+
|
127
|
+
volumes = volumes.merge(dev_volumes)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
return volumes.map{|k,v| "-v #{k}:#{v}"}.join(' ')
|
132
|
+
end
|
133
|
+
|
134
|
+
def options_to_string options = {}
|
135
|
+
options_str = ''
|
136
|
+
|
137
|
+
if options.verbose
|
138
|
+
options_str += '--verbose '
|
139
|
+
end
|
140
|
+
|
141
|
+
if options.overwrite
|
142
|
+
options_str += '--overwrite '
|
143
|
+
end
|
144
|
+
|
145
|
+
if options.copy_data
|
146
|
+
options_str += '--copy-data '
|
147
|
+
end
|
148
|
+
|
149
|
+
options = options.__hash__
|
150
|
+
|
151
|
+
options.delete(:dev)
|
152
|
+
options.delete(:verbose)
|
153
|
+
options.delete(:overwrite)
|
154
|
+
options.delete(:copy_data)
|
155
|
+
|
156
|
+
parsed_options = []
|
157
|
+
|
158
|
+
options.each do |k,v|
|
159
|
+
if self.options_mapping["#{k}"]
|
160
|
+
mapping = self.options_mapping["#{k}"]
|
161
|
+
k = mapping['name']
|
162
|
+
|
163
|
+
if mapping['type'] == "array"
|
164
|
+
v = v.split(',').join(' ')
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
parsed_options << "--#{k} #{v}"
|
169
|
+
end
|
170
|
+
|
171
|
+
options_str += parsed_options.join(' ')
|
172
|
+
return options_str
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Sct
|
2
|
+
class DatabasePullCommand
|
3
|
+
def error message
|
4
|
+
UI.error message
|
5
|
+
exit 1
|
6
|
+
end
|
7
|
+
|
8
|
+
def execute args, options
|
9
|
+
branch = ENV['CI_BRANCH']
|
10
|
+
if not branch or branch == ""
|
11
|
+
branch = 'master'
|
12
|
+
end
|
13
|
+
|
14
|
+
# We need to set this locally, so that we don't save this at the repository
|
15
|
+
pipeline_endpoint = ENV['CI_MERGE_REQUEST_PIPELINE']
|
16
|
+
if not pipeline_endpoint
|
17
|
+
error "Pipeline endpoint not set"
|
18
|
+
end
|
19
|
+
|
20
|
+
# We need to set this locally, so that we don't save this at the repository
|
21
|
+
private_token = ENV['CI_PRIVATE_TOKEN']
|
22
|
+
if not private_token
|
23
|
+
error "Private token not set"
|
24
|
+
end
|
25
|
+
|
26
|
+
if options.all
|
27
|
+
UI.important("Requesting to pull database changes for proactive frame and proactive config")
|
28
|
+
process_request = `curl -X POST -F token=#{private_token} -F ref=master -F variables[DB_PULL_FRAME]=true -F variables[DB_PULL_CONFIG]=true -F variables[REMOTE_BRANCH_NAME]=#{branch} #{pipeline_endpoint}`
|
29
|
+
else
|
30
|
+
db_pull_frame = ""
|
31
|
+
if options.proactive_frame
|
32
|
+
UI.important("Requesting to pull database for proactive frame")
|
33
|
+
db_pull_frame = "-F variables[DB_PULL_FRAME]=true"
|
34
|
+
end
|
35
|
+
|
36
|
+
db_pull_config = ""
|
37
|
+
if options.proactive_config
|
38
|
+
UI.important("Requesting to pull database for proactive config")
|
39
|
+
db_pull_config = "-F variables[DB_PULL_CONFIG]=true"
|
40
|
+
end
|
41
|
+
|
42
|
+
if db_pull_frame != "" or db_pull_config != ""
|
43
|
+
process_request = `curl -X POST -F token=#{private_token} -F ref=master #{db_pull_frame} #{db_pull_config} -F variables[REMOTE_BRANCH_NAME]=#{branch} #{pipeline_endpoint}`
|
44
|
+
else
|
45
|
+
error "Missing options. Use --help to see the available options"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -54,6 +54,19 @@ module Sct
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
command :'database-pull' do |c|
|
58
|
+
c.syntax = 'sct database pull'
|
59
|
+
c.description = 'pull database changes for proactive frame and proactive config'
|
60
|
+
c.option '--all', 'pull the database changes for all repositories'
|
61
|
+
c.option '--proactive-frame', 'pull the database changes from proactive-frame'
|
62
|
+
c.option '--proactive-config', 'pull the database changes from proactive-config'
|
63
|
+
|
64
|
+
c.action do |args, options|
|
65
|
+
UI.important("Trying to pull database")
|
66
|
+
Sct::DatabasePullCommand.new.execute args, options
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
57
70
|
run!
|
58
71
|
end
|
59
72
|
end
|
data/sct/lib/sct/tools.rb
CHANGED
data/sct/lib/sct/version.rb
CHANGED
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.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reshad Farid
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colored
|
@@ -100,6 +100,20 @@ dependencies:
|
|
100
100
|
- - "<"
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: 3.0.0
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: gitlab
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 4.17.0
|
110
|
+
type: :runtime
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 4.17.0
|
103
117
|
- !ruby/object:Gem::Dependency
|
104
118
|
name: tty-screen
|
105
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -201,11 +215,16 @@ files:
|
|
201
215
|
- cluster/lib/cluster/commands_generator.rb
|
202
216
|
- cluster/lib/cluster/module.rb
|
203
217
|
- cluster/lib/cluster/runner.rb
|
218
|
+
- henk/lib/henk.rb
|
219
|
+
- henk/lib/henk/commands_generator.rb
|
220
|
+
- henk/lib/henk/module.rb
|
221
|
+
- henk/lib/henk/runner.rb
|
204
222
|
- sct/lib/.DS_Store
|
205
223
|
- sct/lib/sct.rb
|
206
224
|
- sct/lib/sct/.DS_Store
|
207
225
|
- sct/lib/sct/cli_tools_distributor.rb
|
208
226
|
- sct/lib/sct/command.rb
|
227
|
+
- sct/lib/sct/commands/databasepull.rb
|
209
228
|
- sct/lib/sct/commands/dev.rb
|
210
229
|
- sct/lib/sct/commands/mysqlproxy.rb
|
211
230
|
- sct/lib/sct/commands/shell.rb
|
@@ -235,6 +254,7 @@ post_install_message:
|
|
235
254
|
rdoc_options: []
|
236
255
|
require_paths:
|
237
256
|
- cluster/lib
|
257
|
+
- henk/lib
|
238
258
|
- sct/lib
|
239
259
|
- sct_core/lib
|
240
260
|
required_ruby_version: !ruby/object:Gem::Requirement
|