apollo_commons_ruby 0.7.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 (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/CODE_OF_CONDUCT.md +74 -0
  4. data/Gemfile +6 -0
  5. data/Gemfile.lock +19 -0
  6. data/README.md +40 -0
  7. data/Rakefile +2 -0
  8. data/apollo_commons_ruby-0.2.0.gem +0 -0
  9. data/apollo_commons_ruby-0.3.0.gem +0 -0
  10. data/apollo_commons_ruby-0.4.0.gem +0 -0
  11. data/apollo_commons_ruby-0.5.0.gem +0 -0
  12. data/apollo_commons_ruby-0.6.0.gem +0 -0
  13. data/apollo_commons_ruby.gemspec +26 -0
  14. data/bin/console +14 -0
  15. data/bin/setup +8 -0
  16. data/lib/apollo_commons_ruby.rb +34 -0
  17. data/lib/apollo_commons_ruby/DomainEvent.rb +122 -0
  18. data/lib/apollo_commons_ruby/FileUtils.rb +41 -0
  19. data/lib/apollo_commons_ruby/MarioEvent.rb +45 -0
  20. data/lib/apollo_commons_ruby/NetworkUtils.rb +67 -0
  21. data/lib/apollo_commons_ruby/Operation.rb +4 -0
  22. data/lib/apollo_commons_ruby/ResolveTemplate.rb +53 -0
  23. data/lib/apollo_commons_ruby/SecretConfig.rb +15 -0
  24. data/lib/apollo_commons_ruby/TemplateBuilder.rb +26 -0
  25. data/lib/apollo_commons_ruby/TemplatesHelper.rb +814 -0
  26. data/lib/apollo_commons_ruby/TemplatesRakefile.rb +816 -0
  27. data/lib/apollo_commons_ruby/ViewGroup.rb +62 -0
  28. data/lib/apollo_commons_ruby/ViewGroupComponent.rb +66 -0
  29. data/lib/apollo_commons_ruby/ViewGroupDefinition.rb +61 -0
  30. data/lib/tasks/add_translations.rake +9 -0
  31. data/lib/tasks/checkValidJson.rake +17 -0
  32. data/lib/tasks/delete_domain_event.rake +7 -0
  33. data/lib/tasks/delete_view_group.rake +7 -0
  34. data/lib/tasks/delete_view_group_component.rake +7 -0
  35. data/lib/tasks/delete_view_group_definition.rake +7 -0
  36. data/lib/tasks/deploy_all_templates.rake +7 -0
  37. data/lib/tasks/runTests.rake +27 -0
  38. data/lib/tasks/update_all.rake +36 -0
  39. data/lib/tasks/update_all_domain_events.rake +24 -0
  40. data/lib/tasks/update_all_view_group_components.rake +18 -0
  41. data/lib/tasks/update_domain_event.rake +11 -0
  42. data/lib/tasks/update_one_template.rake +42 -0
  43. data/lib/tasks/update_translations.rake +24 -0
  44. data/lib/tasks/update_view_group_component.rake +9 -0
  45. data/lib/tasks/update_view_group_definition.rake +7 -0
  46. data/lib/tasks/update_view_group_for_user_0.rake +36 -0
  47. data/lib/version.rb +3 -0
  48. metadata +91 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1209bbab616c107bf54448dcd426790c00d68b7bf7164f6d1a886a48576e72af
4
+ data.tar.gz: b5962d1cbd4726c3239545ff0055f9289b7155a2743255fe4fc0d02bc667fa38
5
+ SHA512:
6
+ metadata.gz: 5138c814c68b53f37b1d4dc73f933e3d1271153c62072d01b84bbfe3363115ec360d24d4015a6fb4ed86d323f374d5a540642654cb2727079855267fefcb9e89
7
+ data.tar.gz: 4450538d4e02a204e061f129aab9cfb67f580791cdd9078f952c2ec9f628a9206780a11ad1c5f0610f7274ab3f810b5eee4eba2574e2a0436edba86ee42b83d7
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -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.0)
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
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,26 @@
1
+ require_relative 'lib/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "apollo_commons_ruby"
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,34 @@
1
+ module MarioConfig
2
+ class RakeTasks
3
+ include Rake::DSL if defined? Rake::DSL
4
+ def install_tasks
5
+ load 'tasks/delete_domain_event.rake'
6
+ load 'tasks/delete_view_group_component.rake'
7
+ load 'tasks/delete_view_group_definition.rake'
8
+ load 'tasks/delete_view_group.rake'
9
+ load 'tasks/update_all_domain_events.rake'
10
+ load 'tasks/update_all_view_group_components.rake'
11
+ load 'tasks/update_all.rake'
12
+ load 'tasks/update_domain_event.rake'
13
+ load 'tasks/update_view_group_component.rake'
14
+ load 'tasks/update_view_group_definition.rake'
15
+ load 'tasks/update_view_group_for_user_0.rake'
16
+ end
17
+ end
18
+ end
19
+ MarioConfig::RakeTasks.new.install_tasks
20
+
21
+ module TemplatesTasks
22
+ class RakeTasks
23
+ include Rake::DSL if defined? Rake::DSL
24
+ def install_tasks
25
+ load 'tasks/add_translations.rake'
26
+ load 'tasks/checkValidJson.rake'
27
+ load 'tasks/deploy_all_templates.rake'
28
+ load 'tasks/runTests.rake'
29
+ load 'tasks/update_one_template.rake'
30
+ load 'tasks/update_translations.rake'
31
+ end
32
+ end
33
+ end
34
+ TemplatesTasks::RakeTasks.new.install_tasks
@@ -0,0 +1,122 @@
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
+ $domain_event = nil
12
+ $secretConfig = nil
13
+
14
+ class DomainEvent
15
+ attr_reader :tenantId
16
+ attr_reader :projectId
17
+ attr_reader :viewGroupDefinition
18
+ attr_reader :viewGroupComponent
19
+ attr_reader :topic
20
+ attr_reader :eventName
21
+ attr_reader :requestBody
22
+ attr_reader :location
23
+
24
+ def initialize(configuration_json, view_group_definition, view_group_component, topic, event_name)
25
+ @tenantId = configuration_json["tenantId"]
26
+ @projectId = configuration_json["projectId"]
27
+ @viewGroupDefinition = view_group_definition
28
+ @viewGroupComponent = view_group_component
29
+ @topic = topic
30
+ @eventName = event_name
31
+ @location = "./configs/" + view_group_definition + "/" + view_group_component + "/" + topic + "/" + event_name
32
+ domain_event_properties = File.read(location + "/domain_event_properties.json")
33
+ @requestBody = JSON.parse domain_event_properties
34
+ end
35
+ end
36
+
37
+ def handle_domain_event_task(env, operation)
38
+ viewGroupDefinitionName = env["view_group_definition"]
39
+ environment = env["environment"]
40
+ component = env["view_group_component"]
41
+ topic = env["topic"]
42
+ eventName = env["event_name"]
43
+ tenantId = ENV["tenant_id"]
44
+ projectId = ENV["project_id"]
45
+ handle_domain_event(viewGroupDefinitionName, environment, tenantId, projectId, component, topic, eventName, operation)
46
+ end
47
+
48
+ def handle_domain_event(viewGroupDefinitionName, environment, tenantId, projectId, component, topic, eventName, operation)
49
+ $operation = operation
50
+ load_environment_properties(environment, tenantId, projectId)
51
+ prepare_domain_event(viewGroupDefinitionName, component, topic, eventName)
52
+ perform_domain_event_operation
53
+ end
54
+
55
+ def prepare_domain_event(view_group_definition, component, topic, event_name)
56
+ puts "view_group_definition: #{view_group_definition}"
57
+ puts "component: #{component}"
58
+ puts "topic: #{topic}"
59
+ puts "event_name: #{event_name}"
60
+ $domain_event = DomainEvent.new($environmentProperties, view_group_definition, component, topic, event_name)
61
+ associate_user_details_transformer_in_request_body
62
+ associate_view_group_context_transformer_in_request_body
63
+ form_subscribtion_info
64
+ associate_hars_with_in_request_body
65
+ end
66
+
67
+ def perform_domain_event_operation
68
+ baseMarioUrl = $environmentProperties["apolloMarioBaseUrl"]
69
+ authToken = $secretConfig.authToken
70
+ 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
71
+ replace_environment_based_config_in_string(marioUrl, $environmentProperties)
72
+ if $operation == Operation::PUT
73
+ make_PUT_request(marioUrl,
74
+ replace_environment_based_config_in_string(JSON.generate($domain_event.requestBody), $environmentProperties),
75
+ authToken)
76
+ return
77
+ end
78
+ if $operation == Operation::DELETE
79
+ make_DELETE_request(marioUrl, authToken)
80
+ end
81
+ end
82
+
83
+ def associate_user_details_transformer_in_request_body
84
+ userDetailsTransformerLocation = $domain_event.location + "/user_details_transformer.js"
85
+ userDetailsTransformer = File.read(userDetailsTransformerLocation)
86
+ raise_exception_if_string_empty(userDetailsTransformer, "user_details_transformer")
87
+ $domain_event.requestBody["userDetailsTransformer"] = userDetailsTransformer
88
+ end
89
+
90
+ def associate_view_group_context_transformer_in_request_body
91
+ viewGroupContextTransformerLocation = $domain_event.location + "/view_group_context_transformer.js"
92
+ viewGroupContextTransformer = File.read(viewGroupContextTransformerLocation)
93
+ raise_exception_if_string_empty(viewGroupContextTransformer, "view_group_context_transformer")
94
+ $domain_event.requestBody["viewGroupContextTransformer"] = "<% " + viewGroupContextTransformer + " %>"
95
+ end
96
+
97
+ def form_subscribtion_info
98
+ if $domain_event.requestBody["subscribtionInfo"] == nil
99
+ raise "No subscribtion Info Present in Domain Event Properties"
100
+ end
101
+ if $domain_event.requestBody["subscribtionInfo"]["topicTenantId"] == nil
102
+ raise "No topic tenant id present in Subscribtion Info"
103
+ end
104
+ subscribtionTransformerLocation = $domain_event.location + "/atropos_subscribtion_transformer.js"
105
+ subscribtionTransformer = File.read(subscribtionTransformerLocation)
106
+ raise_exception_if_string_empty(subscribtionTransformer, "atropos_subscribtion_transformer")
107
+ $domain_event.requestBody["subscribtionInfo"]["transformer"] = subscribtionTransformer
108
+ end
109
+
110
+ def associate_hars_with_in_request_body
111
+ return if File.directory?($domain_event.location + "/hars") == false
112
+ harsLocation = $domain_event.location + "/hars"
113
+ harsArr = []
114
+ Dir.entries(harsLocation).sort.each do |har|
115
+ next if har == '.' || har == '..'
116
+ puts "har: #{har}"
117
+ harFile = File.read(harsLocation + "/" + har)
118
+ harJson = JSON.parse harFile
119
+ harsArr.push(harJson)
120
+ end
121
+ $domain_event.requestBody["hars"] = harsArr
122
+ end
@@ -0,0 +1,41 @@
1
+ require 'fileutils'
2
+ require 'json'
3
+ require 'pp'
4
+ require_relative './SecretConfig'
5
+
6
+ def load_environment_properties(environment)
7
+ environmentFile = File.read("./environments/" + environment + "/env.json")
8
+ $environmentProperties = JSON.parse environmentFile
9
+ $secretConfig = SecretConfig.new(environment)
10
+ end
11
+
12
+ def load_environment_properties(environment, tenantId, projectId)
13
+ if tenantId != nil && projectId != nil && file_exists?("./environments/" + environment + "/env_" + tenantId + "_" + projectId + ".json")
14
+ environmentFile = File.read("./environments/" + environment + "/env_" + tenantId + "_" + projectId + ".json")
15
+ else
16
+ environmentFile = File.read("./environments/" + environment + "/env.json")
17
+ end
18
+ $environmentProperties = JSON.parse environmentFile
19
+ $secretConfig = SecretConfig.new(environment)
20
+ end
21
+
22
+ def replace_environment_based_config_in_string(body, environment)
23
+ environment.each do |key, value|
24
+ substring_key = "<<" + key + ">>"
25
+ if body.include? substring_key
26
+ puts "Replacing " + substring_key
27
+ body.gsub! substring_key, value
28
+ end
29
+ end
30
+ if body.include? "\\n"
31
+ puts "Replacing " + "\\n"
32
+ body.gsub! "\\n", ""
33
+ end
34
+ return body
35
+ end
36
+
37
+ def raise_exception_if_string_empty(string, identifier)
38
+ if string == nil || string.empty?
39
+ raise "Empty " + identifier
40
+ end
41
+ 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