apollo_commons_ruby_cli 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.gitignore +9 -0
  4. data/CODE_OF_CONDUCT.md +74 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +19 -0
  7. data/README.md +40 -0
  8. data/Rakefile +2 -0
  9. data/apollo_commons_ruby.gemspec +26 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/lib/apollo_commons_ruby/AtroposSubscription.rb +88 -0
  13. data/lib/apollo_commons_ruby/BackfillSampleData.rb +41 -0
  14. data/lib/apollo_commons_ruby/DomainEvent.rb +181 -0
  15. data/lib/apollo_commons_ruby/ExecuteCommand.rb +20 -0
  16. data/lib/apollo_commons_ruby/FileUtils.rb +136 -0
  17. data/lib/apollo_commons_ruby/MarioConfigsStability.rb +181 -0
  18. data/lib/apollo_commons_ruby/MarioEvent.rb +45 -0
  19. data/lib/apollo_commons_ruby/NetworkUtils.rb +188 -0
  20. data/lib/apollo_commons_ruby/Operation.rb +5 -0
  21. data/lib/apollo_commons_ruby/Permission.rb +51 -0
  22. data/lib/apollo_commons_ruby/RequestDataUtils.rb +28 -0
  23. data/lib/apollo_commons_ruby/ResolveTemplate.rb +40 -0
  24. data/lib/apollo_commons_ruby/SecretConfig.rb +65 -0
  25. data/lib/apollo_commons_ruby/ShopHook.rb +79 -0
  26. data/lib/apollo_commons_ruby/TemplateDebug.rb +207 -0
  27. data/lib/apollo_commons_ruby/TemplatePusher.rb +159 -0
  28. data/lib/apollo_commons_ruby/TemplatesHelper.rb +808 -0
  29. data/lib/apollo_commons_ruby/TemplatesRakefile.rb +864 -0
  30. data/lib/apollo_commons_ruby/TenantInfo.rb +26 -0
  31. data/lib/apollo_commons_ruby/TenantTokenCreator.rb +16 -0
  32. data/lib/apollo_commons_ruby/VerifyMarioConfig.rb +220 -0
  33. data/lib/apollo_commons_ruby/ViewGroup.rb +64 -0
  34. data/lib/apollo_commons_ruby/ViewGroupComponent.rb +73 -0
  35. data/lib/apollo_commons_ruby/ViewGroupDefinition.rb +68 -0
  36. data/lib/apollo_commons_ruby/WebhookReporting.rb +13 -0
  37. data/lib/apollo_commons_ruby/Zebugger.rb +125 -0
  38. data/lib/apollo_commons_ruby.rb +60 -0
  39. data/lib/jar/v1_atroposDevTools.jar +0 -0
  40. data/lib/tasks/add_translations.rake +9 -0
  41. data/lib/tasks/backfill_sample_data.rake +7 -0
  42. data/lib/tasks/checkValidJson.rake +17 -0
  43. data/lib/tasks/delete_domain_event.rake +7 -0
  44. data/lib/tasks/delete_view_group.rake +7 -0
  45. data/lib/tasks/delete_view_group_component.rake +21 -0
  46. data/lib/tasks/delete_view_group_definition.rake +26 -0
  47. data/lib/tasks/deploy_all_templates.rake +7 -0
  48. data/lib/tasks/deploy_permissions.rake +6 -0
  49. data/lib/tasks/deploy_shophooks.rake +6 -0
  50. data/lib/tasks/display_on_zebugger.rake +19 -0
  51. data/lib/tasks/get_tenant_token.rake +6 -0
  52. data/lib/tasks/runTests.rake +27 -0
  53. data/lib/tasks/template_debug.rake +32 -0
  54. data/lib/tasks/update_all.rake +36 -0
  55. data/lib/tasks/update_all_domain_events.rake +24 -0
  56. data/lib/tasks/update_all_view_group_components.rake +18 -0
  57. data/lib/tasks/update_domain_event.rake +12 -0
  58. data/lib/tasks/update_one_template.rake +42 -0
  59. data/lib/tasks/update_translations.rake +24 -0
  60. data/lib/tasks/update_view_group_component.rake +9 -0
  61. data/lib/tasks/update_view_group_definition.rake +7 -0
  62. data/lib/tasks/update_view_group_for_user_0.rake +36 -0
  63. data/lib/tasks/validate_mario_configs.rake +10 -0
  64. data/lib/tasks/verify_mario_config.rake +15 -0
  65. data/lib/version.rb +3 -0
  66. metadata +109 -0
