sct 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8fad01fe00c948d248dae7390285021760ae28ad592411a3cbc18ffdef650cd8
4
- data.tar.gz: 1ba8d43b23ade6f4316767b8759c91bf98f2dac1327cb9903a2c8fa66b2f7a5e
3
+ metadata.gz: a7b7da8359137491424793ea19a9ae9d845bb11cb84a8df92b2c0135fe335948
4
+ data.tar.gz: 6ebe428263d46c7fd9d36f43c7503c6b640ed6d2ce30f5ef32204e12d50a771e
5
5
  SHA512:
6
- metadata.gz: 88c67f14fb87bc1ca891527e46b78b7552fb5021832347fdff73e4af0a8066e6b25cd17344b295ba2588af7265682a79248b245d6d2f0b1fe93fa5e9d5b4050c
7
- data.tar.gz: 392db33f0c88bdc2f36025b24a85614865bcf54d99f22970b8da874bf8abf1f956ec194ab5dc3d2659ee708fc5d34940d59689d6f2e0e9bf433139c3262dd5d0
6
+ metadata.gz: fca4bbe727e063bd35b3676a7a98c1c2349b05d69517b9c2104871358b17a1571077c3735dc4967157580a1e6d5a83a3515b6fe833b1b5c13a82189e06af1af0
7
+ data.tar.gz: f03408e6083a32af44de9f65784dee6d3b74deb9f72915babc3f3c8a50713eaf312697da77e50826391ab58f3990c7c81cbcb49cc881d3e231fa213fe50da61f
data/henk/lib/henk.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'sct_core'
2
+ require 'terminal-table'
3
+
4
+ require_relative 'henk/runner'
5
+ require_relative 'henk/module'
@@ -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,7 @@
1
+ module Henk
2
+
3
+ # import the helper functionality from SCT
4
+ Helpers = Sct::Helper
5
+ UI = Sct::UI
6
+
7
+ 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
data/sct/lib/sct/tools.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  module Sct
2
2
  TOOLS = [
3
3
  :sct,
4
- :cluster
4
+ :cluster,
5
+ :henk
5
6
  ]
6
7
 
7
8
  # a list of all the config files we currently expect
@@ -1,3 +1,3 @@
1
1
  module Sct
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
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.1.0
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-06-30 00:00:00.000000000 Z
11
+ date: 2021-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored
@@ -215,6 +215,10 @@ files:
215
215
  - cluster/lib/cluster/commands_generator.rb
216
216
  - cluster/lib/cluster/module.rb
217
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
218
222
  - sct/lib/.DS_Store
219
223
  - sct/lib/sct.rb
220
224
  - sct/lib/sct/.DS_Store
@@ -250,6 +254,7 @@ post_install_message:
250
254
  rdoc_options: []
251
255
  require_paths:
252
256
  - cluster/lib
257
+ - henk/lib
253
258
  - sct/lib
254
259
  - sct_core/lib
255
260
  required_ruby_version: !ruby/object:Gem::Requirement