lex-node 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +61 -0
  3. data/.gitignore +11 -0
  4. data/.idea/.rakeTasks +7 -0
  5. data/.idea/lex-node.iml +35 -0
  6. data/.idea/misc.xml +7 -0
  7. data/.idea/modules.xml +8 -0
  8. data/.idea/vagrant.xml +7 -0
  9. data/.idea/workspace.xml +13 -0
  10. data/.rspec +3 -0
  11. data/.rubocop.yml +25 -0
  12. data/Gemfile +4 -0
  13. data/Gemfile.lock +52 -0
  14. data/LICENSE.txt +21 -0
  15. data/README.md +40 -0
  16. data/Rakefile +6 -0
  17. data/bin/console +14 -0
  18. data/bin/setup +8 -0
  19. data/bitbucket-pipelines.yml +0 -0
  20. data/legion-extensions-node.gemspec +27 -0
  21. data/lib/legion/extensions/node.rb +10 -0
  22. data/lib/legion/extensions/node/actors/beat.rb +27 -0
  23. data/lib/legion/extensions/node/actors/crypt.rb +7 -0
  24. data/lib/legion/extensions/node/actors/push_key.rb +27 -0
  25. data/lib/legion/extensions/node/runners/beat.rb +13 -0
  26. data/lib/legion/extensions/node/runners/crypt.rb +62 -0
  27. data/lib/legion/extensions/node/runners/node.rb +42 -0
  28. data/lib/legion/extensions/node/transport.rb +12 -0
  29. data/lib/legion/extensions/node/transport/exchanges/node.rb +10 -0
  30. data/lib/legion/extensions/node/transport/messages/beat.rb +31 -0
  31. data/lib/legion/extensions/node/transport/messages/public_key.rb +17 -0
  32. data/lib/legion/extensions/node/transport/messages/push_cluster_secret.rb +32 -0
  33. data/lib/legion/extensions/node/transport/messages/request_cluster_secret.rb +19 -0
  34. data/lib/legion/extensions/node/transport/messages/request_public_keys.rb +15 -0
  35. data/lib/legion/extensions/node/transport/queues/health.rb +7 -0
  36. data/lib/legion/extensions/node/transport/queues/node.rb +13 -0
  37. data/lib/legion/extensions/node/version.rb +7 -0
  38. metadata +125 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5cdedcd97242200357d0c416e032ce60ec69cd0a26467d6d1f752e3bedea592a
