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,136 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'json'
|
3
|
+
require 'pp'
|
4
|
+
require_relative './SecretConfig'
|
5
|
+
|
6
|
+
def load_environment_properties_file(environment, tenantId, projectId)
|
7
|
+
if file_exists?("./.apollo/#{environment}.json")
|
8
|
+
apolloEnvFile = File.read("./.apollo/#{environment}.json")
|
9
|
+
|
10
|
+
if file_exists?("./environments/#{environment}.json")
|
11
|
+
tenantEnvFile = File.read("./environments/#{environment}.json")
|
12
|
+
end
|
13
|
+
|
14
|
+
if apolloEnvFile != nil && tenantEnvFile != nil
|
15
|
+
$environmentProperties = JSON.parse(tenantEnvFile).merge(JSON.parse(apolloEnvFile))
|
16
|
+
elsif tenantEnvFile != nil
|
17
|
+
$environmentProperties = JSON.parse tenantEnvFile
|
18
|
+
else
|
19
|
+
$environmentProperties = JSON.parse apolloEnvFile
|
20
|
+
end
|
21
|
+
else
|
22
|
+
if (environment == 'PreProd')
|
23
|
+
environment = 'Preprod'
|
24
|
+
end
|
25
|
+
envFile = "./environments/" + environment + "/env_" + tenantId + "_" + projectId + ".json"
|
26
|
+
if tenantId != nil && projectId != nil && file_exists?(envFile)
|
27
|
+
environmentFile = File.read(envFile)
|
28
|
+
else
|
29
|
+
environmentFile = File.read("./environments/" + environment + "/env.json")
|
30
|
+
end
|
31
|
+
|
32
|
+
$environmentProperties = JSON.parse environmentFile
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def load_environment_properties(environment, tenantId, projectId)
|
37
|
+
load_environment_properties_file(environment, tenantId, projectId)
|
38
|
+
load_secret_config_file(environment)
|
39
|
+
end
|
40
|
+
|
41
|
+
def load_secret_config_file(environment)
|
42
|
+
begin
|
43
|
+
$secretConfig = SecretConfig.new(environment)
|
44
|
+
rescue
|
45
|
+
print "Running in local. If on jenkins check secret config file"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def load_environment_properties_for_debug(environment, tenantId, projectId)
|
50
|
+
if(tenantId != nil && projectId != nil)
|
51
|
+
load_environment_properties_file(environment, tenantId, projectId)
|
52
|
+
if (environment == 'PreProd')
|
53
|
+
environment = 'Preprod'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
$secretConfig = DebugSecretConfig.new(environment)
|
57
|
+
end
|
58
|
+
|
59
|
+
def replace_environment_based_config_in_string(body, environment)
|
60
|
+
environment.each do |key, value|
|
61
|
+
substring_key = "<<" + key + ">>"
|
62
|
+
if body.include? substring_key
|
63
|
+
puts "Replacing " + substring_key
|
64
|
+
body.gsub! substring_key, value
|
65
|
+
end
|
66
|
+
end
|
67
|
+
if body.include? "\\n"
|
68
|
+
puts "Replacing " + "\\n"
|
69
|
+
body.gsub! "\\n", ""
|
70
|
+
end
|
71
|
+
return body
|
72
|
+
end
|
73
|
+
|
74
|
+
def reverse_replace_environment_based_config_in_string(body, environment)
|
75
|
+
environment.each do |key, value|
|
76
|
+
substring_key = "<<" + key + ">>"
|
77
|
+
if body.include? value
|
78
|
+
puts "Replacing " + value
|
79
|
+
body.gsub! value, substring_key
|
80
|
+
end
|
81
|
+
end
|
82
|
+
return body
|
83
|
+
end
|
84
|
+
|
85
|
+
def replace_single_quote(body)
|
86
|
+
if body.include? "'"
|
87
|
+
puts "Replacing " + "'"
|
88
|
+
body.gsub! "'", "\\\""
|
89
|
+
end
|
90
|
+
return body
|
91
|
+
end
|
92
|
+
|
93
|
+
def replace_double_quote_with_single_quote(body)
|
94
|
+
if body.include? "\\\""
|
95
|
+
body.gsub! "\\\"", "$$q$$"
|
96
|
+
end
|
97
|
+
if body.include? "\""
|
98
|
+
puts "Replacing \" with '"
|
99
|
+
body.gsub! "\"", "'"
|
100
|
+
end
|
101
|
+
if body.include? "$$q$$"
|
102
|
+
body.gsub! "$$q$$", "\\\”"
|
103
|
+
end
|
104
|
+
return body
|
105
|
+
end
|
106
|
+
|
107
|
+
def raise_exception_if_string_empty(string, identifier)
|
108
|
+
if string == nil || string.empty?
|
109
|
+
raise "Empty " + identifier
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def write_to_file(output_file, data)
|
114
|
+
File.new(output_file, 'w+')
|
115
|
+
File.open(output_file, 'w') {|file| file.truncate(0) }
|
116
|
+
File.open(output_file, "w") do |f|
|
117
|
+
f.write(data)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def read_data_from_file_path(file_path)
|
122
|
+
file_data = {}
|
123
|
+
begin
|
124
|
+
if (file_exists?(file_path))
|
125
|
+
in_file = File.read(file_path)
|
126
|
+
return if in_file == nil
|
127
|
+
file_data = in_file
|
128
|
+
else
|
129
|
+
file_data = {}
|
130
|
+
end
|
131
|
+
rescue Exception => e
|
132
|
+
puts "Reading from #{file_path} failed with error: #{e}"
|
133
|
+
file_data = {}
|
134
|
+
end
|
135
|
+
return file_data
|
136
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
require_relative './ExecuteCommand'
|
2
|
+
require_relative './SecretConfig'
|
3
|
+
require_relative './FileUtils'
|
4
|
+
require 'json'
|
5
|
+
require_relative './NetworkUtils'
|
6
|
+
require_relative 'VerifyMarioConfig'
|
7
|
+
require_relative 'WebhookReporting'
|
8
|
+
require_relative 'DomainEvent'
|
9
|
+
require_relative 'RequestDataUtils'
|
10
|
+
require_relative 'TenantInfo'
|
11
|
+
|
12
|
+
$environmentProperties = nil
|
13
|
+
def validate_mario_configs(env)
|
14
|
+
environment = env['environment']
|
15
|
+
env["is_local"] = "false"
|
16
|
+
load_environment_properties(env['environment'], env['tenant_id'], env['project_id'])
|
17
|
+
tenant_info = get_tenant_info(env)
|
18
|
+
tenant_info = JSON.parse(tenant_info)
|
19
|
+
if tenant_info['isEnabled'] == false
|
20
|
+
puts "TENANT IS DISABLED. NOT PROCEEDING"
|
21
|
+
return
|
22
|
+
end
|
23
|
+
all_domain_events = get_all_domain_events(env)
|
24
|
+
if all_domain_events == nil
|
25
|
+
puts "DOMAIN EVENT DATA IS NULL. COULD NOT PROCEED"
|
26
|
+
return
|
27
|
+
end
|
28
|
+
all_domain_events = JSON.parse(all_domain_events)
|
29
|
+
all_domain_events.each do |domainEventData|
|
30
|
+
domain_event_data_json = JSON.parse(domainEventData.to_json)
|
31
|
+
viewGroupDefinition = domain_event_data_json['viewGroupDefinition']
|
32
|
+
component = domain_event_data_json['component']
|
33
|
+
domainEventName = domain_event_data_json['domainEventName']
|
34
|
+
topic = domain_event_data_json['topic']
|
35
|
+
atroposTransformer = nil
|
36
|
+
atroposTransformer = replace_double_quote_with_single_quote(domain_event_data_json['subscriptionInfo']['transformer'])
|
37
|
+
next if domain_event_data_json['attrs'] == nil || domain_event_data_json['attrs']['sampleData'] == nil || domain_event_data_json['attrs']['sampleData'].size == 0
|
38
|
+
sampleData = domain_event_data_json['attrs']['sampleData'][0]
|
39
|
+
task = Hash.new
|
40
|
+
task['environment'] = env['environment']
|
41
|
+
task['view_group_definition'] = viewGroupDefinition
|
42
|
+
task['view_group_component'] = component
|
43
|
+
task['topic'] = topic
|
44
|
+
task['event_name'] = domainEventName
|
45
|
+
task['tenant_id'] = env['tenant_id']
|
46
|
+
task['project_id'] = env['project_id']
|
47
|
+
task['request_data_file'] = "sampleData"
|
48
|
+
begin
|
49
|
+
base_location = Dir.pwd + "/temp/configs/" + task["view_group_definition"] + "/" + task["view_group_component"] + "/" + task["topic"] + "/" + task["event_name"]
|
50
|
+
create_dir_at_path(Dir.pwd + "/temp")
|
51
|
+
create_dir_at_path(Dir.pwd + "/temp/configs")
|
52
|
+
create_dir_at_path(Dir.pwd + "/temp/configs/" + task["view_group_definition"])
|
53
|
+
create_dir_at_path(Dir.pwd + "/temp/configs/" + task["view_group_definition"] + "/" + task["view_group_component"])
|
54
|
+
create_dir_at_path(Dir.pwd + "/temp/configs/" + task["view_group_definition"] + "/" + task["view_group_component"] + "/" + task["topic"])
|
55
|
+
create_dir_at_path(Dir.pwd + "/temp/configs/" + task["view_group_definition"] + "/" + task["view_group_component"] + "/" + task["topic"] + "/" + task["event_name"])
|
56
|
+
create_dir_at_path(Dir.pwd + "/temp/configs/" + task["view_group_definition"] + "/" + task["view_group_component"] + "/" + task["topic"] + "/" + task["event_name"] + "/sampleData")
|
57
|
+
create_dir_at_path(Dir.pwd + "/temp/configs/" + task["view_group_definition"] + "/" + task["view_group_component"] + "/" + task["topic"] + "/" + task["event_name"] + "/sampleData/" + env['environment'])
|
58
|
+
atropos_transformer_location_temp = base_location + "/atropos_subscription_transformer.js"
|
59
|
+
sample_data_location_temp = base_location + "/sampleData/" + env['environment'] + "/sampleData.json"
|
60
|
+
write_to_file(atropos_transformer_location_temp, atroposTransformer)
|
61
|
+
write_to_file(sample_data_location_temp, sampleData.to_json)
|
62
|
+
requestData = validate_atropos_transformer_and_get_output(task, sample_data_location_temp, atropos_transformer_location_temp)
|
63
|
+
if requestData == nil
|
64
|
+
send_webhook_message(task, compose_message(task, "Invalid Atropos Subscription Transformer"))
|
65
|
+
else
|
66
|
+
debug_api_response = handle_mario_debugger(task, "sampleData", requestData, false, false)
|
67
|
+
if JSON.parse(debug_api_response)["status"] == 'failure' || JSON.parse(debug_api_response)["status"] == nil
|
68
|
+
stringified_response = JSON.pretty_generate(JSON.parse(debug_api_response))
|
69
|
+
send_webhook_message(task, compose_message(task, stringified_response))
|
70
|
+
end
|
71
|
+
end
|
72
|
+
rescue => exception
|
73
|
+
puts exception
|
74
|
+
send_webhook_message(task, compose_message(task, "Invalid Configuration"))
|
75
|
+
end
|
76
|
+
begin
|
77
|
+
delete_dir_at_path("/temp")
|
78
|
+
rescue => exception
|
79
|
+
puts "Unable to delete temp directory"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def validate_local_configs(env)
|
85
|
+
environment = env["environment"]
|
86
|
+
tenantId = env["tenant_id"]
|
87
|
+
projectId = env["project_id"]
|
88
|
+
|
89
|
+
Dir.foreach('./configs') do |viewGroupDefinition|
|
90
|
+
next if viewGroupDefinition == '.' || viewGroupDefinition == '..' || viewGroupDefinition == '.DS_Store'
|
91
|
+
Dir.foreach('./configs/' + viewGroupDefinition) do |viewGroupComponent|
|
92
|
+
next if viewGroupComponent == '.' || viewGroupComponent == '..' || viewGroupComponent == 'view_group_definition_properties.json' || viewGroupComponent == '.DS_Store'
|
93
|
+
Dir.foreach('./configs/' + viewGroupDefinition + "/" + viewGroupComponent) do |topic|
|
94
|
+
next if topic == '.' || topic == '..' || topic == 'view_group_component_properties.json' || topic == '.DS_Store'
|
95
|
+
Dir.foreach('./configs/' + viewGroupDefinition + "/" + viewGroupComponent + "/" + topic) do |eventName|
|
96
|
+
next if eventName == '.' || eventName == '..' || eventName == '.DS_Store'
|
97
|
+
puts "Debugging domain event for topic " + topic + " and eventName = " + eventName + " and viewGroupDefinition = " + viewGroupDefinition + " and component = " + viewGroupComponent
|
98
|
+
task = Hash.new
|
99
|
+
task['environment'] = env['environment']
|
100
|
+
task['view_group_definition'] = viewGroupDefinition
|
101
|
+
task['view_group_component'] = viewGroupComponent
|
102
|
+
task['topic'] = topic
|
103
|
+
task['event_name'] = eventName
|
104
|
+
task['tenant_id'] = env['tenant_id']
|
105
|
+
task['project_id'] = env['project_id']
|
106
|
+
begin
|
107
|
+
task['request_data_file'] = get_sample_data_path_from_directory_name(task)
|
108
|
+
begin
|
109
|
+
validate_local_domain_event(task)
|
110
|
+
rescue => exception
|
111
|
+
puts "Unable to validate mario config"
|
112
|
+
puts exception.backtrace
|
113
|
+
end
|
114
|
+
rescue => exception
|
115
|
+
puts "Sample Data not present"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def validate_local_domain_event(env)
|
124
|
+
atropos_transformer_js_validation_jar_output_data = validate_atropos_transformer_and_get_output(env, nil)
|
125
|
+
if atropos_transformer_js_validation_jar_output_data == nil
|
126
|
+
puts "Invalid Atropos Subscription Transformer"
|
127
|
+
raise "Invalid Atropos Subscription Transformer"
|
128
|
+
end
|
129
|
+
status = validate_mario_config(env, env['request_data_file'], atropos_transformer_js_validation_jar_output_data, true, true)
|
130
|
+
if status == false
|
131
|
+
raise "Invalid Configuration"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# Migrate away from flock terminologies in webhook message
|
136
|
+
def compose_message(env, message)
|
137
|
+
# to get the current repo
|
138
|
+
repo_url = `git config --get remote.origin.url`
|
139
|
+
#current_branch = `git branch --show-current`
|
140
|
+
|
141
|
+
if repo_url.include? "@"
|
142
|
+
repo_url = repo_url.gsub(":","/")
|
143
|
+
first_part = repo_url.split("@")[0]
|
144
|
+
second_part = repo_url.split("@")[1].split(".git")[0] + "/src/master"
|
145
|
+
first_part = "https://"
|
146
|
+
repo_url = first_part.concat(second_part)
|
147
|
+
else
|
148
|
+
repo_url = repo_url.split(".git")[0] + "/src/master"
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
str = "<br/> <flockml><span style='color:#4CB659'><b> REPO URL = <a href=\'"+ repo_url +"\'>"+ repo_url+"</a></b></span></flockml><br/>TENANT ID = " + env["tenant_id"] + "<br/>PROJECT ID = " + env["project_id"] + "<br/>VIEW GROUP DEFINITION = " + env["view_group_definition"] +
|
153
|
+
+ "<br/>VIEW GROUP COMPONENT = " + env["view_group_component"] + "<br/>TOPIC = " + env["topic"].gsub("<","<").gsub(">",">") +
|
154
|
+
+ " <br/>EVENT NAME = " + env["event_name"] + "<br/>REQUEST DATA FILE = " + env["request_data_file"] + "<br/><br/><br/>"
|
155
|
+
line = "<br/>================================================= ";
|
156
|
+
|
157
|
+
if(message.include? "logs")
|
158
|
+
if JSON.parse(message)["status"] == 'failure'
|
159
|
+
return str.concat("<flockml><span style='color:#dd3416'><b>").concat((JSON.parse(message)["logs"].last).to_json).concat("</b></span></flockml>").concat(line)
|
160
|
+
end
|
161
|
+
elsif(message.include? "INVALID PATH")
|
162
|
+
puts message.gsub("<","<").gsub(">",">").red
|
163
|
+
last_element_in_the_path = message.split("/").last
|
164
|
+
path = message.split(":")[1].gsub(Dir.pwd,"").gsub(last_element_in_the_path,"")
|
165
|
+
return str.gsub(repo_url,repo_url+path).concat("<flockml><span style='color:#dd3416'><b>").concat(message).concat(":</b></span></flockml>").concat(line)
|
166
|
+
elsif(message.include? "RuntimeException")
|
167
|
+
error_log = "PLEASE CHECK ATROPOS SUBSCRIPTION FILE, THERE IS A RUNTIME EXCEPTION" +
|
168
|
+
+ "<br/><br/>" + message
|
169
|
+
puts error_log.red
|
170
|
+
return str.gsub(repo_url,repo_url).concat("<flockml><span style='color:#dd3416'><b>").concat(error_log).concat(":</b></span></flockml>").concat(line)
|
171
|
+
elsif (message.include? "data")
|
172
|
+
if (JSON.parse(message)["data"] == nil)
|
173
|
+
message = "PLEASE CHECK ATROPOS SUBSCRIPTION FILE, AFTER VALIDATION OF ATROPOS SUBSCRIPTION FILE, THE RESULTANT TRANSFORMED PAYLOAD IS NULL" +
|
174
|
+
+ "<br/><br/> "
|
175
|
+
puts message.red
|
176
|
+
return str.gsub(repo_url,repo_url).concat("<flockml><span style='color:#dd3416'><b>").concat(message).concat(":</b></span></flockml>").concat(line)
|
177
|
+
end
|
178
|
+
else
|
179
|
+
return str.gsub(repo_url, repo_url).concat("<flockml><span style='color:#dd3416'><b>").concat(line).concat(message).concat(":</b></span></flockml>")
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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
|
+
$mario_event = nil
|
11
|
+
$secretConfig = nil
|
12
|
+
|
13
|
+
class MarioEvent
|
14
|
+
attr_reader :tenantId
|
15
|
+
attr_reader :projectId
|
16
|
+
attr_reader :viewGroupDefinition
|
17
|
+
attr_reader :viewGroupComponent
|
18
|
+
attr_reader :topic
|
19
|
+
attr_reader :eventName
|
20
|
+
attr_reader :requestBody
|
21
|
+
|
22
|
+
def initialize(configuration_json, view_group_definition, view_group_component, topic, event_name, request_body)
|
23
|
+
@tenantId = configuration_json["tenantId"]
|
24
|
+
@projectId = configuration_json["projectId"]
|
25
|
+
@viewGroupDefinition = view_group_definition
|
26
|
+
@viewGroupComponent = view_group_component
|
27
|
+
@topic = topic
|
28
|
+
@eventName = event_name
|
29
|
+
@requestBody = request_body
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def handle_mario_event(viewGroupDefinitionName, environment, tenantId, projectId, component, topic, eventName, requestBody)
|
34
|
+
load_environment_properties(environment, tenantId, projectId)
|
35
|
+
$mario_event = MarioEvent.new($environmentProperties, viewGroupDefinitionName, component, topic, eventName, requestBody)
|
36
|
+
perform_mario_event_operation
|
37
|
+
end
|
38
|
+
|
39
|
+
def perform_mario_event_operation
|
40
|
+
baseMarioUrl = $environmentProperties["apolloMarioBaseUrl"]
|
41
|
+
authToken = $secretConfig.authToken
|
42
|
+
marioUrl = baseMarioUrl + "/apollo-mario/1.0/tenants/" + $mario_event.tenantId + "/projects/" + $mario_event.projectId + "/view-group-definitions/" + $mario_event.viewGroupDefinition + "/components/" + $mario_event.viewGroupComponent + "/topics/" + $mario_event.topic + "/events/" + $mario_event.eventName + "/subscription"
|
43
|
+
replace_environment_based_config_in_string(marioUrl, $environmentProperties)
|
44
|
+
make_POST_request(marioUrl,replace_environment_based_config_in_string(JSON.generate(JSON.parse $mario_event.requestBody), $environmentProperties), authToken)
|
45
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
require 'openssl'
|
5
|
+
require 'base64'
|
6
|
+
|
7
|
+
def make_PUT_request (url, body, authtoken, query_params = nil, should_log = true)
|
8
|
+
if authtoken == nil
|
9
|
+
authtoken = ""
|
10
|
+
end
|
11
|
+
uri = URI.parse(url)
|
12
|
+
uri.query = URI.encode_www_form(query_params) if query_params != nil
|
13
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
14
|
+
http.use_ssl = true
|
15
|
+
request = Net::HTTP::Put.new(uri.request_uri,
|
16
|
+
initheader = {
|
17
|
+
'Content-Type' =>'application/json',
|
18
|
+
'X-Zeta-AuthToken' => authtoken,
|
19
|
+
'Authorization' => 'Bearer ' + authtoken
|
20
|
+
})
|
21
|
+
request.body = body
|
22
|
+
|
23
|
+
puts "#{uri}\n\n" if should_log
|
24
|
+
puts "#{request.body}\n\n" if should_log
|
25
|
+
response = http.request(request)
|
26
|
+
puts "#{response.body}\n\n" if should_log
|
27
|
+
return response.body
|
28
|
+
end
|
29
|
+
|
30
|
+
def make_POST_request (url, body, authtoken, query_params = nil, should_log = true)
|
31
|
+
if authtoken == nil
|
32
|
+
authtoken = ""
|
33
|
+
end
|
34
|
+
uri = URI.parse(url)
|
35
|
+
uri.query = URI.encode_www_form(query_params) if query_params != nil
|
36
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
37
|
+
http.use_ssl = true
|
38
|
+
request = Net::HTTP::Post.new(uri.request_uri,
|
39
|
+
initheader = {
|
40
|
+
'Content-Type' =>'application/json',
|
41
|
+
'X-Zeta-AuthToken' => authtoken,
|
42
|
+
'Authorization' => 'Bearer ' + authtoken
|
43
|
+
})
|
44
|
+
request.body = body
|
45
|
+
|
46
|
+
puts "#{uri}\n\n" if should_log
|
47
|
+
puts "#{request.body}\n\n" if should_log
|
48
|
+
response = http.request(request)
|
49
|
+
puts "#{response.body}\n\n" if should_log
|
50
|
+
return response.body
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def make_DELETE_request (url, body = nil, authToken = nil, query_params = nil, should_log = true)
|
55
|
+
uri = URI.parse(url)
|
56
|
+
uri.query = URI.encode_www_form(query_params) if query_params != nil
|
57
|
+
|
58
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
59
|
+
http.use_ssl = true
|
60
|
+
request = Net::HTTP::Delete.new(uri.request_uri,
|
61
|
+
initheader = {
|
62
|
+
'Content-Type' =>'application/json',
|
63
|
+
'X-Zeta-AuthToken' => authToken,
|
64
|
+
'Authorization' => 'Bearer ' + authToken
|
65
|
+
})
|
66
|
+
if body != nil
|
67
|
+
request.body = body
|
68
|
+
end
|
69
|
+
|
70
|
+
puts "#{uri}\n\n" if should_log
|
71
|
+
puts "#{request.body}\n\n" if should_log
|
72
|
+
response = http.request(request)
|
73
|
+
puts "#{response.body}\n\n" if should_log
|
74
|
+
return response.body
|
75
|
+
end
|
76
|
+
|
77
|
+
def make_GET_request (url, authToken, query_params = nil, should_log = true)
|
78
|
+
uri = URI.parse(url)
|
79
|
+
uri.query = URI.encode_www_form(query_params) if query_params != nil
|
80
|
+
|
81
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
82
|
+
http.use_ssl = true
|
83
|
+
request = Net::HTTP::Get.new(uri.request_uri,
|
84
|
+
initheader = {
|
85
|
+
'X-Zeta-AuthToken' => authToken,
|
86
|
+
'Authorization' => 'Bearer ' + authToken
|
87
|
+
})
|
88
|
+
|
89
|
+
puts "#{uri}\n\n" if should_log
|
90
|
+
puts "#{request.body}\n\n" if should_log
|
91
|
+
response = http.request(request)
|
92
|
+
puts "#{response.body}\n\n" if should_log
|
93
|
+
return response.code, response.body
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_hera_token_and_make_request(type, environment, tenantId, projectId, url, body = nil, query_params = nil, should_log = true)
|
97
|
+
return get_token_and_make_request(type, environment, tenantId, projectId, url, body, query_params, should_log, false)
|
98
|
+
end
|
99
|
+
|
100
|
+
def get_tenant_token_and_make_request(type, environment, tenantId, projectId, url, body = nil, query_params = nil, should_log = true)
|
101
|
+
return get_token_and_make_request(type, environment, tenantId, projectId, url, body, query_params, should_log, true)
|
102
|
+
end
|
103
|
+
|
104
|
+
def get_token_and_make_request(type, environment, tenantId, projectId, url, body = nil, query_params = nil, should_log = true, use_tenant_token = true)
|
105
|
+
if file_exists?("./.apollo/#{environment}.json")
|
106
|
+
conf_file = File.read(File.expand_path("./.apollo/#{environment}.json"))
|
107
|
+
conf = JSON.parse conf_file
|
108
|
+
if use_tenant_token
|
109
|
+
authToken = conf["tenantAuthToken"]
|
110
|
+
else
|
111
|
+
authToken = conf["heraAuthToken"]
|
112
|
+
end
|
113
|
+
|
114
|
+
else
|
115
|
+
raise_exception_if_string_empty(environment, "environment")
|
116
|
+
raise_exception_if_string_empty(tenantId, "tenantId")
|
117
|
+
raise_exception_if_string_empty(projectId, "projectId")
|
118
|
+
|
119
|
+
tenantTokenCacheKey = "tenantToken_#{environment}_#{tenantId}"
|
120
|
+
if(ENV[tenantTokenCacheKey] == nil)
|
121
|
+
puts "Making api call to get tenant token"
|
122
|
+
load_environment_properties(environment, tenantId, projectId)
|
123
|
+
raise_exception_if_string_empty($environmentProperties["apolloAppBaseUrl"], "apolloAppBaseUrl")
|
124
|
+
|
125
|
+
authToken = get_token(tenantId, use_tenant_token)
|
126
|
+
ENV[tenantTokenCacheKey] = authToken
|
127
|
+
else
|
128
|
+
puts "Using cached tenant token"
|
129
|
+
authToken = ENV[tenantTokenCacheKey]
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
if (authToken == nil)
|
134
|
+
raise "Failed to get authToken"
|
135
|
+
return
|
136
|
+
end
|
137
|
+
|
138
|
+
if type == HTTP::GET
|
139
|
+
code, response = make_GET_request(url, authToken, query_params, true)
|
140
|
+
return response
|
141
|
+
elsif type == HTTP::POST
|
142
|
+
response = make_POST_request(url, body, authToken, query_params, true)
|
143
|
+
elsif type == HTTP::DELETE
|
144
|
+
response = make_DELETE_request(url, body, authToken, query_params, true)
|
145
|
+
elsif type == HTTP::PUT
|
146
|
+
response = make_PUT_request(url, body, authToken, query_params, true)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def get_token(tenantId, use_tenant_token)
|
151
|
+
if use_tenant_token
|
152
|
+
get_tenant_token($environmentProperties["apolloAppBaseUrl"], tenantId, $secretConfig.heraAuthToken)
|
153
|
+
else
|
154
|
+
$secretConfig.heraAuthToken
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def get_tenant_token(apolloAppBaseUrl, tenantId, heraAuthToken)
|
159
|
+
puts "getting tenant auth token from apollo app"
|
160
|
+
|
161
|
+
apolloAppUrl = apolloAppBaseUrl + "/apollo-app/1.0/tenants/#{tenantId}/access-token"
|
162
|
+
code, response = make_GET_request(apolloAppUrl, heraAuthToken, nil, false)
|
163
|
+
|
164
|
+
jsonResponse = JSON.parse(response)
|
165
|
+
tenantAuthToken = jsonResponse["access_token"]
|
166
|
+
|
167
|
+
if (tenantAuthToken == nil)
|
168
|
+
raise "Failed to get tenantAuthToken from apollo-app"
|
169
|
+
return nil
|
170
|
+
end
|
171
|
+
|
172
|
+
return tenantAuthToken
|
173
|
+
end
|
174
|
+
|
175
|
+
def invoke_API(environment, url, type, query_params = nil, body = nil, authToken = nil)
|
176
|
+
secretConfig = SecretConfig.new(environment);
|
177
|
+
query_params = query_params == nil ? {} : query_params
|
178
|
+
if type == HTTP::GET
|
179
|
+
code, response = make_GET_request(url, authToken == nil ? secretConfig.authToken : authToken, query_params, true)
|
180
|
+
elsif type == HTTP::POST
|
181
|
+
response = make_POST_request(url, body, authToken == nil ? secretConfig.authToken : authToken, query_params, true)
|
182
|
+
elsif type == HTTP::DELETE
|
183
|
+
response = make_DELETE_request(url, body, authToken == nil ? secretConfig.authToken : authToken, query_params, true)
|
184
|
+
end
|
185
|
+
if response
|
186
|
+
JSON.parse response
|
187
|
+
end
|
188
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'json'
|
3
|
+
require 'pp'
|
4
|
+
require_relative './NetworkUtils'
|
5
|
+
require_relative './FileUtils'
|
6
|
+
require_relative './SecretConfig'
|
7
|
+
|
8
|
+
$environmentProperties = nil
|
9
|
+
$secretConfig = nil
|
10
|
+
|
11
|
+
def deploy_permissions(env)
|
12
|
+
environment = env["environment"]
|
13
|
+
tenantId = env["tenantId"]
|
14
|
+
projectId = env["projectId"]
|
15
|
+
itemId = env["itemId"]
|
16
|
+
|
17
|
+
raise_exception_if_string_empty(environment, "environment")
|
18
|
+
raise_exception_if_string_empty(tenantId, "tenantId")
|
19
|
+
raise_exception_if_string_empty(projectId, "projectId")
|
20
|
+
|
21
|
+
load_environment_properties(environment, tenantId, projectId)
|
22
|
+
|
23
|
+
permissionConfigCollectionId = "scopeID." + projectId + ".permission_config@collections.zeta.in"
|
24
|
+
|
25
|
+
if itemId == nil || itemId.empty?
|
26
|
+
files = Dir["./permissions/*.json"]
|
27
|
+
files.each do |path|
|
28
|
+
itemId = File.basename(path, ".json")
|
29
|
+
puts "Deploying permission " + itemId
|
30
|
+
deploy_one_permission(environment, tenantId, projectId, permissionConfigCollectionId, itemId)
|
31
|
+
end
|
32
|
+
else
|
33
|
+
puts "Deploying permission " + itemId
|
34
|
+
deploy_one_permission(environment, tenantId, projectId, permissionConfigCollectionId, itemId)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def deploy_one_permission(environment, tenantId, projectId, permissionConfigCollectionId, itemId)
|
39
|
+
permissionConfig = read_data_from_file_path("./permissions/" + itemId + ".json")
|
40
|
+
|
41
|
+
permissionConfig = JSON.pretty_generate(JSON.parse(permissionConfig)).gsub("\n", '').gsub("\t", '')
|
42
|
+
|
43
|
+
request_payload = {
|
44
|
+
:itemID => itemId,
|
45
|
+
:data => permissionConfig
|
46
|
+
}
|
47
|
+
|
48
|
+
url = $environmentProperties["omsBaseUrl"] + "/zeta.in/collections/1.0/setCollectionItem2?to=#{permissionConfigCollectionId}"
|
49
|
+
|
50
|
+
get_token_and_make_request(HTTP::POST, environment, tenantId, projectId, url, request_payload.to_json)
|
51
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative './FileUtils'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
def get_sample_data_path_from_directory(env)
|
5
|
+
sampleDataLocation = Dir.pwd + "/configs/" + env["view_group_definition"] + "/" + env["view_group_component"] + "/" + env["topic"] + "/" + env["event_name"] + "/sampleData/" + env['environment']
|
6
|
+
Dir.entries(sampleDataLocation).sort.each do |sampleData|
|
7
|
+
next if sampleData == '.' || sampleData == '..' || sampleData == '.DS_Store'
|
8
|
+
return sampleDataLocation + "/" + sampleData
|
9
|
+
end
|
10
|
+
return nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_sample_data_path_from_directory_name(env)
|
14
|
+
sampleDataLocation = Dir.pwd + "/configs/" + env["view_group_definition"] + "/" + env["view_group_component"] + "/" + env["topic"] + "/" + env["event_name"] + "/sampleData/" + env['environment']
|
15
|
+
Dir.entries(sampleDataLocation).sort.each do |sampleData|
|
16
|
+
next if sampleData == '.' || sampleData == '..' || sampleData == '.DS_Store'
|
17
|
+
return sampleData.split(".")[0]
|
18
|
+
end
|
19
|
+
return nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_dir_at_path(path)
|
23
|
+
FileUtils.mkdir_p (path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete_dir_at_path(path)
|
27
|
+
FileUtils.rm_rf(Dir.pwd + path)
|
28
|
+
end
|