razorrisk-cassini-utilities-cassis 0.7.6

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.
@@ -0,0 +1,236 @@
1
+ # encoding: UTF-8
2
+
3
+ # ######################################################################## #
4
+ # File: razor_risk/cassini/utilities/cassis/zip_utils.rb
5
+ #
6
+ # Purpose: Zip utility functions
7
+ #
8
+ # Created: 11th July 2018
9
+ # Updated: 25th January 2019
10
+ #
11
+ # Author: Matthew Wilson
12
+ #
13
+ # Copyright (c) 2018, Razor Risk Technologies Pty Ltd
14
+ # All rights reserved.
15
+ #
16
+ # ######################################################################## #
17
+
18
+ require 'razor_risk/cassini/utilities/cassis/program_utils'
19
+
20
+ require 'razor_risk/cassini/utilities/cassis/internal/require/pantheios'
21
+ require 'razor_risk/cassini/utilities/cassis/internal/require/xqsr3/quality/parameter_checking'
22
+
23
+ require 'open3'
24
+ require 'yaml'
25
+
26
+ =begin
27
+ =end
28
+
29
+ module RazorRisk
30
+ module Cassini
31
+ module Utilities
32
+ module CassIS
33
+
34
+ module ZipUtils
35
+
36
+ def load_unzippers_spec config_dirs, unzippers_all, unzippers_unix, unzippers_windows
37
+
38
+ unzippers = nil
39
+
40
+ unless unzippers
41
+
42
+ config_dirs.each do |config_dir|
43
+
44
+ cf_path = File.join(config_dir, ProgramUtils.windows? ? unzippers_windows : unzippers_unix)
45
+
46
+ if File.file?(cf_path)
47
+
48
+ unzippers = cf_path
49
+
50
+ break
51
+ end
52
+ end
53
+ end
54
+
55
+ unless unzippers
56
+
57
+ config_dirs.each do |config_dir|
58
+
59
+ cf_path = File.join(config_dir, unzippers_all)
60
+
61
+ if File.file? cf_path
62
+
63
+ unzippers = cf_path
64
+
65
+ break
66
+ end
67
+ end
68
+ end
69
+
70
+ if unzippers
71
+
72
+ begin
73
+
74
+ unzippers = YAML.load_file unzippers
75
+ rescue => x
76
+
77
+ $stderr.puts "exception(#{x.class}): #{x}"
78
+
79
+ raise
80
+ end
81
+ end
82
+
83
+ unzippers
84
+ end
85
+
86
+ def load_unzipper_classes lib_dir, aborter
87
+
88
+ Dir[ "#{lib_dir}/razor_risk/utilities/software/packaging/unzippers/*" ].each { |p| require p }
89
+
90
+ unless defined?(::RazorRisk::Utilities::Software::Packaging::Unzippers)
91
+
92
+ begin
93
+
94
+ require 'razor_risk/utilities/software/packaging/unzippers'
95
+ rescue ::LoadError
96
+
97
+ aborter.abort 'no zippers found'
98
+ end
99
+ end
100
+ end
101
+
102
+ def get_zip_command_maker unzip_tools, env, **options
103
+
104
+ hmd = nil
105
+
106
+ if ProgramUtils.windows?
107
+
108
+ hmd ||= options[:homedrive]
109
+ hmd ||= env['HOMEDRIVE'] || 'C:'
110
+ end
111
+
112
+ unzip_tools.each do |k, v|
113
+
114
+ uz_class = v['class'] or next
115
+
116
+ # 1. try the environment variable(s)
117
+
118
+ env_vars = v['env-vars'] || []
119
+
120
+ env_vars.each do |env_var|
121
+
122
+ evv = env[env_var]
123
+
124
+ if evv && File.exist?(evv)
125
+
126
+ # evv might be a file, in which case
127
+
128
+ return uz_class.new(evv) if File.file?(evv)
129
+
130
+ if File.directory?(evv)
131
+
132
+ exe = v['exe']
133
+
134
+ p = File.join(evv, exe)
135
+
136
+ return uz_class.new(p) if File.file?(p)
137
+ end
138
+ end
139
+ end
140
+
141
+ # 2. try the directories
142
+
143
+ exe = v['exe'] or next
144
+
145
+ directories = v['directories'] || []
146
+
147
+ directories.each do |dir|
148
+
149
+ dir = ProgramUtils.make_windows_path(dir, hmd) if ProgramUtils.windows?
150
+
151
+ p = File.join(dir, exe)
152
+
153
+ return uz_class.new(p) if File.file?(p)
154
+ end
155
+
156
+ # 3. try 'which/where'
157
+
158
+ unless ProgramUtils.windows?
159
+
160
+ begin
161
+
162
+ stdout, _, status = Open3::captur3("which \"#{exe}\"")
163
+ r = stdout.strip
164
+
165
+ return uz_class.new(r) unless r.nil? or r.empty? or !status.success?
166
+ rescue Errno::ENOENT => x
167
+
168
+ end
169
+ else
170
+
171
+ begin
172
+ stdout, _, status = Open3::capture3("where \"#{exe}\"")
173
+ r = stdout.split(/$/).map(&:strip).compact.first
174
+
175
+ return uz_class.new(r) unless r.nil? or r.empty? or !status.success?
176
+ rescue Errno::ENOENT => x
177
+
178
+ end
179
+ end
180
+ end
181
+
182
+
183
+ nil
184
+ end
185
+
186
+ def report_unzip_failure unzip_tools, env, aborter, **options
187
+
188
+ hmd = nil
189
+
190
+ if windows?
191
+
192
+ hmd ||= options[:homedrive]
193
+ hmd ||= env['HOMEDRIVE'] || 'C:'
194
+ end
195
+
196
+ msg = ''
197
+
198
+ msg += "failed to detect any of the following (un)zipper utilities:\n"
199
+
200
+ unzip_tools.each { |k, v| msg += "\t#{k}\n" }
201
+
202
+ msg += "in any of the following directories:\n"
203
+
204
+ unzip_tools.each do |k, v|
205
+
206
+ (v['directories'] || {}).each do |dir|
207
+
208
+ dir = ProgramUtils.make_windows_path(dir, hmd) if windows?
209
+
210
+ msg += "\t#{dir}\n"
211
+ end
212
+ end
213
+
214
+ msg += "and none of the following environment variables were defined or, if defined, existed:\n"
215
+
216
+ unzip_tools.each do |k, v|
217
+
218
+ (v['env-vars'] || {}).each do |ev|
219
+
220
+ msg += "\t#{ev}\n"
221
+ end
222
+ end
223
+
224
+ aborter.abort msg
225
+ end
226
+
227
+ end # module ZipUtils
228
+
229
+ end # module CassIS
230
+ end # module Utilities
231
+ end # module Cassini
232
+ end # module RazorRisk
233
+
234
+ # ############################## end of file ############################# #
235
+
236
+
@@ -0,0 +1,6 @@
1
+
2
+ require 'razor_risk/cassini/utilities/cassis/configuration_generator'
3
+ require 'razor_risk/cassini/utilities/cassis/constants'
4
+ require 'razor_risk/cassini/utilities/cassis/program_utils'
5
+ require 'razor_risk/cassini/utilities/cassis/version'
6
+ require 'razor_risk/cassini/utilities/cassis/zip_utils'
@@ -0,0 +1,122 @@
1
+ # encoding: utf-8
2
+
3
+ # ##########################################################################
4
+ #
5
+ # Process the CLI arguments for the configurator.
6
+ #
7
+ # Copyright (c) 2019 Razor Risk Technologies Pty Limited. All rights reserved.
8
+ #
9
+ # ##########################################################################
10
+
11
+ # ##########################################################
12
+ # requires
13
+
14
+ require 'razor_risk/cassini/utilities/cassis/version'
15
+ require 'razor_risk/cassini/utilities/cassis/constants'
16
+
17
+ require 'libclimate'
18
+
19
+
20
+ # ##########################################################
21
+ # modules
22
+
23
+ module RazorRisk
24
+ module Cassini
25
+ module Utilities
26
+ module Configuration
27
+
28
+ # ##########################################################
29
+ # CLI
30
+
31
+ class CLI
32
+
33
+ include ::RazorRisk::Cassini::Utilities::CassIS
34
+
35
+ def self.parse_args *args
36
+
37
+ options = {}
38
+ climate = LibCLImate::Climate.new do |cl|
39
+
40
+ cl.add_flag(
41
+ '--absolute-paths',
42
+ alias: '-a',
43
+ help: 'given paths are made absolute'
44
+ ) do
45
+ options[:absolute_paths] = true
46
+ end
47
+
48
+ cl.add_flag(
49
+ '--quiet',
50
+ alias: '-q',
51
+ help: 'does not issue informational/progress reports (to standard output stream) the installation progress steps; any failure contingent reports are still issued'
52
+ ) do
53
+ options[:quiet] = true
54
+ end
55
+
56
+ cl.add_flag(
57
+ '--generate-initial-config ',
58
+ alias: '-C',
59
+ help: 'generates an initial configuration file'
60
+ ) do
61
+ options[:gen_init_conf] = true
62
+ end
63
+
64
+ cl.add_flag(
65
+ '--generate-secrets',
66
+ alias: '-S',
67
+ help: 'generates a secrets files required for JWT'
68
+ ) do
69
+ options[:gen_secrets] = true
70
+ end
71
+
72
+ cl.add_flag(
73
+ '--no-configuration',
74
+ alias: '-N',
75
+ help: 'do not run configuration helper to configure the razor web services'
76
+ ) do
77
+ options[:no_configuration] = true
78
+ end
79
+
80
+ cl.add_option(
81
+ '--input-config-file',
82
+ alias: '-f',
83
+ help: 'Merge an input configuration rather than configuring interactively'
84
+ ) do |o, a|
85
+ options[:no_configuration] = true
86
+ options[:input_config] = o.value
87
+ end
88
+
89
+ cl.info_lines = [
90
+ 'Razor Web Services Configuration Tool',
91
+ CASSIS_INFO_DESCRIPTION,
92
+ CASSINI_INFO_DESCRIPTION,
93
+ CASSINI_INFO_COPYRIGHT_ + '2018',
94
+ :version,
95
+ nil,
96
+ 'Configures a Razor Web Services instance.',
97
+ nil,
98
+ ]
99
+ end
100
+
101
+ options[:aborter] = climate
102
+ options[:working_directory] = Dir.pwd
103
+
104
+ climate.run *args
105
+
106
+ options
107
+ end
108
+ end
109
+
110
+
111
+ # ##########################################################
112
+ # modules
113
+
114
+ end # module Configuration
115
+ end # module Utilities
116
+ end # module Cassini
117
+ end # module RazorRisk
118
+
119
+
120
+ # ############################## end of file ############################# #
121
+
122
+
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ # ##########################################################################
4
+ #
5
+ # Copyright (c) 2019 Razor Risk Technologies Pty Limited. All rights reserved.
6
+ #
7
+ # ##########################################################################
8
+
9
+ # ##########################################################
10
+ # requires
11
+
12
+ require 'razor_risk/cassini/utilities/configuration/cli'
13
+
14
+ # ############################## end of file ############################# #
15
+
16
+
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ # ##########################################################################
5
+ #
6
+ # Copyright (c) 2019 Razor Risk Technologies Pty Limited. All rights reserved.
7
+ #
8
+ # ##########################################################################
9
+
10
+ #
11
+ class Hash
12
+
13
+ # Returns a new hash that combines the contents of the receiver and the
14
+ # contents of the given hash. Duplicate keys are deep merged if the
15
+ # values are both hashes, concatenated if both values are arrays,
16
+ # otherwise overwritten with the value from +other_hash+.
17
+ #
18
+ # @param other_hash [Hash] The hash to be merged in.
19
+ #
20
+ # @raise [::ArgumentError] if +other_hash+ is not a +Hash+.
21
+ #
22
+ # @return [::Hash] A new hash that combines the contents of the receiver
23
+ # and the contents of the given hash.
24
+ def deep_merge other_hash
25
+
26
+ unless other_hash.is_a? ::Hash
27
+ raise ArgumentError.new "Argument is not a Hash"
28
+ end
29
+
30
+ self.merge(other_hash) do |key, v1, v2|
31
+ if v1.is_a? ::Hash and v2.is_a? ::Hash
32
+ v1.deep_merge v2
33
+ elsif v1.is_a? ::Array and v2.is_a? ::Array
34
+ [ v1, v2 ].flatten
35
+ else
36
+ v2
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ # ############################## end of file ############################# #
43
+
44
+
@@ -0,0 +1,81 @@
1
+ # encoding: UTF-8
2
+
3
+ # ######################################################################## #
4
+ # File: lib/razor_risk/utilities/software/packaging/unzippers/mac_zip.rb
5
+ #
6
+ # Purpose: Definition of
7
+ # RazorRisk::Utilities::Software::Packaging::Unzippers::MacZip
8
+ #
9
+ # Author: Matthew Wilson
10
+ #
11
+ # Copyright (c) 2018, Razor Risk Technologies Pty Ltd
12
+ # All rights reserved.
13
+ #
14
+ # ######################################################################## #
15
+
16
+
17
+ # ##########################################################################
18
+ # requires
19
+
20
+ require 'open3'
21
+
22
+ # ##########################################################################
23
+ # module
24
+
25
+ module RazorRisk
26
+ module Utilities
27
+ module Software
28
+ module Packaging
29
+ module Unzippers
30
+
31
+ # ##########################################################################
32
+ # classes
33
+
34
+ class MacZip
35
+
36
+ def initialize exe_path, **options
37
+
38
+ @exe_path = exe_path
39
+ @options = options
40
+ end
41
+
42
+ def call(archive_path, destination_root, **options)
43
+
44
+ options = @options.merge options
45
+ indent = options[:indent] || ''
46
+
47
+ cmd = ''
48
+ cmd += %Q<"#{@exe_path}" >
49
+ cmd += '-o '
50
+ cmd += %Q<-d "#{destination_root}" >
51
+ cmd += '-- '
52
+ cmd += %Q<"#{archive_path}">
53
+
54
+ stdout_str, stderr_str, status = Open3.capture3(cmd)
55
+
56
+ if 0 != status.exitstatus
57
+
58
+ $stderr.puts stderr_str
59
+
60
+ return status.exitstatus
61
+ else
62
+
63
+ unless options[:quiet]
64
+
65
+ $stdout.puts stdout_str.split(/[\r\n]/).map { |l| "#{indent}#{l}" }.join("\n")
66
+ end
67
+ end
68
+
69
+ 0
70
+ end
71
+ end
72
+
73
+ end # module Unzippers
74
+ end # module Packaging
75
+ end # module Software
76
+ end # module Utilities
77
+ end # module RazorRisk
78
+
79
+ # ############################## end of file ############################# #
80
+
81
+
@@ -0,0 +1,82 @@
1
+ # encoding: UTF-8
2
+
3
+ # ######################################################################## #
4
+ # File: lib/razor_risk/utilities/software/packaging/unzippers/seven_zip.rb
5
+ #
6
+ # Purpose: Definition of
7
+ # RazorRisk::Utilities::Software::Packaging::Unzippers::SevenZip
8
+ #
9
+ # Author: Matthew Wilson
10
+ #
11
+ # Copyright (c) 2018, Razor Risk Technologies Pty Ltd
12
+ # All rights reserved.
13
+ #
14
+ # ######################################################################## #
15
+
16
+
17
+ # ##########################################################################
18
+ # requires
19
+
20
+ require 'open3'
21
+
22
+ # ##########################################################################
23
+ # module
24
+
25
+ module RazorRisk
26
+ module Utilities
27
+ module Software
28
+ module Packaging
29
+ module Unzippers
30
+
31
+ # ##########################################################################
32
+ # classes
33
+
34
+ class SevenZip
35
+
36
+ def initialize exe_path, **options
37
+
38
+ @exe_path = exe_path
39
+ @options = options
40
+ end
41
+
42
+ def call(archive_path, destination_root, **options)
43
+
44
+ options = @options.merge options
45
+ indent = options[:indent] || ''
46
+
47
+ cmd = ''
48
+ cmd += %Q<"#{@exe_path}" >
49
+ cmd += 'x '
50
+ cmd += '-aoa '
51
+ cmd += %Q<-o"#{destination_root}" >
52
+ cmd += '-- '
53
+ cmd += %Q<"#{archive_path}">
54
+
55
+ stdout_str, stderr_str, status = Open3.capture3(cmd)
56
+
57
+ if 0 != status.exitstatus
58
+
59
+ $stderr.puts stderr_str
60
+
61
+ return status.exitstatus
62
+ else
63
+
64
+ unless options[:quiet]
65
+
66
+ $stdout.puts stdout_str.split(/[\r\n]/).map { |l| "#{indent}#{l}" }.join("\n")
67
+ end
68
+ end
69
+
70
+ 0
71
+ end
72
+ end
73
+
74
+ end # module Unzippers
75
+ end # module Packaging
76
+ end # module Software
77
+ end # module Utilities
78
+ end # module RazorRisk
79
+
80
+ # ############################## end of file ############################# #
81
+
82
+
@@ -0,0 +1,82 @@
1
+ # encoding: UTF-8
2
+
3
+ # ######################################################################## #
4
+ # File: lib/razor_risk/utilities/software/packaging/unzippers/win_rar.rb
5
+ #
6
+ # Purpose: Definition of
7
+ # RazorRisk::Utilities::Software::Packaging::Unzippers::WinRAR
8
+ #
9
+ # Author: Matthew Wilson
10
+ #
11
+ # Copyright (c) 2018, Razor Risk Technologies Pty Ltd
12
+ # All rights reserved.
13
+ #
14
+ # ######################################################################## #
15
+
16
+
17
+ # ##########################################################################
18
+ # requires
19
+
20
+ require 'open3'
21
+
22
+ # ##########################################################################
23
+ # module
24
+
25
+ module RazorRisk
26
+ module Utilities
27
+ module Software
28
+ module Packaging
29
+ module Unzippers
30
+
31
+ # ##########################################################################
32
+ # classes
33
+
34
+ class WinRAR
35
+
36
+ def initialize exe_path, **options
37
+
38
+ @exe_path = exe_path
39
+ @options = options
40
+ end
41
+
42
+ def call(archive_path, destination_root, **options)
43
+
44
+ options = @options.merge options
45
+ indent = options[:indent] || ''
46
+
47
+ cmd = ''
48
+ cmd += %Q<"#{@exe_path}" >
49
+ cmd += 'x '
50
+ cmd += '-o+ '
51
+ cmd += %Q<"#{archive_path}" >
52
+ cmd += '*.* '
53
+ cmd += %Q<"#{destination_root}">
54
+
55
+ stdout_str, stderr_str, status = Open3.capture3(cmd)
56
+
57
+ if 0 != status.exitstatus
58
+
59
+ $stderr.puts stderr_str
60
+
61
+ return status.exitstatus
62
+ else
63
+
64
+ unless options[:quiet]
65
+
66
+ $stdout.puts stdout_str.split(/[\r\n]/).map { |l| "#{indent}#{l}" }.join("\n")
67
+ end
68
+ end
69
+
70
+ 0
71
+ end
72
+ end
73
+
74
+ end # module Unzippers
75
+ end # module Packaging
76
+ end # module Software
77
+ end # module Utilities
78
+ end # module RazorRisk
79
+
80
+ # ############################## end of file ############################# #
81
+
82
+