4
+ data.tar.gz: fbb1923b3a4e98d0442f942048169efa941a6f82f242e90c548775c3b3e13dba
5
+ SHA512:
6
+ metadata.gz: 2038c463680688fb09b8ac991e66d08e6b93102ae3869b0f21ebbcdf19dd2baf8e4180a67db69a79f2902906079a08a9802dc5b7fe305d01afce0de44c0223d8
7
+ data.tar.gz: abb883b8ffdb0ff20116c150fa0b6f43d4dcdc6a5d05757ca5c22112944d3e2e34d1f55e63e8130aea504585ac6d54ca9fbb8502646035b231176e67b466c72f
@@ -0,0 +1,61 @@
1
+ version: 2.1
2
+ orbs:
3
+ ruby: circleci/ruby@0.2.1
4
+
5
+ jobs:
6
+ "rubocop":
7
+ docker:
8
+ - image: circleci/ruby:2.5-node
9
+ steps:
10
+ - checkout
11
+ - ruby/load-cache
12
+ - ruby/install-deps
13
+ - run:
14
+ name: Run Rubocop
15
+ command: bundle exec rubocop
16
+ - ruby/save-cache
17
+ "ruby-two-five":
18
+ docker:
19
+ - image: circleci/ruby:2.5
20
+ - image: memcached:1.5-alpine
21
+ steps:
22
+ - checkout
23
+ - ruby/load-cache
24
+ - ruby/install-deps
25
+ - ruby/run-tests
26
+ - ruby/save-cache
27
+ "ruby-two-six":
28
+ docker:
29
+ - image: circleci/ruby:2.6
30
+ - image: memcached:1.5-alpine
31
+ steps:
32
+ - checkout
33
+ - ruby/load-cache
34
+ - ruby/install-deps
35
+ - ruby/run-tests
36
+ - ruby/save-cache
37
+ "ruby-two-seven":
38
+ docker:
39
+ - image: circleci/ruby:2.7
40
+ - image: memcached:1.5-alpine
41
+ steps:
42
+ - checkout
43
+ - ruby/load-cache
44
+ - ruby/install-deps
45
+ - ruby/run-tests
46
+ - ruby/save-cache
47
+
48
+ workflows:
49
+ version: 2
50
+ rubocop-rspec:
51
+ jobs:
52
+ - rubocop
53
+ - ruby-two-five:
54
+ requires:
55
+ - rubocop
56
+ - ruby-two-six:
57
+ requires:
58
+ - ruby-two-five
59
+ - ruby-two-seven:
60
+ requires:
61
+ - ruby-two-five
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.idea/.rakeTasks ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build lex-node-0.1.0.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install lex-node-0.1.0.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install lex-node-0.1.0.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.1.0 and build and push lex-node-0.1.0.gem to rubygems.org" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="Run RSpec code examples" fullCmd="spec" taksId="spec" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
@@ -0,0 +1,35 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$">
8
+ <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
9
+ </content>
10
+ <orderEntry type="inheritedJdk" />
11
+ <orderEntry type="sourceFolder" forTests="false" />
12
+ <orderEntry type="library" scope="PROVIDED" name="ast (v2.4.0, RVM: ruby-2.6.3) [gem]" level="application" />
13
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.1.4, RVM: ruby-2.6.3) [gem]" level="application" />
14
+ <orderEntry type="library" scope="PROVIDED" name="chef (v15.8.23, RVM: ruby-2.6.3) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.3, RVM: ruby-2.6.3) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="jaro_winkler (v1.5.4, RVM: ruby-2.6.3) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="parallel (v1.19.1, RVM: ruby-2.6.3) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="parser (v2.7.0.4, RVM: ruby-2.6.3) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="rainbow (v3.0.0, RVM: ruby-2.6.3) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="rake (v13.0.1, RVM: ruby-2.6.3) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.4, RVM: ruby-2.6.3) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="rspec (v3.9.0, RVM: ruby-2.6.3) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.9.1, RVM: ruby-2.6.3) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.9.0, RVM: ruby-2.6.3) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.9.1, RVM: ruby-2.6.3) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.9.2, RVM: ruby-2.6.3) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="rubocop (v0.80.1, RVM: ruby-2.6.3) [gem]" level="application" />
28
+ <orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.10.1, RVM: ruby-2.6.3) [gem]" level="application" />
29
+ <orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v1.6.1, RVM: ruby-2.6.3) [gem]" level="application" />
30
+ </component>
31
+ <component name="RModuleSettingsStorage">
32
+ <LOAD_PATH number="1" string0="$MODULE_DIR$/lib/legion" />
33
+ <I18N_FOLDERS number="0" />
34
+ </component>
35
+ </module>
data/.idea/misc.xml ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="JavaScriptSettings">
4
+ <option name="languageLevel" value="ES6" />
5
+ </component>
6
+ <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-2.6.3" project-jdk-type="RUBY_SDK" />
7
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/lex-node.iml" filepath="$PROJECT_DIR$/.idea/lex-node.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/vagrant.xml ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VagrantProjectSettings">
4
+ <option name="instanceFolder" value="" />
5
+ <option name="provider" value="" />
6
+ </component>
7
+ </project>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="CoverageOptionsProvider">
4
+ <option name="myAddOrReplace" value="0" />
5
+ </component>
6
+ <component name="Git.Settings">
7
+ <option name="PUSH_AUTO_UPDATE" value="true" />
8
+ <option name="ROOT_SYNC" value="DONT_SYNC" />
9
+ </component>
10
+ <component name="PropertiesComponent">
11
+ <property name="settings.editor.selected.configurable" value="reference.settingsdialog.project.vagrant" />
12
+ </component>
13
+ </project>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ Layout/LineLength:
2
+ Max: 120
3
+ Metrics/MethodLength:
4
+ Max: 30
5
+ Metrics/ClassLength:
6
+ Max: 1500
7
+ Metrics/BlockLength:
8
+ Max: 50
9
+ Layout/SpaceAroundEqualsInParameterDefault:
10
+ EnforcedStyle: space
11
+ Style/SymbolArray:
12
+ Enabled: true
13
+ Layout/HashAlignment:
14
+ EnforcedHashRocketStyle: table
15
+ EnforcedColonStyle: table
16
+ Style/Documentation:
17
+ Enabled: false
18
+ AllCops:
19
+ TargetRubyVersion: 2.5
20
+ Style/FrozenStringLiteralComment:
21
+ Enabled: false
22
+ Naming/FileName:
23
+ Enabled: false
24
+ Style/ClassAndModuleChildren:
25
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in legion-extensions-node.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lex-node (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ diff-lcs (1.3)
11
+ jaro_winkler (1.5.4)
12
+ parallel (1.19.1)
13
+ parser (2.7.0.4)
14
+ ast (~> 2.4.0)
15
+ rainbow (3.0.0)
16
+ rake (13.0.1)
17
+ rexml (3.2.4)
18
+ rspec (3.9.0)
19
+ rspec-core (~> 3.9.0)
20
+ rspec-expectations (~> 3.9.0)
21
+ rspec-mocks (~> 3.9.0)
22
+ rspec-core (3.9.1)
23
+ rspec-support (~> 3.9.1)
24
+ rspec-expectations (3.9.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.9.0)
27
+ rspec-mocks (3.9.1)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.9.0)
30
+ rspec-support (3.9.2)
31
+ rubocop (0.80.1)
32
+ jaro_winkler (~> 1.5.1)
33
+ parallel (~> 1.10)
34
+ parser (>= 2.7.0.1)
35
+ rainbow (>= 2.2.2, < 4.0)
36
+ rexml
37
+ ruby-progressbar (~> 1.7)
38
+ unicode-display_width (>= 1.4.0, < 1.7)
39
+ ruby-progressbar (1.10.1)
40
+ unicode-display_width (1.6.1)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ lex-node!
47
+ rake
48
+ rspec
49
+ rubocop
50
+
51
+ BUNDLED WITH
52
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Esity
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # Legion::Extensions::Node
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/legion/extensions/node`. 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 'legion-extensions-node'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install legion-extensions-node
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. Then, run `rake spec` to run the tests. 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]/legion-extensions-node.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'legion/extensions/node'
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
File without changes
@@ -0,0 +1,27 @@
1
+ require_relative 'lib/legion/extensions/node/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'lex-node'
5
+ spec.version = Legion::Extensions::Node::VERSION
6
+ spec.authors = ['Esity']
7
+ spec.email = ['matthewdiverson@gmail.com']
8
+
9
+ spec.summary = 'Does Legion Node things'
10
+ spec.description = 'This lex is responsible for sending heartbeats, and allowing for dynamic confgs'
11
+ spec.homepage = 'https://bitbucket.org/legion-io/lex-node/CHANGELOG.md'
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
14
+
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = 'https://bitbucket.org/legion-io/lex-node/src/'
17
+ spec.metadata['changelog_uri'] = 'https://bitbucket.org/legion-io/lex-node/CHANGELOG.md'
18
+
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'rubocop'
27
+ end
@@ -0,0 +1,10 @@
1
+ require 'legion/extensions/node/version'
2
+ require 'legion/extensions'
3
+
4
+ module Legion
5
+ module Extensions
6
+ module Node
7
+ extend Legion::Extensions::Core
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ module Legion::Extensions::Node::Actor
2
+ class Beat < Legion::Extensions::Actors::Every
3
+ def runner_function
4
+ 'beat'
5
+ end
6
+
7
+ def use_runner?
8
+ false
9
+ end
10
+
11
+ def check_subtask?
12
+ false
13
+ end
14
+
15
+ def generate_task?
16
+ false
17
+ end
18
+
19
+ def run_now?
20
+ true
21
+ end
22
+
23
+ def time
24
+ 1
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ module Legion::Extensions::Node::Actor
2
+ class Crypt < Legion::Extensions::Actors::Subscription
3
+ def delay_start
4
+ 2
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ module Legion::Extensions::Node::Actor
2
+ class PushKey < Legion::Extensions::Actors::Once
3
+ def function
4
+ 'request_public_keys'
5
+ end
6
+
7
+ def runner_class
8
+ Legion::Extensions::Node::Runners::Crypt
9
+ end
10
+
11
+ def disabled?
12
+ true
13
+ end
14
+
15
+ def use_runner?
16
+ true
17
+ end
18
+
19
+ def check_subtask?
20
+ false
21
+ end
22
+
23
+ def generate_task?
24
+ false
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ module Legion::Extensions::Node::Runners
2
+ module Beat
3
+ include Legion::Extensions::Helpers::Transport
4
+
5
+ def beat(status: 'healthy', **opts)
6
+ log.debug 'sending hearbeat'
7
+ messages::Beat.new(status: status).publish
8
+ { success: true, status: status, **opts }
9
+ end
10
+
11
+ include Legion::Extensions::Helpers::Lex
12
+ end
13
+ end
@@ -0,0 +1,62 @@
1
+ module Legion::Extensions::Node::Runners
2
+ module Crypt
3
+ include Legion::Extensions::Helpers::Lex
4
+
5
+ def self.push_public_key(**_opts)
6
+ log.debug 'push_public_key'
7
+ message_hash = { function: 'update_public_key',
8
+ public_key: Base64.encode64(Legion::Crypt.public_key),
9
+ **Legion::Settings[:client] }
10
+ Legion::Extensions::Node::Transport::Messages::PublicKey.new(message_hash).publish
11
+ {}
12
+ end
13
+
14
+ def self.update_public_key(name:, public_key:, **_opts)
15
+ log.debug 'update_public_key'
16
+ Legion::Settings[:cluster][:public_keys][name] = public_key
17
+ {}
18
+ end
19
+
20
+ def self.delete_public_key(name:, **_opts)
21
+ log.debug 'delete_public_key'
22
+ Legion::Settings[:cluster][:public_keys].delete(name)
23
+ {}
24
+ end
25
+
26
+ def self.request_public_keys(**_opts)
27
+ log.debug 'request_public_keys'
28
+ message_hash = { function: 'push_public_key' }
29
+ Legion::Extensions::Node::Transport::Messages::RequestPublicKeys.new(message_hash).publish
30
+ {}
31
+ end
32
+
33
+ def self.request_cluster_secret(**_opts)
34
+ log.debug 'request_cluster_secret'
35
+ Legion::Transport::Messages::RequestClusterSecret.new.publish
36
+ {}
37
+ end
38
+
39
+ def self.push_cluster_secret(public_key:, queue_name:, **_opts)
40
+ log.debug 'push_cluster_secret'
41
+ return {} unless Legion::Settings[:crypt][:cs_encrypt_ready]
42
+
43
+ encrypted = Legion::Crypt.encrypt_from_keypair(public_key: public_key,
44
+ message: Legion::Settings[:crypt][:cluster_secret].to_s)
45
+ legion = Legion::Crypt.encrypt('legion')
46
+ Legion::Extensions::Node::Transport::Messages::PushClusterSecret.new(message: encrypted,
47
+ queue_name: queue_name,
48
+ validation_string: 'legion',
49
+ encrypted_string: legion).publish
50
+ {}
51
+ end
52
+
53
+ def self.receive_cluster_secret(public_key:, message:, **opts)
54
+ log.debug 'receive_cluster_secret'
55
+ log.debug opts
56
+ Legion::Settings[:crypt][:cluster_secret] = Legion::Crypt.decrypt_from_keypair(public_key, message)
57
+ Legion::Settings[:crypt][:encrypted_string] = opts[:encrypted_string]
58
+ Legion::Settings[:crypt][:validation_string] = opts[:validation_string]
59
+ {}
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,42 @@
1
+ module Legion::Extensions::Node::Runners
2
+ module Node
3
+ include Legion::Extensions::Helpers::Lex
4
+
5
+ def self.message(_options = {}, **hash)
6
+ log.debug 'message'
7
+ hash.each do |k, v|
8
+ raise 'Cannot override base setting that doesn\'t exist' if Legion::Settings[k].nil?
9
+
10
+ if v.is_a? String
11
+ Legion::Settings[k] = v
12
+ elsif v.is_a? Hash
13
+ v.each do |key, value|
14
+ Legion::Settings[k][key] = value
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ def self.push_public_key(**_opts)
21
+ log.debug 'push_public_key'
22
+ message_hash = { function: 'update_public_key',
23
+ public_key: Legion::Crypt.public_key.to_s,
24
+ **Legion::Settings[:client] }
25
+ Legion::Extensions::Node::Transport::Messages::PublicKey.new(message_hash).publish
26
+ {}
27
+ end
28
+
29
+ def self.update_public_key(name:, public_key:, **_opts)
30
+ log.debug 'update_public_key'
31
+ Legion::Settings[:cluster][:public_keys][name] = public_key
32
+ {}
33
+ end
34
+
35
+ def self.receive_cluster_secret(public_key:, message:, **_opts)
36
+ log.debug 'receive_cluster_secret'
37
+ Legion::Settings[:crypt][:cluster_secret] = Legion::Crypt.decrypt_from_keypair(public_key: public_key,
38
+ message: message)
39
+ {}
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,12 @@
1
+ require 'legion/extensions/transport'
2
+
3
+ module Legion::Extensions::Node::Transport
4
+ extend Legion::Extensions::Transport
5
+ def self.additional_e_to_q
6
+ array = [{ from: 'node', to: 'node', routing_key: "node.#{Legion::Settings['client']['name']}" }]
7
+ array.push(from: 'node', to: 'node', routing_key: 'node.data.#') if Legion::Settings[:data][:connected]
8
+ array.push(from: 'node', to: 'node', routing_key: 'node.cache.#') if Legion::Settings[:cache][:connected]
9
+ array.push(from: 'node', to: 'node', routing_key: 'node.crypt.#')
10
+ array
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ require 'legion/transport/exchanges/node'
2
+
3
+ module Legion::Extensions::Node
4
+ module Transport
5
+ module Exchanges
6
+ class Node < Legion::Transport::Exchanges::Node
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,31 @@
1
+ module Legion::Extensions::Node::Transport::Messages
2
+ class Beat < Legion::Transport::Message
3
+ def routing_key
4
+ 'health'
5
+ end
6
+
7
+ def type
8
+ 'heartbeat'
9
+ end
10
+
11
+ def expiration
12
+ 5000
13
+ end
14
+
15
+ def encrypt?
16
+ false
17
+ end
18
+
19
+ def message
20
+ hash = { hostname: Legion::Settings[:client][:hostname], pid: Process.pid, timestamp: Time.now }
21
+ hash[:status] = @options[:status].nil? ? 'healthy' : @options[:status]
22
+ hash
23
+ end
24
+
25
+ def validate
26
+ raise 'status should be a string' unless @options[:status].is_a?(String) || @options[:status].nil?
27
+
28
+ @valid = true
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,17 @@
1
+ module Legion::Extensions::Node::Transport::Messages
2
+ class PublicKey < Legion::Transport::Message
3
+ def routing_key
4
+ 'node.crypt.update_public_key'
5
+ end
6
+
7
+ def type
8
+ 'task'
9
+ end
10
+
11
+ def validate
12
+ raise 'public_key should be a string' unless @options[:public_key].is_a?(String)
13
+
14
+ @valid = true
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,32 @@
1
+ module Legion::Extensions::Node::Transport::Messages
2
+ class PushClusterSecret < Legion::Transport::Message
3
+ def routing_key
4
+ @options[:queue_name]
5
+ end
6
+
7
+ def exchange
8
+ Legion::Transport::Exchanges::Node
9
+ end
10
+
11
+ def message
12
+ { function: 'receive_cluster_secret',
13
+ runner_class: 'Legion::Extensions::Node::Runners::Crypt',
14
+ message: @options[:message],
15
+ validation_string: @options[:validation_string] || nil,
16
+ encrypted_string: @options[:encrypted_string] || nil,
17
+ public_key: Base64.encode64(Legion::Crypt.public_key) }
18
+ end
19
+
20
+ def type
21
+ 'task'
22
+ end
23
+
24
+ def encrypt?
25
+ false
26
+ end
27
+
28
+ def validate
29
+ @valid = true
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ module Legion::Extensions::Node::Transport::Messages
2
+ class RequestClusterSecret < Legion::Transport::Message
3
+ def routing_key
4
+ 'node.crypt.push_cluster_secret'
5
+ end
6
+
7
+ def message
8
+ { function: 'push_cluster_secret', node_name: Legion::Settings[:client][:name] }
9
+ end
10
+
11
+ def type
12
+ 'task'
13
+ end
14
+
15
+ def validate
16
+ @valid = true
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ module Legion::Extensions::Node::Transport::Messages
2
+ class RequestPublicKeys < Legion::Transport::Message
3
+ def routing_key
4
+ 'node'
5
+ end
6
+
7
+ def type
8
+ 'task'
9
+ end
10
+
11
+ def validate
12
+ @valid = true
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module Legion::Extensions::Node::Transport::Queues
2
+ class Health < Legion::Transport::Queue
3
+ def queue_options
4
+ { arguments: { 'x-single-active-consumer': true }, auto_delete: false }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ require 'socket'
2
+
3
+ module Legion::Extensions::Node::Transport::Queues
4
+ class Node < Legion::Transport::Queue
5
+ def queue_name
6
+ "node.#{Legion::Settings['client']['name']}"
7
+ end
8
+
9
+ def queue_options
10
+ { durable: false, exclusive: true, auto_delete: true }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module Legion
2
+ module Extensions
3
+ module Node
4
+ VERSION = '0.1.0'.freeze
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lex-node
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Esity
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: This lex is responsible for sending heartbeats, and allowing for dynamic
56
+ confgs
57
+ email:
58
+ - matthewdiverson@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".circleci/config.yml"
64
+ - ".gitignore"
65
+ - ".idea/.rakeTasks"
66
+ - ".idea/lex-node.iml"
67
+ - ".idea/misc.xml"
68
+ - ".idea/modules.xml"
69
+ - ".idea/vagrant.xml"
70
+ - ".idea/workspace.xml"
71
+ - ".rspec"
72
+ - ".rubocop.yml"
73
+ - Gemfile
74
+ - Gemfile.lock
75
+ - LICENSE.txt
76
+ - README.md
77
+ - Rakefile
78
+ - bin/console
79
+ - bin/setup
80
+ - bitbucket-pipelines.yml
81
+ - legion-extensions-node.gemspec
82
+ - lib/legion/extensions/node.rb
83
+ - lib/legion/extensions/node/actors/beat.rb
84
+ - lib/legion/extensions/node/actors/crypt.rb
85
+ - lib/legion/extensions/node/actors/push_key.rb
86
+ - lib/legion/extensions/node/runners/beat.rb
87
+ - lib/legion/extensions/node/runners/crypt.rb
88
+ - lib/legion/extensions/node/runners/node.rb
89
+ - lib/legion/extensions/node/transport.rb
90
+ - lib/legion/extensions/node/transport/exchanges/node.rb
91
+ - lib/legion/extensions/node/transport/messages/beat.rb
92
+ - lib/legion/extensions/node/transport/messages/public_key.rb
93
+ - lib/legion/extensions/node/transport/messages/push_cluster_secret.rb
94
+ - lib/legion/extensions/node/transport/messages/request_cluster_secret.rb
95
+ - lib/legion/extensions/node/transport/messages/request_public_keys.rb
96
+ - lib/legion/extensions/node/transport/queues/health.rb
97
+ - lib/legion/extensions/node/transport/queues/node.rb
98
+ - lib/legion/extensions/node/version.rb
99
+ homepage: https://bitbucket.org/legion-io/lex-node/CHANGELOG.md
100
+ licenses:
101
+ - MIT
102
+ metadata:
103
+ homepage_uri: https://bitbucket.org/legion-io/lex-node/CHANGELOG.md
104
+ source_code_uri: https://bitbucket.org/legion-io/lex-node/src/
105
+ changelog_uri: https://bitbucket.org/legion-io/lex-node/CHANGELOG.md
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: 2.3.0
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubygems_version: 3.0.8
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Does Legion Node things
125
+ test_files: []