apollo_commons_ruby_cli 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +19 -0
- data/README.md +40 -0
- data/Rakefile +2 -0
- data/apollo_commons_ruby.gemspec +26 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/apollo_commons_ruby/AtroposSubscription.rb +88 -0
- data/lib/apollo_commons_ruby/BackfillSampleData.rb +41 -0
- data/lib/apollo_commons_ruby/DomainEvent.rb +181 -0
- data/lib/apollo_commons_ruby/ExecuteCommand.rb +20 -0
- data/lib/apollo_commons_ruby/FileUtils.rb +136 -0
- data/lib/apollo_commons_ruby/MarioConfigsStability.rb +181 -0
- data/lib/apollo_commons_ruby/MarioEvent.rb +45 -0
- data/lib/apollo_commons_ruby/NetworkUtils.rb +188 -0
- data/lib/apollo_commons_ruby/Operation.rb +5 -0
- data/lib/apollo_commons_ruby/Permission.rb +51 -0
- data/lib/apollo_commons_ruby/RequestDataUtils.rb +28 -0
- data/lib/apollo_commons_ruby/ResolveTemplate.rb +40 -0
- data/lib/apollo_commons_ruby/SecretConfig.rb +65 -0
- data/lib/apollo_commons_ruby/ShopHook.rb +79 -0
- data/lib/apollo_commons_ruby/TemplateDebug.rb +207 -0
- data/lib/apollo_commons_ruby/TemplatePusher.rb +159 -0
- data/lib/apollo_commons_ruby/TemplatesHelper.rb +808 -0
- data/lib/apollo_commons_ruby/TemplatesRakefile.rb +864 -0
- data/lib/apollo_commons_ruby/TenantInfo.rb +26 -0
- data/lib/apollo_commons_ruby/TenantTokenCreator.rb +16 -0
- data/lib/apollo_commons_ruby/VerifyMarioConfig.rb +220 -0
- data/lib/apollo_commons_ruby/ViewGroup.rb +64 -0
- data/lib/apollo_commons_ruby/ViewGroupComponent.rb +73 -0
- data/lib/apollo_commons_ruby/ViewGroupDefinition.rb +68 -0
- data/lib/apollo_commons_ruby/WebhookReporting.rb +13 -0
- data/lib/apollo_commons_ruby/Zebugger.rb +125 -0
- data/lib/apollo_commons_ruby.rb +60 -0
- data/lib/jar/v1_atroposDevTools.jar +0 -0
- data/lib/tasks/add_translations.rake +9 -0
- data/lib/tasks/backfill_sample_data.rake +7 -0
- data/lib/tasks/checkValidJson.rake +17 -0
- data/lib/tasks/delete_domain_event.rake +7 -0
- data/lib/tasks/delete_view_group.rake +7 -0
- data/lib/tasks/delete_view_group_component.rake +21 -0
- data/lib/tasks/delete_view_group_definition.rake +26 -0
- data/lib/tasks/deploy_all_templates.rake +7 -0
- data/lib/tasks/deploy_permissions.rake +6 -0
- data/lib/tasks/deploy_shophooks.rake +6 -0
- data/lib/tasks/display_on_zebugger.rake +19 -0
- data/lib/tasks/get_tenant_token.rake +6 -0
- data/lib/tasks/runTests.rake +27 -0
- data/lib/tasks/template_debug.rake +32 -0
- data/lib/tasks/update_all.rake +36 -0
- data/lib/tasks/update_all_domain_events.rake +24 -0
- data/lib/tasks/update_all_view_group_components.rake +18 -0
- data/lib/tasks/update_domain_event.rake +12 -0
- data/lib/tasks/update_one_template.rake +42 -0
- data/lib/tasks/update_translations.rake +24 -0
- data/lib/tasks/update_view_group_component.rake +9 -0
- data/lib/tasks/update_view_group_definition.rake +7 -0
- data/lib/tasks/update_view_group_for_user_0.rake +36 -0
- data/lib/tasks/validate_mario_configs.rake +10 -0
- data/lib/tasks/verify_mario_config.rake +15 -0
- data/lib/version.rb +3 -0
- metadata +109 -0
@@ -0,0 +1,808 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
require 'openssl'
|
5
|
+
require 'base64'
|
6
|
+
require_relative './NetworkUtils'
|
7
|
+
require_relative 'SecretConfig'
|
8
|
+
|
9
|
+
module HTTP
|
10
|
+
GET = 1
|
11
|
+
POST = 2
|
12
|
+
DELETE = 3
|
13
|
+
PUT = 4
|
14
|
+
end
|
15
|
+
|
16
|
+
class String
|
17
|
+
def black; "\e[30m#{self}\e[0m" end
|
18
|
+
def red; "\e[31m#{self}\e[0m" end
|
19
|
+
def green; "\e[32m#{self}\e[0m" end
|
20
|
+
def brown; "\e[33m#{self}\e[0m" end
|
21
|
+
def blue; "\e[34m#{self}\e[0m" end
|
22
|
+
def magenta; "\e[35m#{self}\e[0m" end
|
23
|
+
def cyan; "\e[36m#{self}\e[0m" end
|
24
|
+
def gray; "\e[37m#{self}\e[0m" end
|
25
|
+
|
26
|
+
def bg_black; "\e[40m#{self}\e[0m" end
|
27
|
+
def bg_red; "\e[41m#{self}\e[0m" end
|
28
|
+
def bg_green; "\e[42m#{self}\e[0m" end
|
29
|
+
def bg_brown; "\e[43m#{self}\e[0m" end
|
30
|
+
def bg_blue; "\e[44m#{self}\e[0m" end
|
31
|
+
def bg_magenta; "\e[45m#{self}\e[0m" end
|
32
|
+
def bg_cyan; "\e[46m#{self}\e[0m" end
|
33
|
+
def bg_gray; "\e[47m#{self}\e[0m" end
|
34
|
+
|
35
|
+
def bold; "\e[1m#{self}\e[22m" end
|
36
|
+
def italic; "\e[3m#{self}\e[23m" end
|
37
|
+
def underline; "\e[4m#{self}\e[24m" end
|
38
|
+
def blink; "\e[5m#{self}\e[25m" end
|
39
|
+
def reverse_color; "\e[7m#{self}\e[27m" end
|
40
|
+
end
|
41
|
+
|
42
|
+
class LineReplacementProperties
|
43
|
+
|
44
|
+
attr_reader :file_path
|
45
|
+
attr_reader :redundant_line_prefix
|
46
|
+
attr_reader :updated_line
|
47
|
+
|
48
|
+
def initialize(file_path, redundant_line_prefix, updated_line)
|
49
|
+
@file_path = file_path
|
50
|
+
@redundant_line_prefix = redundant_line_prefix
|
51
|
+
@updated_line = updated_line
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
class CreateTemplatePayload
|
57
|
+
def initialize(template_group, language, view, templates, version)
|
58
|
+
@template_group = template_group
|
59
|
+
@language = language
|
60
|
+
@view = view
|
61
|
+
@templates = templates
|
62
|
+
@version = version
|
63
|
+
end
|
64
|
+
|
65
|
+
def to_json
|
66
|
+
body = {
|
67
|
+
"templateGroup"=> @template_group,
|
68
|
+
"language"=> @language,
|
69
|
+
"viewType"=> @view,
|
70
|
+
"templates"=> @templates,
|
71
|
+
"version" => @version
|
72
|
+
}
|
73
|
+
body.to_json
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
class TemplateMapping
|
79
|
+
|
80
|
+
def initialize(template_name, template_path, template_mapping)
|
81
|
+
@template_name = template_name
|
82
|
+
@template_path = template_path
|
83
|
+
@template_mapping = template_mapping
|
84
|
+
end
|
85
|
+
|
86
|
+
def create_hash
|
87
|
+
{
|
88
|
+
"template_name"=> @template_name,
|
89
|
+
"template_path"=> @template_path,
|
90
|
+
"template_mapping"=> @template_mapping
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
def create_mapping
|
95
|
+
{
|
96
|
+
@template_mapping => @template_name
|
97
|
+
}
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class Template
|
102
|
+
|
103
|
+
attr_reader :data_template
|
104
|
+
|
105
|
+
def initialize(template_name, default_content, data_template, presentation, attrs)
|
106
|
+
@default_content = default_content
|
107
|
+
@data_template = data_template
|
108
|
+
@presentation = presentation
|
109
|
+
@template_name = template_name
|
110
|
+
@attrs = attrs
|
111
|
+
end
|
112
|
+
|
113
|
+
def create_hash
|
114
|
+
{
|
115
|
+
@template_name => {
|
116
|
+
"defaultContent"=> @default_content,
|
117
|
+
"dataTemplateBase64"=> @data_template,
|
118
|
+
"presentationBase64"=> @presentation,
|
119
|
+
"attrs"=> @attrs
|
120
|
+
}
|
121
|
+
}
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
class CreateTemplatePayload
|
127
|
+
def initialize(template_group, language, view, templates, version)
|
128
|
+
@template_group = template_group
|
129
|
+
@language = language
|
130
|
+
@view = view
|
131
|
+
@templates = templates
|
132
|
+
@version = version
|
133
|
+
end
|
134
|
+
|
135
|
+
def to_json
|
136
|
+
body = {
|
137
|
+
"templateGroup"=> @template_group,
|
138
|
+
"language"=> @language,
|
139
|
+
"viewType"=> @view,
|
140
|
+
"templates"=> @templates,
|
141
|
+
"version" => @version
|
142
|
+
}
|
143
|
+
body.to_json
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
class ConvertPresentationPayload
|
149
|
+
def initialize(presentation, sourcePresentationType, targetPresentationType)
|
150
|
+
@presentation = presentation
|
151
|
+
@sourcePresentationType = sourcePresentationType
|
152
|
+
@targetPresentationType = targetPresentationType
|
153
|
+
end
|
154
|
+
|
155
|
+
def to_json
|
156
|
+
body = {
|
157
|
+
"presentation"=> @presentation,
|
158
|
+
"sourcePresentationType"=> @sourcePresentationType,
|
159
|
+
"targetPresentationType"=> @targetPresentationType
|
160
|
+
}
|
161
|
+
body.to_json
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
module JSON
|
167
|
+
def self.is_valid_json?(json)
|
168
|
+
begin
|
169
|
+
JSON.parse(json)
|
170
|
+
return true
|
171
|
+
rescue JSON::ParserError => e
|
172
|
+
return false
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
class TemplateConfig
|
178
|
+
BaseAppID = "1005"
|
179
|
+
SupportedLanguages = "supportedLanguages"
|
180
|
+
BaseLanguageResource = "VI"
|
181
|
+
|
182
|
+
def self.language_resource_path(language)
|
183
|
+
return "Resources/#{language}.json"
|
184
|
+
end
|
185
|
+
|
186
|
+
def self.base_language_resource_path()
|
187
|
+
return language_resource_path("#{TemplateConfig::BaseLanguageResource}")
|
188
|
+
end
|
189
|
+
|
190
|
+
def self.template_group_contents_path_for_base_app(template_group)
|
191
|
+
return template_group_contents_path_for_appID(template_group, BaseAppID)
|
192
|
+
end
|
193
|
+
|
194
|
+
def self.template_group_contents_path_for_appID(template_group, appID)
|
195
|
+
parent_dir_path = template_group_parent_directory_path_for_appID(template_group, appID)
|
196
|
+
return "#{parent_dir_path}/#{appID}"
|
197
|
+
end
|
198
|
+
|
199
|
+
def self.template_group_parent_directory_path_for_appID(template_group, appID)
|
200
|
+
template_group_parent_path = template_group_parent_directory_path(template_group)
|
201
|
+
return "#{template_group_parent_path}/common/UIVIEW/appID_#{appID}"
|
202
|
+
end
|
203
|
+
|
204
|
+
def self.template_group_parent_directory_path(template_group)
|
205
|
+
return "Templates/#{template_group}"
|
206
|
+
end
|
207
|
+
|
208
|
+
def self.template_group_details_path_for_template_group(template_group)
|
209
|
+
template_group_parent_path = template_group_parent_directory_path(template_group)
|
210
|
+
return "#{template_group_parent_path}/templateGroupDetails.json"
|
211
|
+
end
|
212
|
+
|
213
|
+
def self.template_group_details_for_template_group(template_group)
|
214
|
+
file_path = template_group_details_path_for_template_group(template_group)
|
215
|
+
return read_raw_json_data_from_file_path(file_path)
|
216
|
+
end
|
217
|
+
|
218
|
+
def self.supported_languages_for_template_group(template_group)
|
219
|
+
return template_group_details_for_template_group(template_group)["#{TemplateConfig::SupportedLanguages}"]
|
220
|
+
end
|
221
|
+
|
222
|
+
def self.update_template_group_details_for_template_group(template_group, key, value)
|
223
|
+
template_group_details = template_group_details_for_template_group(template_group)
|
224
|
+
template_group_details[key] = value
|
225
|
+
template_group_details_file_path = template_group_details_path_for_template_group(template_group)
|
226
|
+
puts "updated template group details: #{JSON.pretty_generate template_group_details}"
|
227
|
+
write_data_to_file(template_group_details_file_path, template_group_details)
|
228
|
+
end
|
229
|
+
|
230
|
+
def self.add_language_to_supported_languages_for_template_group(template_group, language)
|
231
|
+
if language == nil
|
232
|
+
log_error("Cannot add nil lanugage to supportedLanguages")
|
233
|
+
return
|
234
|
+
end
|
235
|
+
supported_languages = supported_languages_for_template_group(template_group)
|
236
|
+
if supported_languages.include?(language)
|
237
|
+
log_info("Language #{language} already exists in supported languages. Skipping adding language")
|
238
|
+
else
|
239
|
+
puts "Adding language #{language} to supported languages"
|
240
|
+
supported_languages.push(language)
|
241
|
+
update_template_group_details_for_template_group(template_group, "#{TemplateConfig::SupportedLanguages}", supported_languages)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
class String
|
247
|
+
def newline
|
248
|
+
self.gsub(/\n/,"")
|
249
|
+
end
|
250
|
+
def tabs
|
251
|
+
self.gsub(/\t/," ")
|
252
|
+
end
|
253
|
+
def esc
|
254
|
+
self.gsub(/\"/,"\\\"")
|
255
|
+
end
|
256
|
+
def escnewline
|
257
|
+
self.gsub(/\n/,"\\n")
|
258
|
+
end
|
259
|
+
def unesc
|
260
|
+
self.gsub(/\\\"/,"\"")
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
class CreateCollectionItem
|
265
|
+
def initialize(item_id, data)
|
266
|
+
@itemID = item_id
|
267
|
+
@data = data
|
268
|
+
end
|
269
|
+
|
270
|
+
def to_json
|
271
|
+
body = {
|
272
|
+
"itemID"=> @itemID,
|
273
|
+
"data"=> @data,
|
274
|
+
"isBase64Encoded"=> "true"
|
275
|
+
}
|
276
|
+
body.to_json
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
class Configuration
|
281
|
+
|
282
|
+
attr_reader :environment
|
283
|
+
attr_reader :base_folder_path
|
284
|
+
attr_reader :templated_data_file_path
|
285
|
+
attr_reader :env_data_file_path
|
286
|
+
attr_reader :resources_file_path
|
287
|
+
attr_reader :apollo_config_base_url
|
288
|
+
attr_reader :post_insert_templates_url
|
289
|
+
attr_reader :post_update_templates_url
|
290
|
+
attr_reader :get_templates_for_view_url
|
291
|
+
attr_reader :post_upsert_template_mappings_url
|
292
|
+
attr_reader :get_template_group_details_url
|
293
|
+
attr_reader :post_update_template_group_url
|
294
|
+
attr_reader :post_insert_template_group_url
|
295
|
+
|
296
|
+
def setup(environment, tenantId, projectId)
|
297
|
+
if file_exists?("./.apollo/#{environment}.json")
|
298
|
+
environmentFile = File.read("./.apollo/#{environment}.json")
|
299
|
+
envFile = "./environments/#{environment}.json"
|
300
|
+
else
|
301
|
+
if (environment == 'PreProd')
|
302
|
+
environment = 'Preprod'
|
303
|
+
end
|
304
|
+
if (tenantId != nil && projectId != nil)
|
305
|
+
envFile = "./environments/" + environment + "/env_" + tenantId + "_" + projectId + ".json"
|
306
|
+
if(file_exists?(envFile))
|
307
|
+
environmentFile = File.read(envFile)
|
308
|
+
end
|
309
|
+
else
|
310
|
+
envFile = "./environments/" + environment + "/env.json"
|
311
|
+
if(file_exists?(envFile))
|
312
|
+
environmentFile = File.read(envFile)
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
conf = JSON.parse environmentFile
|
318
|
+
if (conf["apolloConfigBaseUrl"] == nil)
|
319
|
+
puts "Required configurations are missing"
|
320
|
+
raise "Required configurations are missing"
|
321
|
+
return nil
|
322
|
+
end
|
323
|
+
|
324
|
+
@base_folder_path = "./Templates"
|
325
|
+
@templated_data_file_path = "./scripts/commonData/generatedTemplatedData.json"
|
326
|
+
@environment = environment
|
327
|
+
@resources_file_path = "./Resources"
|
328
|
+
@env_data_file_path = envFile
|
329
|
+
@apollo_config_base_url = conf["apolloConfigBaseUrl"]
|
330
|
+
end
|
331
|
+
|
332
|
+
def initialize(environment, base_path)
|
333
|
+
if file_exists?("./.apollo/#{environment}.json")
|
334
|
+
conf_file = File.read(File.expand_path("./.apollo/#{environment}.json"))
|
335
|
+
conf = JSON.parse conf_file
|
336
|
+
|
337
|
+
if (conf["apolloConfigBaseUrl"] == nil)
|
338
|
+
puts "Required configurations are missing"
|
339
|
+
raise "Required configurations are missing"
|
340
|
+
return nil
|
341
|
+
end
|
342
|
+
|
343
|
+
@environment = environment
|
344
|
+
@base_folder_path = "./Templates"
|
345
|
+
@templated_data_file_path = "./scripts/commonData/generatedTemplatedData.json"
|
346
|
+
@env_data_file_path = "./environments/#{environment}.json"
|
347
|
+
@apollo_config_base_url = conf["apolloConfigBaseUrl"]
|
348
|
+
@resources_file_path = "./Resources"
|
349
|
+
|
350
|
+
else
|
351
|
+
puts base_path
|
352
|
+
|
353
|
+
if base_path == nil
|
354
|
+
conf_file = File.read(File.expand_path("/var/jenkins_home/template_config/config.json"));
|
355
|
+
else
|
356
|
+
conf_file = File.read(File.expand_path(base_path));
|
357
|
+
end
|
358
|
+
|
359
|
+
conf = JSON.parse conf_file
|
360
|
+
if (base_path == nil)
|
361
|
+
conf = conf[environment.downcase]
|
362
|
+
end
|
363
|
+
|
364
|
+
if (conf["apolloConfigBaseUrl"] == nil)
|
365
|
+
puts "Required configurations are missing"
|
366
|
+
raise "Required configurations are missing"
|
367
|
+
return nil
|
368
|
+
end
|
369
|
+
|
370
|
+
@environment = environment
|
371
|
+
@base_folder_path = "./Templates"
|
372
|
+
@templated_data_file_path = "./scripts/commonData/generatedTemplatedData.json"
|
373
|
+
@env_data_file_path = conf["env_data_file_path"]
|
374
|
+
@apollo_config_base_url = conf["apolloConfigBaseUrl"]
|
375
|
+
@resources_file_path = "./Resources"
|
376
|
+
@post_insert_templates_url = conf["omsBaseUrl"] + conf["postInsertTemplatesUrl"]
|
377
|
+
@post_update_templates_url = conf["omsBaseUrl"] + conf["postUpdateTemplatesUrl"]
|
378
|
+
@get_templates_for_view_url = conf["omsBaseUrl"] + conf["getTemplatesForViewUrl"]
|
379
|
+
@post_upsert_template_mappings_url = conf["omsBaseUrl"] + conf["postUpsertTemplateMappingsUrl"]
|
380
|
+
@get_template_group_details_url = conf["omsBaseUrl"] + conf["getTemplateGroupDetailsUrl"]
|
381
|
+
@post_update_template_group_url = conf["omsBaseUrl"] + conf["postUpdateTemplateGroupUrl"]
|
382
|
+
@post_insert_template_group_url = conf["omsBaseUrl"] + conf["postInsertTemplateGroupUrl"]
|
383
|
+
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
def get_stringified_value(str)
|
388
|
+
if str == nil
|
389
|
+
return ""
|
390
|
+
end
|
391
|
+
return str
|
392
|
+
end
|
393
|
+
def data_template_file_path_for_template(template_group, lang, view_type, template_name)
|
394
|
+
"#{@base_folder_path}/#{template_group}/#{lang}/#{view_type}/#{template_name}/dataTemplate.json"
|
395
|
+
end
|
396
|
+
|
397
|
+
def presentation_file_path_for_template(template_group, lang, view_type, template_name)
|
398
|
+
"#{@base_folder_path}/#{template_group}/#{lang}/#{view_type}/#{template_name}/presentation.json"
|
399
|
+
end
|
400
|
+
|
401
|
+
def default_content_file_path_for_template(template_group, lang, view_type, template_name)
|
402
|
+
"#{@base_folder_path}/#{template_group}/#{lang}/#{view_type}/#{template_name}/defaultContent.json"
|
403
|
+
end
|
404
|
+
|
405
|
+
def template_name_dir_path_for_template(template_group, language, view_type, template_name)
|
406
|
+
"#{@base_folder_path}/#{template_group}/#{language}/#{view_type}/#{template_name}"
|
407
|
+
end
|
408
|
+
|
409
|
+
def view_type_dir_path_for_template(template_group, language, view_type)
|
410
|
+
"#{@base_folder_path}/#{template_group}/#{language}/#{view_type}"
|
411
|
+
end
|
412
|
+
|
413
|
+
def view_type_dir_path_for_template_with_version(template_group, language, view_type, version)
|
414
|
+
"#{@base_folder_path}/#{template_group}/#{language}/#{view_type}/#{version}"
|
415
|
+
end
|
416
|
+
|
417
|
+
def language_dir_path_for_template(template_group, language)
|
418
|
+
"#{@base_folder_path}/#{template_group}/#{language}"
|
419
|
+
end
|
420
|
+
|
421
|
+
def transfomer_file_path_for_template(template_group)
|
422
|
+
"#{@base_folder_path}/#{template_group}/transformer.js"
|
423
|
+
end
|
424
|
+
|
425
|
+
def client_transfomer_file_path_for_template(template_group)
|
426
|
+
"#{@base_folder_path}/#{template_group}/clientTransformer.js"
|
427
|
+
end
|
428
|
+
|
429
|
+
def template_group_details_file_path_for_template(template_group)
|
430
|
+
"#{@base_folder_path}/#{template_group}/templateGroupDetails.json"
|
431
|
+
end
|
432
|
+
|
433
|
+
def template_group_dir_path_for_template(template_group)
|
434
|
+
"#{@base_folder_path}/#{template_group}"
|
435
|
+
end
|
436
|
+
|
437
|
+
def language_file_path_for_template(language)
|
438
|
+
"#{@resources_file_path}/#{language}.json"
|
439
|
+
end
|
440
|
+
|
441
|
+
def env_file_path(tenant_id, project_id)
|
442
|
+
if file_exists?("./environments/#{@environment}.json")
|
443
|
+
"./environments/#{@environment}.json"
|
444
|
+
elsif file_exists?("./environments/#{@environment}/env_#{tenant_id}_#{project_id}.json")
|
445
|
+
"./environments/#{@environment}/env_#{tenant_id}_#{project_id}.json"
|
446
|
+
else
|
447
|
+
"#{@env_data_file_path}"
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|
451
|
+
end
|
452
|
+
|
453
|
+
def directory_exists?(directory)
|
454
|
+
File.directory?(directory)
|
455
|
+
end
|
456
|
+
|
457
|
+
def file_exists?(file_name)
|
458
|
+
File.file?(file_name)
|
459
|
+
end
|
460
|
+
|
461
|
+
def invoke_API(environment, url, type, query_params = nil, body = nil, authToken = nil)
|
462
|
+
secretConfig = SecretConfig.new(environment);
|
463
|
+
query_params = query_params == nil ? {} : query_params
|
464
|
+
if type == HTTP::GET
|
465
|
+
code, response = make_GET_request(url, authToken == nil ? secretConfig.authToken : authToken, query_params, true)
|
466
|
+
elsif type == HTTP::POST
|
467
|
+
response = make_POST_request(url, body, authToken == nil ? secretConfig.authToken : authToken, query_params, true)
|
468
|
+
elsif type == HTTP::DELETE
|
469
|
+
response = make_DELETE_request(url, body, authToken == nil ? secretConfig.authToken : authToken, query_params, true)
|
470
|
+
end
|
471
|
+
if response
|
472
|
+
JSON.parse response
|
473
|
+
end
|
474
|
+
end
|
475
|
+
|
476
|
+
def make_collection_POST_request (url, body, authToken, query_params = nil)
|
477
|
+
uri = URI.parse(url)
|
478
|
+
uri.query = URI.encode_www_form(query_params) if query_params != nil
|
479
|
+
|
480
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
481
|
+
http.use_ssl = true
|
482
|
+
request = Net::HTTP::Post.new(uri.request_uri,
|
483
|
+
initheader = {'Content-Type' =>'application/json', 'X-Zeta-AuthToken' => authToken})
|
484
|
+
request.body = body
|
485
|
+
|
486
|
+
puts "#{uri}\n\n"
|
487
|
+
puts "#{request.body}\n\n"
|
488
|
+
http.request(request).body
|
489
|
+
end
|
490
|
+
|
491
|
+
def make_collection_GET_request (url, query_params = nil)
|
492
|
+
uri = URI(url)
|
493
|
+
uri.query = URI.encode_www_form(query_params) if query_params != nil
|
494
|
+
|
495
|
+
response = Net::HTTP.get_response(uri)
|
496
|
+
if response.is_a?(Net::HTTPSuccess)
|
497
|
+
utf8_encoded = response.body.force_encoding("UTF-8")
|
498
|
+
JSON.parse utf8_encoded
|
499
|
+
else
|
500
|
+
puts "Error occured while loading #{url}\nquery_params: #{query_params}
|
501
|
+
Error: #{response.inspect}, #{response.body}"
|
502
|
+
end
|
503
|
+
end
|
504
|
+
|
505
|
+
def write_data_to_file(file_path, data)
|
506
|
+
out_file = File.new(file_path, "w")
|
507
|
+
out_file.truncate(0)
|
508
|
+
out_file.puts JSON.pretty_generate data
|
509
|
+
out_file.close
|
510
|
+
end
|
511
|
+
|
512
|
+
def write_templated_data_to_file(configuration, collection_data)
|
513
|
+
out_file = File.new(configuration.templated_data_file_path, "w")
|
514
|
+
out_file.puts JSON.pretty_generate collection_data
|
515
|
+
out_file.close
|
516
|
+
end
|
517
|
+
|
518
|
+
def file_of_name_in_dir_path(dir_path, file_name)
|
519
|
+
file_path = ""
|
520
|
+
begin
|
521
|
+
file_path = Dir.entries(dir_path).select {
|
522
|
+
|entry| entry.include? file_name
|
523
|
+
}.first
|
524
|
+
if !(file_path == nil)
|
525
|
+
file_path = File.join(dir_path,file_path)
|
526
|
+
end
|
527
|
+
rescue Exception => e
|
528
|
+
puts "ERROR: file_of_name_in_dir_path #{dir_path} #{file_name} #{e}"
|
529
|
+
end
|
530
|
+
return file_path
|
531
|
+
end
|
532
|
+
|
533
|
+
def read_data_from_file_of_name_in_dir_path(dir_path, file_name)
|
534
|
+
file_data = {}
|
535
|
+
begin
|
536
|
+
file_path = Dir.entries(dir_path).select {
|
537
|
+
|entry| entry.include? file_name
|
538
|
+
}.first
|
539
|
+
file_path = File.join(dir_path,file_path)
|
540
|
+
file_data = File.read(file_path)
|
541
|
+
rescue Exception => e
|
542
|
+
puts "Reading from #{file_path} failed with error: #{e}"
|
543
|
+
end
|
544
|
+
return file_data
|
545
|
+
end
|
546
|
+
|
547
|
+
def read_data_from_file_path(file_path)
|
548
|
+
file_data = {}
|
549
|
+
begin
|
550
|
+
if (file_exists?(file_path))
|
551
|
+
in_file = File.read(file_path)
|
552
|
+
return if in_file == nil
|
553
|
+
file_data = in_file
|
554
|
+
else
|
555
|
+
file_data = {}
|
556
|
+
end
|
557
|
+
rescue Exception => e
|
558
|
+
puts "Reading from #{file_path} failed with error: #{e}"
|
559
|
+
file_data = {}
|
560
|
+
end
|
561
|
+
return file_data
|
562
|
+
end
|
563
|
+
|
564
|
+
def read_plain_text_data_from_file_path(file_path)
|
565
|
+
file_data = ""
|
566
|
+
begin
|
567
|
+
if (file_exists?(file_path))
|
568
|
+
in_file = File.read(file_path)
|
569
|
+
return if in_file == nil
|
570
|
+
file_data = in_file
|
571
|
+
end
|
572
|
+
rescue Exception => e
|
573
|
+
puts "Reading from #{file_path} failed with error: #{e}"
|
574
|
+
end
|
575
|
+
return file_data
|
576
|
+
end
|
577
|
+
|
578
|
+
def read_res_data_from_file_path(file_path)
|
579
|
+
file_data = {}
|
580
|
+
if (!file_exists?(file_path))
|
581
|
+
file_path = "./Resources/EN.json"
|
582
|
+
end
|
583
|
+
file_data = read_data_from_file_path(file_path)
|
584
|
+
return file_data
|
585
|
+
end
|
586
|
+
|
587
|
+
def setup_appID_uiview_template_group_directory(template_group, appID)
|
588
|
+
base_path = TemplateConfig.template_group_parent_directory_path_for_appID(template_group, appID)
|
589
|
+
contents_path = TemplateConfig.template_group_contents_path_for_appID(template_group, appID)
|
590
|
+
if (directory_exists?(base_path))
|
591
|
+
puts "Template parent directory for appID: #{appID} already exists at path: #{base_path}"
|
592
|
+
else
|
593
|
+
Dir.mkdir base_path
|
594
|
+
end
|
595
|
+
|
596
|
+
if (directory_exists?(contents_path))
|
597
|
+
puts "Template contents directory for appID: #{appID} already exists at path: #{contents_path}"
|
598
|
+
else
|
599
|
+
Dir.mkdir contents_path
|
600
|
+
end
|
601
|
+
end
|
602
|
+
|
603
|
+
def print_separator()
|
604
|
+
puts "------------------------------------------------------------------------------------------------".green
|
605
|
+
end
|
606
|
+
|
607
|
+
def print_header(message)
|
608
|
+
print_separator()
|
609
|
+
puts message.bold.magenta
|
610
|
+
print_separator()
|
611
|
+
end
|
612
|
+
|
613
|
+
def log_error(message)
|
614
|
+
puts "ERROR: #{message}".bold.red
|
615
|
+
end
|
616
|
+
|
617
|
+
def log_info(message)
|
618
|
+
puts "INFO: #{message}".bold
|
619
|
+
end
|
620
|
+
|
621
|
+
def read_new_app_template_groups_from_config()
|
622
|
+
new_app_template_groups = Array.new
|
623
|
+
file_path = "new_app_template_groups.json"
|
624
|
+
|
625
|
+
begin
|
626
|
+
new_app_templates_config = read_raw_json_data_from_file_path(file_path)
|
627
|
+
if new_app_templates_config["templateGroups"].is_a?(Array)
|
628
|
+
new_app_template_groups = new_app_templates_config["templateGroups"]
|
629
|
+
else
|
630
|
+
throw "templateGroups inside config is not an array"
|
631
|
+
end
|
632
|
+
rescue Exception => e
|
633
|
+
log_error("Failed to read new_app_template_groups_config with error: #{e}")
|
634
|
+
end
|
635
|
+
return new_app_template_groups
|
636
|
+
end
|
637
|
+
|
638
|
+
def read_raw_json_data_from_file_path(file_path)
|
639
|
+
data = Hash.new
|
640
|
+
begin
|
641
|
+
if(file_exists?(file_path))
|
642
|
+
in_file = File.read(file_path)
|
643
|
+
if in_file != nil
|
644
|
+
data = JSON.parse(in_file)
|
645
|
+
else
|
646
|
+
throw "Contents are nil"
|
647
|
+
end
|
648
|
+
end
|
649
|
+
rescue Exception => e
|
650
|
+
log_error("Failed to read contents of file at path [#{file_path}]with error: #{e}")
|
651
|
+
end
|
652
|
+
return data
|
653
|
+
end
|
654
|
+
|
655
|
+
def read_json_data_from_file_path(file_path)
|
656
|
+
file_data = {}
|
657
|
+
begin
|
658
|
+
if (file_exists?(file_path))
|
659
|
+
in_file = File.read(file_path)
|
660
|
+
return if in_file == nil
|
661
|
+
data = JSON.parse(in_file)
|
662
|
+
data = data.to_json
|
663
|
+
file_data = data
|
664
|
+
else
|
665
|
+
file_data = {}
|
666
|
+
end
|
667
|
+
rescue Exception => e
|
668
|
+
puts "Reading from #{file_path} failed with error: #{e}"
|
669
|
+
file_data = {}
|
670
|
+
end
|
671
|
+
return file_data
|
672
|
+
end
|
673
|
+
|
674
|
+
def print_separator_line()
|
675
|
+
puts "--------------------------------------------------------------------------------------------------------------------------------------"
|
676
|
+
end
|
677
|
+
|
678
|
+
def does_templated_data_has_payment_instrument_as_states(templated_data, activePaymentInstrumentID, os)
|
679
|
+
if os == "android"
|
680
|
+
outer_states = templated_data["states"]
|
681
|
+
if outer_states
|
682
|
+
if !outer_states.empty?
|
683
|
+
inner_states = outer_states["states"]
|
684
|
+
if !inner_states.empty?
|
685
|
+
keys = inner_states.keys
|
686
|
+
return keys.include? activePaymentInstrumentID
|
687
|
+
end
|
688
|
+
end
|
689
|
+
end
|
690
|
+
end
|
691
|
+
if os == "ios"
|
692
|
+
outer_states = templated_data["states"]
|
693
|
+
keys = outer_states.keys
|
694
|
+
return keys.include? activePaymentInstrumentID
|
695
|
+
end
|
696
|
+
end
|
697
|
+
|
698
|
+
def directory_list(dir_path)
|
699
|
+
dirNames = []
|
700
|
+
Dir.entries(dir_path).select {
|
701
|
+
|entry| File.directory? File.join(dir_path,entry) and !(entry =='.' || entry == '..')
|
702
|
+
}.each do |item|
|
703
|
+
dirNames.push(item)
|
704
|
+
end
|
705
|
+
return dirNames
|
706
|
+
end
|
707
|
+
|
708
|
+
def all_directory_and_sub_directory_with_character_not_in_dir_path(dir_path, character)
|
709
|
+
dirNames = Hash.new
|
710
|
+
Dir.entries(dir_path).select {
|
711
|
+
|entry| File.directory? File.join(dir_path,entry) and !(entry =='.' || entry == '..')
|
712
|
+
}.each do |item|
|
713
|
+
indexOfCharacter = item.index(character)
|
714
|
+
indexOfTemplater = item.index("{{")
|
715
|
+
if indexOfCharacter and indexOfCharacter >= 0 and (!indexOfTemplater || indexOfCharacter < indexOfTemplater)
|
716
|
+
dirNames = dirNames.merge(all_directory_and_sub_directory_with_character_not_in_dir_path(File.join(dir_path,item), character))
|
717
|
+
else
|
718
|
+
dirNames[item] = File.join(dir_path,item)
|
719
|
+
end
|
720
|
+
end
|
721
|
+
return dirNames
|
722
|
+
end
|
723
|
+
|
724
|
+
def all_directory_and_sub_directory_in_dir_path(dir_path)
|
725
|
+
dirNames = Hash.new
|
726
|
+
Dir.entries(dir_path).select {
|
727
|
+
|entry| File.directory? File.join(dir_path,entry) and !(entry =='.' || entry == '..')
|
728
|
+
}.each do |item|
|
729
|
+
dir_path_of_item = File.join(dir_path,item)
|
730
|
+
dir_names_of_item = directory_list(dir_path_of_item)
|
731
|
+
if dir_names_of_item.count > 0
|
732
|
+
dirNames[item] = File.join(dir_path,item)
|
733
|
+
dirNames = dirNames.merge(all_directory_and_sub_directory_in_dir_path(dir_path_of_item))
|
734
|
+
else
|
735
|
+
dirNames[item] = File.join(dir_path,item)
|
736
|
+
end
|
737
|
+
end
|
738
|
+
return dirNames
|
739
|
+
end
|
740
|
+
|
741
|
+
def template_mapping_in_dir_path_file_path_with_character(dir_path, file_path, character)
|
742
|
+
dir_path += "/"
|
743
|
+
file_path.slice! dir_path
|
744
|
+
mapping_components = file_path.split('/')
|
745
|
+
template_mapping = "";
|
746
|
+
mapping_components.each do |item|
|
747
|
+
if item == "default"
|
748
|
+
template_mapping = "*"
|
749
|
+
else
|
750
|
+
length = item.length
|
751
|
+
indexOfCharacter = item.index(character)
|
752
|
+
indexOfTemplater = item.index("{{")
|
753
|
+
if indexOfCharacter and indexOfCharacter >= 0 and (!indexOfTemplater || indexOfCharacter < indexOfTemplater)
|
754
|
+
item_component = item.slice!(indexOfCharacter+1..length-1)
|
755
|
+
if template_mapping.empty?
|
756
|
+
mapping = item_component
|
757
|
+
else
|
758
|
+
mapping = "_" + item_component
|
759
|
+
end
|
760
|
+
template_mapping += mapping
|
761
|
+
end
|
762
|
+
end
|
763
|
+
end
|
764
|
+
return template_mapping
|
765
|
+
end
|
766
|
+
|
767
|
+
def get_presentation_after_conversion_if_neeeded(apolloConfigBaseUrl, environment, template_path)
|
768
|
+
begin
|
769
|
+
#Parsing Presentation
|
770
|
+
presentation_file_path = file_of_name_in_dir_path(template_path,"presentation")
|
771
|
+
puts "presentation_file_path #{presentation_file_path}"
|
772
|
+
presentation = read_data_from_file_path(presentation_file_path)
|
773
|
+
|
774
|
+
#template should fail if presentation file is not present at all
|
775
|
+
if presentation_file_path == nil
|
776
|
+
raise "ERROR: Presentation file not found at path: #{presentation_file_path}"
|
777
|
+
end
|
778
|
+
|
779
|
+
if presentation_file_path.end_with? ".json"
|
780
|
+
#if presentation file is json, then enforce proper json
|
781
|
+
if !JSON.is_valid_json?(presentation)
|
782
|
+
raise "ERROR: Presentation is not a valid JSON"
|
783
|
+
end
|
784
|
+
presentation = JSON.parse(presentation, :quirks_mode => true).to_json
|
785
|
+
return presentation
|
786
|
+
elsif presentation_file_path.end_with? ".xml"
|
787
|
+
presentation = presentation.newline
|
788
|
+
puts "converting presentation xml #{presentation}"
|
789
|
+
json_presentation_string = convert_xml_presentation_to_json(environment, apolloConfigBaseUrl, presentation)
|
790
|
+
puts "converted presentation to json #{json_presentation_string}"
|
791
|
+
return json_presentation_string
|
792
|
+
end
|
793
|
+
rescue Exception => e
|
794
|
+
puts "ERROR: Template loading from #{template_path} failed with error: #{e}"
|
795
|
+
end
|
796
|
+
end
|
797
|
+
|
798
|
+
def convert_xml_presentation_to_json(environment, apolloConfigBaseUrl, presentation)
|
799
|
+
request_payload = ConvertPresentationPayload.new(presentation, "XML", "JSON")
|
800
|
+
endpoint = "#{apolloConfigBaseUrl}/1.0/presentation/convert"
|
801
|
+
converted_presentation = invoke_API(environment, endpoint, HTTP::POST, nil, request_payload.to_json)
|
802
|
+
return converted_presentation["presentation"].unesc
|
803
|
+
end
|
804
|
+
|
805
|
+
module ApolloCommonsRuby
|
806
|
+
class Error < StandardError; end
|
807
|
+
# Your code goes here...
|
808
|
+
end
|