@@ -0,0 +1,26 @@
1
+ require 'fileutils'
2
+ require 'json'
3
+ require 'pp'
4
+ require_relative './NetworkUtils'
5
+ require_relative './FileUtils'
6
+ require_relative './TenantInfo'
7
+ require_relative './Operation'
8
+ require_relative './VerifyMarioConfig'
9
+ require_relative './RequestDataUtils'
10
+
11
+ $environment = nil
12
+ $environmentProperties = nil
13
+
14
+ def get_tenant_info(env)
15
+ if env["is_local"] == "false"
16
+ load_environment_properties(env['environment'], env['tenant_id'], env['project_id'])
17
+ else
18
+ load_environment_properties_for_debug(env['environment'], env['tenant_id'], env['project_id'])
19
+ end
20
+ baseMarioUrl = $environmentProperties["apolloMarioBaseUrl"]
21
+ $environment = env['environment']
22
+ marioUrl = baseMarioUrl + "/apollo-mario/1.0/tenants/" + env["tenant_id"] + "/projects/" + env["project_id"] + "/tenant-info"
23
+ if env["is_local"] == "false"
24
+ return get_hera_token_and_make_request(HTTP::GET, $environment, env['tenant_id'], env['project_id'], marioUrl)
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ require 'fileutils'
2
+ require 'json'
3
+ require 'pp'
4
+ require_relative './NetworkUtils'
5
+ require_relative './FileUtils'
6
+
7
+ def get_tenant_token_from_apollo_app(env)
8
+ tenantId = env["tenantId"]
9
+ raise_exception_if_string_empty(tenantId, "tenantId")
10
+ apolloAppBaseUrl = env["apolloAppBaseUrl"]
11
+ heraAuthToken = env["heraAuthToken"]
12
+ tenantToken = get_tenant_token(apolloAppBaseUrl, tenantId, heraAuthToken)
13
+ if tenantToken != nil
14
+ puts "Tenant Token : " + tenantToken
15
+ end
16
+ end
@@ -0,0 +1,220 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'openssl'
5
+ require 'base64'
6
+ require 'logger'
7
+ require_relative 'SecretConfig'
8
+ require_relative 'FileUtils'
9
+ require_relative 'TemplateDebug'
10
+ require_relative 'TemplatesHelper'
11
+ require_relative 'Operation'
12
+ require_relative 'ViewGroupDefinition'
13
+ require_relative 'ViewGroupComponent'
14
+ require_relative 'DomainEvent'
15
+
16
+ $environmentProperties = nil
17
+ $mario_event = nil
18
+ $LOGGER_FILE = nil
19
+
20
+ class MarioDebugger
21
+ attr_reader :tenantId
22
+ attr_reader :projectId
23
+ attr_reader :viewGroupDefinition
24
+ attr_reader :viewGroupComponent
25
+ attr_reader :topic
26
+ attr_reader :eventName
27
+
28
+ def initialize(configuration_json, view_group_definition, view_group_component, topic, event_name)
29
+ @tenantId = configuration_json["tenantId"]
30
+ @projectId = configuration_json["projectId"]
31
+ @viewGroupDefinition = view_group_definition
32
+ @viewGroupComponent = view_group_component
33
+ @topic = topic
34
+ @eventName = event_name
35
+ end
36
+ end
37
+
38
+ def validate_mario_config(env, request_data_file_identifier, request_data, is_for_debugging, should_pass_local_config_data)
39
+ debug_api_response = handle_mario_debugger(env, request_data_file_identifier, request_data, is_for_debugging, should_pass_local_config_data, false)
40
+ if JSON.parse(debug_api_response)["status"] == 'failure' || JSON.parse(debug_api_response)["status"] == nil
41
+ stringified_response = JSON.pretty_generate(JSON.parse(debug_api_response))
42
+ puts "Failure Response : #{stringified_response}"
43
+ # Api call failure. Allow the configuration to be updated
44
+ if stringified_response.include? "WebClientResponseException"
45
+ return true
46
+ end
47
+ return false
48
+ end
49
+ return true
50
+ end
51
+
52
+ def handle_mario_debugger(env, request_data_file_identifier, requestDataJson, is_for_debugging = false, should_pass_local_config_data = false, display_in_zebugger = false)
53
+ viewGroupDefinition = env['view_group_definition']
54
+ environment = env['environment']
55
+ component = env['view_group_component']
56
+ topic = env['topic']
57
+ eventName = env['event_name']
58
+ tenantId = env['tenant_id']
59
+ projectId = env['project_id']
60
+ template_directory = nil
61
+ userId = nil
62
+ domainId = nil
63
+ if is_for_debugging == true
64
+ load_environment_properties_for_debug(environment, tenantId, projectId)
65
+ template_directory = $secretConfig.templateDirectory
66
+ userId = $secretConfig.userId
67
+ domainId = $secretConfig.domainId
68
+ authToken = $secretConfig.authToken
69
+ else
70
+ load_environment_properties(environment, tenantId, projectId)
71
+ end
72
+ authToken = $secretConfig.authToken
73
+ $mario_debugger = MarioDebugger.new($environmentProperties, viewGroupDefinition, component, topic, eventName)
74
+ viewGroupComponent = nil
75
+ if is_for_debugging == true
76
+ viewGroupComponent = handle_view_group_component_task(env, Operation::DEBUG)
77
+ end
78
+ response = verify_mario_config(environment, authToken, env, request_data_file_identifier, requestDataJson, is_for_debugging, should_pass_local_config_data, viewGroupComponent, template_directory, userId, domainId)
79
+ if JSON.parse(response)["status"] == 'success' && display_in_zebugger == true
80
+ view_template_on_zebugger(env, viewGroupComponent, template_directory)
81
+ end
82
+ return response
83
+ end
84
+
85
+ def verify_mario_config(environment, authToken, env, request_data_file_identifier, requestDataJson, is_for_debugging, should_pass_local_config_data, viewGroupComponent, template_directory = nil, userId = nil, domainId = nil)
86
+ baseMarioUrl = $environmentProperties["apolloMarioBaseUrl"]
87
+ marioUrl = baseMarioUrl + "/apollo-mario/1.0/tenants/" + $mario_debugger.tenantId + "/projects/" + $mario_debugger.projectId + "/view-group-definitions/" + $mario_debugger.viewGroupDefinition + "/components/" + $mario_debugger.viewGroupComponent + "/topics/" + $mario_debugger.topic + "/events/" + $mario_debugger.eventName + "/debug"
88
+ requestDataJson = JSON.parse(requestDataJson)
89
+ if should_pass_local_config_data == true
90
+ requestDataJson["viewGroupDefinition"] = handle_view_group_definition_task(env, Operation::DEBUG)
91
+ requestDataJson["viewGroupComponent"] = viewGroupComponent
92
+ requestDataJson["domainEvent"] = handle_domain_event_task(env, Operation::DEBUG)
93
+ end
94
+ if is_for_debugging == true
95
+ requestDataJson["templateGroupDetails"] = get_template_group(env, viewGroupComponent, template_directory)
96
+ end
97
+ requestDataJson["useMockViewGroup"] = true
98
+ # make a post request
99
+ return make_debug_request(!is_for_debugging, environment, $mario_debugger.tenantId, $mario_debugger.projectId, replace_environment_based_config_in_string(marioUrl, $environmentProperties),
100
+ replace_environment_based_config_in_string(JSON.generate(requestDataJson), $environmentProperties), authToken, request_data_file_identifier, requestDataJson, is_for_debugging, template_directory)
101
+ end
102
+
103
+ def make_debug_request (use_tenant_token, environment, tenantId, projectId, url, body, authtoken, request_data_file_identifier, requestDataJson, is_for_debugging, template_directory = nil)
104
+ if authtoken == nil
105
+ authtoken = ""
106
+ end
107
+ if use_tenant_token == true
108
+ load_environment_properties(environment, tenantId, projectId)
109
+ authtoken = get_tenant_token($environmentProperties["apolloAppBaseUrl"], tenantId, $secretConfig.heraAuthToken)
110
+ end
111
+ uri = URI.parse(url)
112
+ http = Net::HTTP.new(uri.host, uri.port)
113
+ http.use_ssl = true
114
+ request = Net::HTTP::Post.new(uri.request_uri,
115
+ initheader = {
116
+ 'Content-Type' =>'application/json',
117
+ 'X-Zeta-AuthToken' => authtoken,
118
+ 'Authorization' => 'Bearer ' + authtoken
119
+ })
120
+ request.body = body
121
+ response = http.request(request)
122
+ base_directory = "./temp/"
123
+ if is_for_debugging == true
124
+ base_directory = "./"
125
+ end
126
+ FileUtils.mkdir_p (base_directory + "configs/" + $mario_debugger.viewGroupDefinition + "/" + $mario_debugger.viewGroupComponent + "/" + $mario_debugger.topic + "/" + $mario_debugger.eventName + "/debugOutputs")
127
+ # Initialize Logger File Path
128
+ $LOGGER_FILE = base_directory + "configs/" + $mario_debugger.viewGroupDefinition + "/" + $mario_debugger.viewGroupComponent + "/" + $mario_debugger.topic + "/" + $mario_debugger.eventName + "/debugOutputs/logs_" + request_data_file_identifier + ".log"
129
+ # Verify if file exists or not
130
+ if(File.exist?($LOGGER_FILE))
131
+ File.delete($LOGGER_FILE)
132
+ end
133
+
134
+ # Create new file
135
+ log = Logger.new($LOGGER_FILE)
136
+ #Write to output file
137
+ output_file = base_directory + "configs/" + $mario_debugger.viewGroupDefinition + "/" + $mario_debugger.viewGroupComponent + "/" + $mario_debugger.topic + "/" + $mario_debugger.eventName + "/debugOutputs/output_" + request_data_file_identifier + ".json"
138
+
139
+ # Write api response
140
+ if (JSON.parse(response.body)["status"] == 'success')
141
+ log.info "\n\n\nURL :" + url
142
+ log.info "\n\nRequest Body :" + JSON.pretty_generate(JSON.parse(request.body))
143
+ log.info "\n\n\nResponse Body:" + JSON.pretty_generate(JSON.parse(response.body))
144
+ puts "#{JSON.pretty_generate(JSON.parse(response.body))}"
145
+ write_output_to_files(output_file, request_data_file_identifier, response, template_directory)
146
+ return response.body
147
+ else
148
+ log.info "\n\n\nURL :" + url
149
+ log.info "\n\nRequest Body :" + JSON.pretty_generate(JSON.parse(request.body))
150
+ stringified_response = JSON.pretty_generate(JSON.parse(response.body))
151
+ log.info "\n\n\nResponse Body :"+ stringified_response
152
+ puts "#{stringified_response}"
153
+
154
+ failure_reason = '{"Failure Reason" : "Unable to get template Data"}'
155
+ if stringified_response.include? "in.zeta.springframework.boot.commons.authorization.sandboxAccessControl.UnauthorizedException"
156
+ message = "Invalid Tenant Token in userInfo. Get tenant token from https://apollo-ci.zetaapps.in/view/Apollo%20Automation/job/get-tenant-token/build".red
157
+ failure_reason = '{"Failure Reason" : "#{message}"}'
158
+ raise "#{message}"
159
+ elsif stringified_response.include? "UNAUTHORIZED"
160
+ message = "Invalid Tenant Token in userInfo. Get tenant token from https://apollo-ci.zetaapps.in/view/Apollo%20Automation/job/get-tenant-token/build".red
161
+ failure_reason = '{"Failure Reason" : "#{message}"}'
162
+ raise "#{message}"
163
+ end
164
+ if stringified_response.include? "View Group Context Transformer Compilation Error"
165
+ failure_reason = '{"Failure Reason" : "Invalid View Group Context Transformer. Check if the js has missing variable, unescaped double quotes, comments, unstringified undefined or strings begin with double quote"}'
166
+ elsif stringified_response.include? "WebClientResponseException"
167
+ failure_reason = '{"Failure Reason" : "Har Api Call is failing. If unauthorized is present check the auth token else contact the respective service owner and notify them about the issue"}'
168
+ elsif stringified_response.include? "TimeoutException"
169
+ failure_reason = '{"Failure Reason" : "Har Api Call is timing out. Contact the service owner and tell them to check. To unblock yourself for testing purposes add timeoutDuration in Har Config. Give the the duration in milliseconds"}'
170
+ elsif stringified_response.include? "TypeError: Cannot read property"
171
+ failure_reason = '{"Failure Reason" : "Check your transformer.js file. The compilation is failing. Check if the js has missing variable, unescaped double quotes, comments, unstringified undefined or strings begin with double quote"}'
172
+ elsif stringified_response.include? "Invalid Template Group Transformer, not appending transformer data Reason"
173
+ failure_reason = '{"Failure Reason" : "Check your transformer.js file. The compilation is failing. Check if the js has missing variable, unescaped double quotes, comments, unstringified undefined or strings begin with double quote"}'
174
+ elsif stringified_response.include? "Unable to get itemid templating data list for device"
175
+ failure_reason = '{"Failure Reason" : "Check your view group context item id transformer js string. The compilation is failing. Check if the js has missing variable, unescaped double quotes, comments, unstringified undefined or strings begin with double quote"}'
176
+ end
177
+ write_data_to_file(output_file, JSON.parse(failure_reason))
178
+ return response.body
179
+ end
180
+ end
181
+
182
+ def write_output_to_files(output_file, requestDataJson, response, templateDirectory)
183
+ templateData = JSON.parse(JSON.parse(response.body)["items"][0]["data"])["payloads"]["payload1"]["templateData"]
184
+ write_data_to_file(output_file, templateData)
185
+
186
+ if templateDirectory != nil
187
+ #Write to templates directory
188
+ FileUtils.mkdir_p templateDirectory + "/scripts/commonData"
189
+ write_data_to_file(templateDirectory + "/scripts/commonData/generatedTemplatedData.json", templateData)
190
+ end
191
+ end
192
+
193
+ def view_template_on_zebugger(env, viewGroupComponent, templateDirectory)
194
+ zebugger_cmd = "cd #{templateDirectory}; rake zebugger environment=#{env["environment"]} " + "template_group=#{viewGroupComponent["templateGroup"]} language=EN view_type=MARIO platform=#{env["platform"]} tenant_id=#{env['tenant_id']} project_id=#{env['project_id']} templated_data_ready=true"
195
+ begin
196
+ system(zebugger_cmd)
197
+ rescue
198
+ end
199
+ end
200
+
201
+
202
+ def get_template_group(env, viewGroupComponent, template_directory)
203
+ task = OpenStruct.new
204
+ task.environment = env['environment']
205
+ task.template_group = viewGroupComponent["templateGroup"]
206
+ task.view_type = 'MARIO'
207
+ task.template_name = 'default'
208
+ task.tenant_id = env['tenant_id']
209
+ task.project_id = env['project_id']
210
+ task.should_update_inbox = false
211
+ task.scope_id = env['project_id']
212
+ if(env['language'] != nil)
213
+ task.language = env['language']
214
+ else
215
+ task.language = 'EN'
216
+ end
217
+ task.is_debug_api = true
218
+ task.template_directory = template_directory
219
+ return get_template_group_details(task)
220
+ end
@@ -0,0 +1,64 @@
1
+ require 'fileutils'
2
+ require 'json'
3
+ require 'pp'
4
+ require_relative './NetworkUtils'
5
+ require_relative './FileUtils'
6
+ require_relative './Operation'
7
+ require_relative './SecretConfig'
8
+
9
+ $environmentProperties = nil
10
+ $operation = nil
11
+ $viewGroup = nil
12
+ $secretConfig = nil
13
+ $environment = nil
14
+
15
+ class ViewGroup
16
+ attr_reader :tenantId
17
+ attr_reader :projectId
18
+ attr_reader :viewGroupDefinition
19
+ attr_reader :domainId
20
+ attr_reader :apolloUserId
21
+ attr_reader :viewGroupName
22
+
23
+ def initialize(configuration_json, view_group_definition, view_group_name, domain_id, apollo_user_id)
24
+ @tenantId = configuration_json["tenantId"]
25
+ @projectId = configuration_json["projectId"]
26
+ @viewGroupDefinition = view_group_definition
27
+ @viewGroupName = view_group_name
28
+ @domainId = domain_id
29
+ @apolloUserId = apollo_user_id
30
+ end
31
+ end
32
+
33
+ def handle_view_group_task(env, operation)
34
+ viewGroupDefinitionName = env["view_group_definition"]
35
+ $environment = env["environment"]
36
+ viewGroupName = env["view_group_name"]
37
+ domainId = env["domain"]
38
+ apolloUserId = env["apollo_user_id"]
39
+ tenantId = ENV["tenant_id"]
40
+ projectId = ENV["project_id"]
41
+ handle_view_group(viewGroupDefinitionName, $environment, tenantId, projectId, viewGroupName, domainId, apolloUserId, operation)
42
+ end
43
+
44
+ def handle_view_group(viewGroupDefinitionName, environment, tenantId, projectId, viewGroupName, domainId, apolloUserId, operation)
45
+ $operation = operation
46
+ $environment = environment
47
+ load_environment_properties(environment, tenantId, projectId)
48
+ prepare_view_group(viewGroupDefinitionName, viewGroupName, domainId, apolloUserId)
49
+ perform_view_group_operation
50
+ end
51
+
52
+ def prepare_view_group(viewGroupDefinitionName, viewGroupName, domainId, apolloUserId)
53
+ $viewGroup = ViewGroup.new($environmentProperties, viewGroupDefinitionName, viewGroupName, domainId, apolloUserId)
54
+ end
55
+
56
+ def perform_view_group_operation
57
+ baseMarioUrl = $environmentProperties["apolloMarioBaseUrl"]
58
+ authToken = $secretConfig.authToken
59
+ marioUrl = baseMarioUrl + "/apollo-mario/1.0/tenants/" + $viewGroup.tenantId + "/projects/" + $viewGroup.projectId + "/domains/" + $viewGroup.domainId + "/users/" + $viewGroup.apolloUserId + "/view-group-definitions/" + $viewGroup.viewGroupDefinition + "/view-groups/" + $viewGroup.viewGroupName
60
+ replace_environment_based_config_in_string(marioUrl, $environmentProperties)
61
+ if $operation == Operation::DELETE
62
+ get_tenant_token_and_make_request(HTTP::DELETE, $environment, $viewGroup.tenantId, $viewGroup.projectId, marioUrl)
63
+ end
64
+ end
@@ -0,0 +1,73 @@
1
+ require 'fileutils'
2
+ require 'json'
3
+ require 'pp'
4
+ require_relative './NetworkUtils'
5
+ require_relative './FileUtils'
6
+ require_relative './Operation'
7
+ require_relative './SecretConfig'
8
+
9
+ $environmentProperties = nil
10
+ $operation = nil
11
+ $viewGroupComponent = nil
12
+ $secretConfig = nil
13
+ $environment = nil
14
+
15
+ class ViewGroupComponent
16
+ attr_reader :tenantId
17
+ attr_reader :projectId
18
+ attr_reader :viewGroupDefinition
19
+ attr_reader :viewGroupComponent
20
+ attr_reader :requestBody
21
+
22
+ def initialize(configuration_json, view_group_definition, view_group_component)
23
+ @tenantId = configuration_json["tenantId"]
24
+ @projectId = configuration_json["projectId"]
25
+ @viewGroupDefinition = view_group_definition
26
+ @viewGroupComponent = view_group_component
27
+ view_group_component_properties = File.read("./configs/" + view_group_definition + "/" + view_group_component + "/view_group_component_properties.json")
28
+ @requestBody = JSON.parse view_group_component_properties
29
+ @requestBody["tenantId"] = configuration_json["tenantId"]
30
+ @requestBody["projectId"] = configuration_json["projectId"]
31
+ @requestBody["viewGroupDefinition"] = view_group_definition
32
+ end
33
+ end
34
+
35
+ def handle_view_group_component_task(env, operation)
36
+ viewGroupDefinitionName = env["view_group_definition"]
37
+ $environment = env["environment"]
38
+ component = env["view_group_component"]
39
+ tenantId = ENV["tenant_id"]
40
+ projectId = ENV["project_id"]
41
+ return handle_view_group_component(viewGroupDefinitionName, $environment, tenantId, projectId, component, operation)
42
+ end
43
+
44
+ def handle_view_group_component(viewGroupDefinitionName, environment, tenantId, projectId, component, operation)
45
+ $operation = operation
46
+ $environment = environment
47
+ load_environment_properties(environment, tenantId, projectId)
48
+ prepare_view_group_component(viewGroupDefinitionName, component)
49
+ return perform_view_group_component_operation
50
+ end
51
+
52
+ def prepare_view_group_component(view_group_definition, component)
53
+ $viewGroupComponent = ViewGroupComponent.new($environmentProperties, view_group_definition, component)
54
+ end
55
+
56
+ def perform_view_group_component_operation
57
+ raise_exception_if_string_empty($viewGroupComponent.requestBody["templateGroup"], "templateGroup")
58
+ if $operation == Operation::DEBUG
59
+ return $viewGroupComponent.requestBody
60
+ end
61
+ baseMarioUrl = $environmentProperties["apolloMarioBaseUrl"]
62
+ authToken = $secretConfig.authToken
63
+ marioUrl = baseMarioUrl + "/apollo-mario/1.0/tenants/" + $viewGroupComponent.tenantId + "/projects/" + $viewGroupComponent.projectId + "/view-group-definitions/" + $viewGroupComponent.viewGroupDefinition + "/components/" + $viewGroupComponent.viewGroupComponent
64
+ replace_environment_based_config_in_string(marioUrl, $environmentProperties)
65
+ if $operation == Operation::PUT
66
+ get_tenant_token_and_make_request(HTTP::PUT, $environment, $viewGroupComponent.tenantId, $viewGroupComponent.projectId, marioUrl,
67
+ replace_environment_based_config_in_string(JSON.generate($viewGroupComponent.requestBody), $environmentProperties))
68
+ return
69
+ end
70
+ if $operation == Operation::DELETE
71
+ get_tenant_token_and_make_request(HTTP::DELETE, $environment, $viewGroupComponent.tenantId, $viewGroupComponent.projectId, marioUrl)
72
+ end
73
+ end
@@ -0,0 +1,68 @@
1
+ require 'fileutils'
2
+ require 'json'
3
+ require 'pp'
4
+ require_relative './NetworkUtils'
5
+ require_relative './FileUtils'
6
+ require_relative './Operation'
7
+ require_relative './SecretConfig'
8
+
9
+ $environmentProperties = nil
10
+ $operation = nil
11
+ $viewGroupDefinition = nil
12
+ $secretConfig = nil
13
+ $environment = nil
14
+ class ViewGroupDefinition
15
+ attr_reader :tenantId
16
+ attr_reader :projectId
17
+ attr_reader :viewGroupDefinition
18
+ attr_reader :requestBody
19
+
20
+ def initialize(configuration_json, view_group_definition)
21
+ @tenantId = configuration_json["tenantId"]
22
+ @projectId = configuration_json["projectId"]
23
+ @viewGroupDefinition = view_group_definition
24
+ view_group_definition_properties = File.read("./configs/" + view_group_definition + "/view_group_definition_properties.json")
25
+ @requestBody = JSON.parse view_group_definition_properties
26
+ @requestBody["tenantId"] = configuration_json["tenantId"]
27
+ @requestBody["projectId"] = configuration_json["projectId"]
28
+ @requestBody["id"] = view_group_definition
29
+ end
30
+ end
31
+
32
+ def handle_view_group_definition_task(env, operation)
33
+ viewGroupDefinitionName = env["view_group_definition"]
34
+ $environment = env["environment"]
35
+ tenantId = ENV["tenant_id"]
36
+ projectId = ENV["project_id"]
37
+ return handle_view_group_definition(viewGroupDefinitionName, $environment, tenantId, projectId, operation)
38
+ end
39
+
40
+ def handle_view_group_definition(viewGroupDefinitionName, environment, tenantId, projectId, operation)
41
+ $operation = operation
42
+ $environment = environment
43
+ load_environment_properties(environment, tenantId, projectId)
44
+ prepare_view_group_definition(viewGroupDefinitionName)
45
+ return perform_view_group_definition_operation
46
+ end
47
+
48
+ def prepare_view_group_definition(view_group_definition)
49
+ $viewGroupDefinition = ViewGroupDefinition.new($environmentProperties, view_group_definition)
50
+ end
51
+
52
+ def perform_view_group_definition_operation
53
+ if $operation == Operation::DEBUG
54
+ return $viewGroupDefinition.requestBody
55
+ end
56
+ baseMarioUrl = $environmentProperties["apolloMarioBaseUrl"]
57
+ authToken = $secretConfig.authToken
58
+ marioUrl = baseMarioUrl + "/apollo-mario/1.0/tenants/" + $viewGroupDefinition.tenantId + "/projects/" + $viewGroupDefinition.projectId + "/view-group-definitions/" + $viewGroupDefinition.viewGroupDefinition
59
+ replace_environment_based_config_in_string(marioUrl, $environmentProperties)
60
+ if $operation == Operation::PUT
61
+ get_tenant_token_and_make_request(HTTP::PUT, $environment, $viewGroupDefinition.tenantId, $viewGroupDefinition.projectId,
62
+ marioUrl, replace_environment_based_config_in_string(JSON.generate($viewGroupDefinition.requestBody), $environmentProperties))
63
+ return
64
+ end
65
+ if $operation == Operation::DELETE
66
+ get_tenant_token_and_make_request(HTTP::DELETE, $environment, $viewGroupDefinition.tenantId, $viewGroupDefinition.projectId, marioUrl)
67
+ end
68
+ end
@@ -0,0 +1,13 @@
1
+ require 'json'
2
+ require_relative 'FileUtils'
3
+ require_relative 'NetworkUtils'
4
+
5
+ def send_webhook_message(env, message)
6
+ load_environment_properties(env['environment'], env['tenant_id'], env['project_id'])
7
+ if $environmentProperties['webhookUrl'] == nil
8
+ puts "MESSAGE COULD NOT BE SENT SINCE WEBHOOKURL IN ENVIRONMENT FILE IS MISSING".red
9
+ else
10
+ requestBody = { "flockml":message }.to_json
11
+ return make_POST_request($environmentProperties['webhookUrl'], requestBody, "")
12
+ end
13
+ end
@@ -0,0 +1,125 @@
1
+ Encoding.default_external = Encoding::UTF_8
2
+ Encoding.default_internal = Encoding::UTF_8
3
+
4
+ require_relative 'TemplatePusher'
5
+ require_relative 'TemplatesHelper'
6
+ require 'fileutils'
7
+
8
+ def build_template(task, templated_data_ready = false)
9
+ environment = task.environment
10
+ template_group = task.template_group
11
+ language = task.language
12
+ view_type = task.view_type
13
+ template_name = "default"
14
+ platform = task.platform
15
+ tenant_id = task.tenant_id
16
+ project_id = task.project_id
17
+ puts ("Zebugger for #{platform}")
18
+
19
+ configuration = Configuration.allocate
20
+ configuration.setup(environment, tenant_id, project_id)
21
+
22
+ template_path = resolve_template_path(configuration, template_group, language, view_type, template_name)
23
+
24
+ templates = create_template_from_file_for_zebugger(tenant_id, project_id, configuration, environment, template_group, language, view_type, template_name, template_path, false).create_hash
25
+
26
+ puts "template_group = #{template_group}"
27
+ puts "language = #{language}"
28
+ puts "view_type = #{view_type}"
29
+
30
+ presentation = Base64.decode64(templates["default"]["presentationBase64"])
31
+ data_template = Base64.decode64(templates["default"]["dataTemplateBase64"])
32
+
33
+ puts "presentation: #{presentation}"
34
+ puts "data_template: #{data_template}"
35
+
36
+ if(templated_data_ready)
37
+ templated_data = File.read('./scripts/commonData/generatedTemplatedData.json')
38
+ puts "\n\n#{templated_data}\n\n"
39
+ finalTemplatedData = JSON.parse(templated_data)
40
+ write_templated_data_to_file(configuration, finalTemplatedData)
41
+ template_id_set = Set.new
42
+ generatedTemplatedData = IO.read('./scripts/commonData/generatedTemplatedData.json')
43
+ dependent_template_ids = get_dependent_template_ids(generatedTemplatedData, template_id_set)
44
+ dependent_template_ids = get_dependent_template_ids(presentation, template_id_set)
45
+ template_id_set.each do |item|
46
+ puts "Dependent template #{item}"
47
+ end
48
+ push_templates_to_device(configuration, environment, template_group, template_path, dependent_template_ids, language, view_type, platform)
49
+ else
50
+ finalTemplatedData = JSON.parse(data_template.escnewline)
51
+ puts "\n\n#{finalTemplatedData}\n\n"
52
+ write_templated_data_to_file(configuration, finalTemplatedData)
53
+
54
+ dependent_template_ids = get_dependent_template_ids(presentation)
55
+ dependent_template_ids = get_dependent_template_ids(data_template, dependent_template_ids)
56
+ push_templates_to_device(configuration, environment, template_group, template_path, dependent_template_ids, language, view_type, platform)
57
+ end
58
+ end
59
+
60
+ def resolve_template_path(configuration, template_group, language, view_type, template_name)
61
+ template_group_details = get_parsed_template_group_details(configuration, template_group)
62
+
63
+ specific_language_folders = []
64
+ dir_path = configuration.template_group_dir_path_for_template(template_group)
65
+ specific_language_folders = directory_list(dir_path)
66
+
67
+ template_language_folder = language
68
+ if !specific_language_folders.include?(language)
69
+ template_language_folder = "common"
70
+ end
71
+
72
+ return Dir.pwd + "/Templates/#{template_group}/#{template_language_folder}/#{view_type}/#{template_name}"
73
+ end
74
+
75
+ def get_parsed_template_group_details(configuration, template_group)
76
+ template_group_details_file_path = configuration.template_group_details_file_path_for_template(template_group)
77
+ template_group_details = read_json_data_from_file_path(template_group_details_file_path)
78
+ return JSON.parse(template_group_details)
79
+ end
80
+
81
+ def create_template_from_file_for_zebugger (tenant_id, project_id, configuration, environment, template_group, language, view, template_name, template_path, is_apollo_config)
82
+ begin
83
+
84
+ presentation = get_presentation_after_conversion_if_neeeded(configuration.apollo_config_base_url, environment, template_path)
85
+ presentation = JSON.parse(presentation).to_json
86
+ presentation = ResolveTemplate.new.resolveLang(presentation.to_json, configuration, language)
87
+ presentation = JSON.parse(presentation, :quirks_mode => true)
88
+ presentation = ResolveTemplate.new.resolveLang(presentation, configuration, language)
89
+ presentation = Base64.encode64(presentation.newline).newline
90
+
91
+ #Parsing data template
92
+ data_template_file_path = file_of_name_in_dir_path(template_path,"dataTemplate")
93
+ puts "data_template_file_path #{data_template_file_path}"
94
+ #many templates will not support dataTemplate, hence initializing a default value
95
+ data_template = "{}"
96
+ if !(data_template_file_path == nil)
97
+ #data template file is present
98
+ begin
99
+ data_template = read_data_from_file_path(data_template_file_path)
100
+ rescue Exception => e
101
+ #Mostly this should not happen, but a sanity check
102
+ puts "ERROR: data template file not found #{e}"
103
+ end
104
+ if data_template_file_path.end_with? ".json" and !data_template.newline.empty?
105
+ #if data template file is json, then enforce proper json
106
+ if !JSON.is_valid_json?(data_template)
107
+ raise "ERROR: data template is not a valid JSON"
108
+ end
109
+ data_template = "#{data_template}"
110
+ end
111
+ end
112
+
113
+ data_template = ResolveTemplate.new.resolveEnv(data_template, configuration, tenant_id, project_id)
114
+ data_template = ResolveTemplate.new.resolveLang(data_template, configuration, language)
115
+ data_template = Base64.encode64(data_template.newline).newline
116
+
117
+ if is_apollo_config
118
+ Template.new(template_name, '', data_template, presentation, "")
119
+ else
120
+ Template.new(template_name, '', data_template, presentation, "")
121
+ end
122
+ rescue Exception => e
123
+ puts "ERROR: Template loading from #{template_group} failed with error: #{e}"
124
+ end
125
+ end
@@ -0,0 +1,60 @@
1
+ module MarioConfig
2
+ class RakeTasks
3
+ include Rake::DSL if defined? Rake::DSL
4
+ def install_tasks
5
+ load 'tasks/get_tenant_token.rake'
6
+ load 'tasks/delete_domain_event.rake'
7
+ load 'tasks/delete_view_group_component.rake'
8
+ load 'tasks/delete_view_group_definition.rake'
9
+ load 'tasks/delete_view_group.rake'
10
+ load 'tasks/update_all_domain_events.rake'
11
+ load 'tasks/update_all_view_group_components.rake'
12
+ load 'tasks/update_all.rake'
13
+ load 'tasks/update_domain_event.rake'
14
+ load 'tasks/update_view_group_component.rake'
15
+ load 'tasks/update_view_group_definition.rake'
16
+ load 'tasks/update_view_group_for_user_0.rake'
17
+ load 'tasks/verify_mario_config.rake'
18
+ load 'tasks/display_on_zebugger.rake'
19
+ load 'tasks/template_debug.rake'
20
+ load 'tasks/validate_mario_configs.rake'
21
+ load 'tasks/backfill_sample_data.rake'
22
+ end
23
+ end
24
+ end
25
+ MarioConfig::RakeTasks.new.install_tasks
26
+
27
+ module TemplatesTasks
28
+ class RakeTasks
29
+ include Rake::DSL if defined? Rake::DSL
30
+ def install_tasks
31
+ load 'tasks/add_translations.rake'
32
+ load 'tasks/checkValidJson.rake'
33
+ load 'tasks/deploy_all_templates.rake'
34
+ load 'tasks/runTests.rake'
35
+ load 'tasks/update_one_template.rake'
36
+ load 'tasks/update_translations.rake'
37
+ end
38
+ end
39
+ end
40
+ TemplatesTasks::RakeTasks.new.install_tasks
41
+
42
+ module ShopHooksTasks
43
+ class RakeTasks
44
+ include Rake::DSL if defined? Rake::DSL
45
+ def install_tasks
46
+ load 'tasks/deploy_shophooks.rake'
47
+ end
48
+ end
49
+ end
50
+ ShopHooksTasks::RakeTasks.new.install_tasks
51
+
52
+ module PermissionsTasks
53
+ class RakeTasks
54
+ include Rake::DSL if defined? Rake::DSL
55
+ def install_tasks
56
+ load 'tasks/deploy_permissions.rake'
57
+ end
58
+ end
59
+ end
60
+ PermissionsTasks::RakeTasks.new.install_tasks