apollo_commons_ruby_cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c2a6d9a71e323ba743ad61c04ae7ea849dba6e7a54d0c0691b2c1f674397384c
4
+ data.tar.gz: 5e976f8165b92a853c44178f24d57be92d29bd4be227b0dc0caf6ae772612f35
5
+ SHA512:
6
+ metadata.gz: 1a6aea498ecf5963b7ab57c76314847df0509861231de77b3a38b7d5fd828df0d2533c4067c992f82e8fae0294080df43e0a4877308a4d83d86e524fca0dc3fa
7
+ data.tar.gz: 39cf3baf730d63369ec7eb48b5723d511dcc55a335334f4d8f0586e745f21c8f7472fb5470a617ccb3c5d878deec00b94086ebc6cfb2a21096b997ccc194ef47
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at sahilpr@zeta.tech. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in apollo_commons_ruby.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ apollo_commons_ruby (0.7.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (12.3.2)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ apollo_commons_ruby!
16
+ rake (~> 12.0)
17
+
18
+ BUNDLED WITH
19
+ 2.2.17
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # ApolloCommonsRuby
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/apollo_commons_ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'apollo_commons_ruby'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install apollo_commons_ruby
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/apollo_commons_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/apollo_commons_ruby/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+
38
+ ## Code of Conduct
39
+
40
+ Everyone interacting in the ApolloCommonsRuby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/apollo_commons_ruby/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ require_relative 'lib/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "apollo_commons_ruby_cli"
5
+ spec.version = ApolloCommonsRuby::VERSION
6
+ spec.authors = ["Sahil Prakash"]
7
+ spec.email = ["sahilpr@zeta.tech"]
8
+
9
+ spec.summary = "Ruby utilities for apollo projects"
10
+ spec.description = "Used in ruby functions"
11
+ spec.homepage = "https://bitbucket.org/zetaengg/apollo_commons_ruby/src"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://bitbucket.org/zetaengg/apollo_commons_ruby/src"
16
+ spec.metadata["changelog_uri"] = "https://bitbucket.org/zetaengg/apollo_commons_ruby/src"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "apollo_commons_ruby"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,88 @@
1
+ require 'find'
2
+ require 'colorize'
3
+ require_relative './ExecuteCommand'
4
+ require_relative './SecretConfig'
5
+ require_relative './FileUtils'
6
+ require_relative './NetworkUtils'
7
+ require_relative './RequestDataUtils'
8
+
9
+
10
+ $environmentProperties = nil
11
+
12
+ def validate_atropos_transformer_and_get_output(env, sample_data_file_path, transformer_file_path = nil)
13
+
14
+ load_environment_properties(env['environment'], env["tenant_id"], env["project_id"])
15
+
16
+ if sample_data_file_path == nil
17
+ sample_data_file_path = get_sample_data_path_from_directory(env)
18
+ end
19
+
20
+ is_temp_transformer_file_used = false
21
+ if transformer_file_path == nil
22
+ is_temp_transformer_file_used = true
23
+ transformer_file_path_base = Dir.pwd + "/configs/" + env["view_group_definition"] + "/" + env["view_group_component"]+ "/" + env["topic"] + "/" + env["event_name"]
24
+ transformer_file_path = transformer_file_path_base + "/atropos_subscription_transformer_temp.js"
25
+ write_to_file(transformer_file_path, replace_environment_based_config_in_string(File.read(transformer_file_path_base + "/atropos_subscription_transformer.js"), $environmentProperties))
26
+ end
27
+
28
+ jarFilePath = File.dirname(File.dirname(File.join(File.dirname(File.expand_path(__FILE__)),'/jar'))) + '/jar/v1_atroposDevTools.jar'
29
+
30
+ command_output = validate_atropos_subscription_js_file(jarFilePath, sample_data_file_path, transformer_file_path)
31
+
32
+ if is_temp_transformer_file_used == true
33
+ File.delete(Dir.pwd + "/configs/" + env["view_group_definition"] + "/" + env["view_group_component"]+ "/" + env["topic"] + "/" + env["event_name"] + "/atropos_subscription_transformer_temp.js")
34
+ end
35
+ return extract_json_from_command_output(command_output)
36
+ end
37
+
38
+ def validate_atropos_subscription_js_file(jarFilePath, sample_data_file, transformer_file_path)
39
+ if sample_data_file == nil
40
+ puts "Sample Data File Not Provided. Skipping Domain Event Validation. Please update sample data to ensure domain event stability"
41
+ raise "Sample Data not provided"
42
+ end
43
+ if sample_data_file.include? "<"
44
+ sample_data_file = sample_data_file.to_s.gsub! "<", "\\<"
45
+ end
46
+ if sample_data_file.include? ">"
47
+ sample_data_file = sample_data_file.to_s.gsub! ">", "\\>"
48
+ end
49
+ if transformer_file_path.include? "<"
50
+ transformer_file_path = transformer_file_path.to_s.gsub! "<", "\\<"
51
+ end
52
+ if transformer_file_path.include? ">"
53
+ transformer_file_path = transformer_file_path.to_s.gsub! ">", "\\>"
54
+ end
55
+ puts "Transformer File Path => #{transformer_file_path}".green
56
+ puts "Sample Data File Path => #{sample_data_file}".green
57
+ puts "Jar File Path => #{jarFilePath}".green
58
+ command = "java -jar " + jarFilePath + " transform webhook "+ sample_data_file + " " + transformer_file_path
59
+ executeShellCommand = ExecuteShellCommand.new
60
+ return executeShellCommand.run_command(command)
61
+ end
62
+
63
+ def extract_json_from_command_output(console_output)
64
+ if console_output.include? "java.lang.RuntimeException"
65
+ return nil
66
+ elsif(console_output.include? "Transformed payload")
67
+ get_transformed_payload = String.new
68
+ put_value_in_get_transformed_payload = false
69
+
70
+ console_output.each_line.with_index do |line, index|
71
+
72
+ if put_value_in_get_transformed_payload == true
73
+ get_transformed_payload.concat(line)
74
+ end
75
+
76
+ if line.include? "Transformed payload"
77
+ put_value_in_get_transformed_payload = true
78
+ end
79
+ end
80
+
81
+ get_transformed_payload = JSON.parse(get_transformed_payload.to_s.uncolorize)
82
+
83
+ output_json = {:data => get_transformed_payload }.to_json
84
+ return output_json
85
+ else
86
+ return output_json
87
+ end
88
+ end
@@ -0,0 +1,41 @@
1
+ require_relative './SecretConfig'
2
+ require_relative './FileUtils'
3
+ require 'json'
4
+ require_relative './NetworkUtils'
5
+ require_relative 'DomainEvent'
6
+
7
+ $environmentProperties = nil
8
+ def backfill_sample_data_for_configs(env)
9
+ environment = env['environment']
10
+ env["is_local"] = "true"
11
+ load_environment_properties_for_debug(env['environment'], env['tenant_id'], env['project_id'])
12
+ all_domain_events = get_all_domain_events(env)
13
+ if all_domain_events == nil
14
+ puts "DOMAIN EVENT DATA IS NULL. COULD NOT PROCEED"
15
+ return
16
+ end
17
+ all_domain_events = JSON.parse(all_domain_events)
18
+ all_domain_events.each do |domainEventData|
19
+ domain_event_data_json = JSON.parse(domainEventData.to_json)
20
+ viewGroupDefinition = domain_event_data_json['viewGroupDefinition']
21
+ component = domain_event_data_json['component']
22
+ domainEventName = domain_event_data_json['domainEventName']
23
+ topic = domain_event_data_json['topic']
24
+ next if domain_event_data_json['attrs'] == nil || domain_event_data_json['attrs']['sampleData'] == nil || domain_event_data_json['attrs']['sampleData'].size == 0
25
+ counter = 0
26
+ domain_event_data_json['attrs']['sampleData'].each do |sampleData|
27
+ begin
28
+ base_location = "/configs/" + viewGroupDefinition + "/" + component + "/" + topic + "/" + domainEventName
29
+ base_location = reverse_replace_environment_based_config_in_string(base_location, $environmentProperties)
30
+ base_location = Dir.pwd + base_location
31
+ create_dir_at_path(base_location + "/sampleData")
32
+ create_dir_at_path(base_location + "/sampleData/" + env['environment'])
33
+ sample_data_location = base_location + "/sampleData/" + env['environment'] + "/sampleData_" + counter.to_s + ".json"
34
+ write_to_file(sample_data_location, sampleData.to_json)
35
+ counter = counter + 1
36
+ rescue => exception
37
+ puts exception
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,181 @@
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
+ require_relative './ViewGroupDefinition'
9
+ require_relative './ViewGroupComponent'
10
+ require_relative './DomainEvent'
11
+ require_relative './Operation'
12
+ require_relative './VerifyMarioConfig'
13
+ require_relative './AtroposSubscription'
14
+ require_relative './RequestDataUtils'
15
+
16
+ $environmentProperties = nil
17
+ $operation = nil
18
+ $domain_event = nil
19
+ $secretConfig = nil
20
+ $environment = nil
21
+
22
+ class DomainEvent
23
+ attr_reader :tenantId
24
+ attr_reader :projectId
25
+ attr_reader :viewGroupDefinition
26
+ attr_reader :viewGroupComponent
27
+ attr_reader :topic
28
+ attr_reader :eventName
29
+ attr_reader :requestBody
30
+ attr_reader :location
31
+
32
+ def initialize(configuration_json, view_group_definition, view_group_component, topic, event_name)
33
+ @tenantId = configuration_json["tenantId"]
34
+ @projectId = configuration_json["projectId"]
35
+ @viewGroupDefinition = view_group_definition
36
+ @viewGroupComponent = view_group_component
37
+ @topic = topic
38
+ @eventName = event_name
39
+ @location = "./configs/" + view_group_definition + "/" + view_group_component + "/" + topic + "/" + event_name
40
+ begin
41
+ domain_event_properties = File.read(location + "/domain_event_properties.json")
42
+ @requestBody = JSON.parse domain_event_properties
43
+ rescue
44
+ @requestBody = JSON.parse '{}'
45
+ end
46
+ @requestBody["tenantId"] = configuration_json["tenantId"]
47
+ @requestBody["projectId"] = configuration_json["projectId"]
48
+ @requestBody["viewGroupDefinition"] = view_group_definition
49
+ @requestBody["component"] = view_group_component
50
+ @requestBody["topic"] = topic
51
+ @requestBody["domainEventName"] = event_name
52
+ end
53
+ end
54
+
55
+ def update_domain_event(env)
56
+ begin
57
+ atropos_transformer_js_validation_jar_output_data = validate_atropos_transformer_and_get_output(env, nil)
58
+ if atropos_transformer_js_validation_jar_output_data == nil
59
+ puts "Invalid Atropos subscription Transformer"
60
+ return nil
61
+ else
62
+ is_valid_config = validate_mario_config(env, get_sample_data_path_from_directory_name(env), atropos_transformer_js_validation_jar_output_data, false, true)
63
+ if is_valid_config != true
64
+ puts "There might be issues in the config. Please fix and deploy again".red
65
+ end
66
+ end
67
+ rescue
68
+ puts "Unable to validate Domain Event"
69
+ end
70
+ handle_view_group_definition_task(env, Operation::PUT)
71
+ handle_view_group_component_task(env, Operation::PUT)
72
+ handle_domain_event_task(env, Operation::PUT)
73
+ end
74
+
75
+ def handle_domain_event_task(env, operation)
76
+ viewGroupDefinitionName = env["view_group_definition"]
77
+ $environment = env["environment"]
78
+ component = env["view_group_component"]
79
+ topic = env["topic"]
80
+ eventName = env["event_name"]
81
+ tenantId = env["tenant_id"]
82
+ projectId = env["project_id"]
83
+ return handle_domain_event(viewGroupDefinitionName, $environment, tenantId, projectId, component, topic, eventName, operation)
84
+ end
85
+
86
+ def handle_domain_event(viewGroupDefinitionName, environment, tenantId, projectId, component, topic, eventName, operation)
87
+ $operation = operation
88
+ $environment = environment
89
+ load_environment_properties(environment, tenantId, projectId)
90
+ puts "view_group_definition: #{viewGroupDefinitionName}"
91
+ puts "component: #{component}"
92
+ puts "topic: #{topic}"
93
+ puts "event_name: #{eventName}"
94
+ $domain_event = DomainEvent.new($environmentProperties, viewGroupDefinitionName, component, topic, eventName)
95
+ if $operation != Operation::DELETE
96
+ prepare_domain_event(viewGroupDefinitionName, component, topic, eventName)
97
+ end
98
+ return perform_domain_event_operation
99
+ end
100
+
101
+ def prepare_domain_event(view_group_definition, component, topic, event_name)
102
+ associate_user_details_transformer_in_request_body
103
+ associate_view_group_context_transformer_in_request_body
104
+ form_subscription_info
105
+ associate_hars_with_in_request_body
106
+ end
107
+
108
+ def perform_domain_event_operation
109
+ if $operation == Operation::DEBUG
110
+ return $domain_event.requestBody
111
+ end
112
+ baseMarioUrl = $environmentProperties["apolloMarioBaseUrl"]
113
+ marioUrl = baseMarioUrl + "/apollo-mario/1.0/tenants/" + $domain_event.tenantId + "/projects/" + $domain_event.projectId + "/view-group-definitions/" + $domain_event.viewGroupDefinition + "/components/" + $domain_event.viewGroupComponent + "/topics/" + $domain_event.topic + "/domain-events/" + $domain_event.eventName
114
+ replace_environment_based_config_in_string(marioUrl, $environmentProperties)
115
+ if $operation == Operation::PUT
116
+ get_tenant_token_and_make_request(HTTP::PUT, $environment, $domain_event.tenantId, $domain_event.projectId, marioUrl,
117
+ replace_environment_based_config_in_string(JSON.generate($domain_event.requestBody), $environmentProperties))
118
+ return
119
+ end
120
+ if $operation == Operation::DELETE
121
+ get_tenant_token_and_make_request(HTTP::DELETE, $environment, $domain_event.tenantId, $domain_event.projectId, marioUrl)
122
+ end
123
+ end
124
+
125
+ def associate_user_details_transformer_in_request_body
126
+ userDetailsTransformerLocation = $domain_event.location + "/user_details_transformer.js"
127
+ userDetailsTransformer = File.read(userDetailsTransformerLocation)
128
+ raise_exception_if_string_empty(userDetailsTransformer, "user_details_transformer")
129
+ $domain_event.requestBody["userDetailsTransformer"] = userDetailsTransformer
130
+ end
131
+
132
+ def associate_view_group_context_transformer_in_request_body
133
+ viewGroupContextTransformerLocation = $domain_event.location + "/view_group_context_transformer.js"
134
+ viewGroupContextTransformer = File.read(viewGroupContextTransformerLocation)
135
+ raise_exception_if_string_empty(viewGroupContextTransformer, "view_group_context_transformer")
136
+ $domain_event.requestBody["viewGroupContextTransformer"] = "<% " + viewGroupContextTransformer + " %>"
137
+ end
138
+
139
+ def form_subscription_info
140
+ if $domain_event.requestBody["subscriptionInfo"] == nil
141
+ raise "No subscription Info Present in Domain Event Properties"
142
+ end
143
+ if $domain_event.requestBody["subscriptionInfo"]["topicTenantId"] == nil
144
+ raise "No topic tenant id present in subscription Info"
145
+ end
146
+ subscriptionTransformerLocation = $domain_event.location + "/atropos_subscription_transformer.js"
147
+ subscriptionTransformer = File.read(subscriptionTransformerLocation)
148
+ raise_exception_if_string_empty(subscriptionTransformer, "atropos_subscription_transformer")
149
+ $domain_event.requestBody["subscriptionInfo"]["transformer"] = replace_double_quote_with_single_quote(subscriptionTransformer)
150
+ # Only for prod. Remove when changes are deployed in prod
151
+ $domain_event.requestBody["subscribtionInfo"] = $domain_event.requestBody["subscriptionInfo"]
152
+ end
153
+
154
+ def associate_hars_with_in_request_body
155
+ return if File.directory?($domain_event.location + "/hars") == false
156
+ harsLocation = $domain_event.location + "/hars"
157
+ harsArr = []
158
+ Dir.entries(harsLocation).sort.each do |har|
159
+ next if har == '.' || har == '..' || har == '.DS_Store'
160
+ puts "har: #{har}"
161
+ harFile = File.read(harsLocation + "/" + har)
162
+ harJson = JSON.parse harFile
163
+ harJson = JSON.parse replace_single_quote(JSON.generate(harJson))
164
+ harsArr.push(harJson)
165
+ end
166
+ $domain_event.requestBody["hars"] = harsArr
167
+ end
168
+
169
+ def get_all_domain_events(env)
170
+ if env["is_local"] == "false"
171
+ load_environment_properties(env['environment'], env['tenant_id'], env['project_id'])
172
+ else
173
+ load_environment_properties_for_debug(env['environment'], env['tenant_id'], env['project_id'])
174
+ end
175
+ baseMarioUrl = $environmentProperties["apolloMarioBaseUrl"]
176
+ $environment = env['environment']
177
+ marioUrl = baseMarioUrl + "/apollo-mario/1.0/tenants/" + env["tenant_id"] + "/projects/" + env["project_id"] + "/domain-events"
178
+ if env["is_local"] == "false"
179
+ return get_tenant_token_and_make_request(HTTP::GET, $environment, env['tenant_id'], env['project_id'], marioUrl)
180
+ end
181
+ end
@@ -0,0 +1,20 @@
1
+ require 'open3'
2
+
3
+ class ExecuteShellCommand
4
+ def run_command(cmd)
5
+ post_content = "stdin"
6
+ stdout_str, stderr_str, exit_code = Open3.capture3(cmd, :stdin_data=>post_content)
7
+
8
+ # command output in console is printed in the following lines of code
9
+ puts stdout_str
10
+ puts stderr_str
11
+
12
+ # based on the result, success or error messages are returned.
13
+ # these logs are used to send flock notification
14
+ if exit_code == 0
15
+ return stdout_str
16
+ else
17
+ return stderr_str
18
+ end
19
+ end
20
+ end