legionio 0.3.5 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rspec.yml +45 -0
  3. data/.github/workflows/rubocop.yml +28 -0
  4. data/.github/workflows/sourcehawk-scan.yml +20 -0
  5. data/.gitignore +15 -0
  6. data/.rubocop.yml +90 -0
  7. data/CHANGELOG.md +4 -0
  8. data/CODE_OF_CONDUCT.md +75 -0
  9. data/CONTRIBUTING.md +55 -0
  10. data/Dockerfile +9 -0
  11. data/Gemfile +10 -0
  12. data/INDIVIDUAL_CONTRIBUTOR_LICENSE.md +30 -0
  13. data/LICENSE +201 -0
  14. data/NOTICE.txt +9 -0
  15. data/README.md +162 -0
  16. data/SECURITY.md +9 -0
  17. data/attribution.txt +1 -0
  18. data/docker_deploy.rb +10 -0
  19. data/exe/legion +4 -0
  20. data/exe/legionio +53 -0
  21. data/exe/lex_gen +5 -0
  22. data/legionio.gemspec +53 -0
  23. data/lib/legion.rb +24 -0
  24. data/lib/legion/cli.rb +56 -0
  25. data/lib/legion/cli/chain.rb +35 -0
  26. data/lib/legion/cli/cohort.rb +10 -0
  27. data/lib/legion/cli/function.rb +41 -0
  28. data/lib/legion/cli/lex/actor.rb +31 -0
  29. data/lib/legion/cli/lex/exchange.rb +32 -0
  30. data/lib/legion/cli/lex/message.rb +32 -0
  31. data/lib/legion/cli/lex/queue.rb +45 -0
  32. data/lib/legion/cli/lex/runner.rb +70 -0
  33. data/lib/legion/cli/lex/templates/actor.erb +6 -0
  34. data/lib/legion/cli/lex/templates/actor_spec.erb +0 -0
  35. data/lib/legion/cli/lex/templates/base/bitbucket.yml.erb +69 -0
  36. data/lib/legion/cli/lex/templates/base/gemfile.erb +3 -0
  37. data/lib/legion/cli/lex/templates/base/gemspec.erb +26 -0
  38. data/lib/legion/cli/lex/templates/base/gitignore.erb +11 -0
  39. data/lib/legion/cli/lex/templates/base/lex.erb +9 -0
  40. data/lib/legion/cli/lex/templates/base/lex_spec.erb +5 -0
  41. data/lib/legion/cli/lex/templates/base/lic.erb +21 -0
  42. data/lib/legion/cli/lex/templates/base/rakefile.erb +6 -0
  43. data/lib/legion/cli/lex/templates/base/readme.md.erb +2 -0
  44. data/lib/legion/cli/lex/templates/base/rubocop.yml.erb +15 -0
  45. data/lib/legion/cli/lex/templates/base/spec_helper.rb.erb +11 -0
  46. data/lib/legion/cli/lex/templates/base/version.erb +7 -0
  47. data/lib/legion/cli/lex/templates/exchange.erb +11 -0
  48. data/lib/legion/cli/lex/templates/exchange_spec.erb +0 -0
  49. data/lib/legion/cli/lex/templates/message.erb +23 -0
  50. data/lib/legion/cli/lex/templates/message_spec.erb +0 -0
  51. data/lib/legion/cli/lex/templates/queue.erb +12 -0
  52. data/lib/legion/cli/lex/templates/queue_helper.erb +24 -0
  53. data/lib/legion/cli/lex/templates/queue_spec.erb +11 -0
  54. data/lib/legion/cli/lex/templates/runner.erb +11 -0
  55. data/lib/legion/cli/lex/templates/runner_spec.erb +11 -0
  56. data/lib/legion/cli/relationship.rb +22 -0
  57. data/lib/legion/cli/task.rb +49 -0
  58. data/lib/legion/cli/trigger.rb +88 -0
  59. data/lib/legion/cli/version.rb +5 -0
  60. data/lib/legion/extensions.rb +229 -0
  61. data/lib/legion/extensions/actors/base.rb +47 -0
  62. data/lib/legion/extensions/actors/defaults.rb +28 -0
  63. data/lib/legion/extensions/actors/every.rb +48 -0
  64. data/lib/legion/extensions/actors/loop.rb +32 -0
  65. data/lib/legion/extensions/actors/nothing.rb +15 -0
  66. data/lib/legion/extensions/actors/once.rb +40 -0
  67. data/lib/legion/extensions/actors/poll.rb +87 -0
  68. data/lib/legion/extensions/actors/subscription.rb +139 -0
  69. data/lib/legion/extensions/builders/actors.rb +61 -0
  70. data/lib/legion/extensions/builders/base.rb +36 -0
  71. data/lib/legion/extensions/builders/helpers.rb +24 -0
  72. data/lib/legion/extensions/builders/runners.rb +62 -0
  73. data/lib/legion/extensions/core.rb +131 -0
  74. data/lib/legion/extensions/data.rb +61 -0
  75. data/lib/legion/extensions/data/migrator.rb +33 -0
  76. data/lib/legion/extensions/data/model.rb +8 -0
  77. data/lib/legion/extensions/helpers/base.rb +82 -0
  78. data/lib/legion/extensions/helpers/cache.rb +23 -0
  79. data/lib/legion/extensions/helpers/core.rb +41 -0
  80. data/lib/legion/extensions/helpers/data.rb +23 -0
  81. data/lib/legion/extensions/helpers/lex.rb +48 -0
  82. data/lib/legion/extensions/helpers/logger.rb +44 -0
  83. data/lib/legion/extensions/helpers/task.rb +60 -0
  84. data/lib/legion/extensions/helpers/transport.rb +44 -0
  85. data/lib/legion/extensions/transport.rb +159 -0
  86. data/lib/legion/lex.rb +89 -0
  87. data/lib/legion/process.rb +124 -0
  88. data/lib/legion/runner.rb +57 -0
  89. data/lib/legion/runner/log.rb +10 -0
  90. data/lib/legion/runner/status.rb +69 -0
  91. data/lib/legion/service.rb +130 -0
  92. data/lib/legion/supervision.rb +15 -0
  93. data/lib/legion/version.rb +3 -0
  94. data/sourcehawk.yml +4 -0
  95. metadata +142 -168
@@ -0,0 +1,41 @@
1
+ module Legion
2
+ class Cli
3
+ class Function < Thor
4
+ desc 'find', 'find'
5
+ option :internal, type: :boolean, default: false
6
+ def find
7
+ Legion::Service.new(cache: false, crypt: false, extensions: false, log_level: 'error')
8
+ response = ask 'trigger extension?', limited_to: Legion::Data::Model::Extension.map(:name)
9
+ trigger_extension = Legion::Data::Model::Extension.where(name: response).first
10
+ runners = Legion::Data::Model::Runner.where(extension_id: trigger_extension.values[:id])
11
+ if runners.count == 1
12
+ trigger_runner = runners.first
13
+ say "Auto selecting #{trigger_runner.values[:name]} since it is the only option"
14
+ else
15
+ response = ask 'trigger runner?', limited_to: runners.map(:name)
16
+ trigger_runner = Legion::Data::Model::Runner.where(name: response).where(extension_id: trigger_extension.values[:id]).first
17
+ end
18
+
19
+ functions = Legion::Data::Model::Function.where(runner_id: trigger_runner.values[:id])
20
+
21
+ if functions.count == 1
22
+ trigger_function = functions.first
23
+ say "Auto selecting #{trigger_function.values[:name]} since it is the only option"
24
+ else
25
+ response = ask 'trigger function?', limited_to: Legion::Data::Model::Function.where(runner_id: trigger_runner.values[:id]).map(:name)
26
+ trigger_function = trigger_runner.functions(name: response).first
27
+ end
28
+ # say "#{trigger_runner.values[:namespace]}.#{trigger_function.values[:name]} selected as trigger", :green, :italicized
29
+ # mute { trigger_function.values[:id] }
30
+ say trigger_function.values[:id]
31
+ # puts self.methods(false)
32
+ end
33
+
34
+ desc 'delete', 'delete'
35
+ def delete; end
36
+
37
+ desc 'activate', 'activate'
38
+ def activate; end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,31 @@
1
+ module Legion
2
+ class Cli
3
+ module Lex
4
+ class Actor < Thor
5
+ include Thor::Actions
6
+
7
+ def self.source_root
8
+ File.dirname(__FILE__)
9
+ end
10
+
11
+ no_commands do
12
+ def lex
13
+ Dir.pwd.split('/').last.split('-').last
14
+ end
15
+ end
16
+
17
+ desc 'create :name', 'creates a new actor'
18
+ method_option :type, enum: %w[subscription every poll once loop], default: 'subscription'
19
+ def create(name)
20
+ template('templates/actor.erb', "#{lex}/lib/actors/#{name}.rb", { name: name, lex: lex, type: options[:type] })
21
+ end
22
+
23
+ desc 'delete :name', 'deletes an actor'
24
+ def delete(name)
25
+ remove_file("lib/legion/extensions/#{lex}/actors/#{name}.rb")
26
+ remove_file("spec/actors/#{name}_spec.rb")
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,32 @@
1
+ module Legion
2
+ class Cli
3
+ module Lex
4
+ class Exchange < Thor
5
+ include Thor::Actions
6
+
7
+ def self.source_root
8
+ File.dirname(__FILE__)
9
+ end
10
+
11
+ no_commands do
12
+ def lex
13
+ Dir.pwd.split('/').last.split('-').last
14
+ end
15
+ end
16
+
17
+ desc 'create :name', 'creates a new exchange class'
18
+ def create(name)
19
+ template('templates/queue.erb', "lib/legion/extensions/#{lex}/transport/exchanges/#{name}.rb", { name: name, lex: lex })
20
+ template('templates/queue_spec.erb', "spec/exchanges/#{name}_spec.rb", { name: name, lex: lex })
21
+ end
22
+
23
+ desc 'delete :name', 'deletes an exchange class'
24
+ def delete(name)
25
+ remove_file("lib/legion/extensions/#{lex}/transport/exchanges/#{name}.rb")
26
+ remove_file("spec/exchanges/#{name}_spec.rb")
27
+ remove_file("spec/transport/exchanges/#{name}_spec.rb")
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ module Legion
2
+ class Cli
3
+ module Lex
4
+ class Message < Thor
5
+ include Thor::Actions
6
+
7
+ def self.source_root
8
+ File.dirname(__FILE__)
9
+ end
10
+
11
+ no_commands do
12
+ def lex
13
+ Dir.pwd.split('/').last.split('-').last
14
+ end
15
+ end
16
+
17
+ desc 'create :name', 'creates a new message'
18
+ def create(name)
19
+ template('templates/message.erb', "lib/legion/extensions/#{lex}/transport/messages/#{name}.rb", { name: name, lex: lex })
20
+ template('templates/message_spec.erb', "spec/messages/#{name}_spec.rb", { name: name, lex: lex })
21
+ end
22
+
23
+ desc 'delete :name', 'deletes a message class'
24
+ def delete(name)
25
+ remove_file("lib/legion/extensions/#{lex}/transport/messages/#{name}.rb")
26
+ remove_file("spec/messages/#{name}_spec.rb")
27
+ remove_file("spec/transport/messages/#{name}_spec.rb")
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,45 @@
1
+ module Legion
2
+ class Cli
3
+ module Lex
4
+ class Queue < Thor
5
+ include Thor::Actions
6
+
7
+ def self.source_root
8
+ File.dirname(__FILE__)
9
+ end
10
+
11
+ no_commands do
12
+ def lex
13
+ Dir.pwd.split('/').last.split('-').last
14
+ end
15
+ end
16
+
17
+ desc 'create :name', 'creates a new queue'
18
+ def create(name)
19
+ template('templates/queue_helper.erb', 'spec/queue_helper.rb')
20
+ template('templates/queue.erb',
21
+ "lib/legion/extensions/#{lex}/transport/queues/#{name}.rb",
22
+ { name: name, lex: lex })
23
+ template('templates/queue_spec.erb', "spec/queues/#{name}_spec.rb", { name: name, lex: lex })
24
+ end
25
+
26
+ desc 'delete :name', 'deletes a queue config file'
27
+ def delete(name)
28
+ remove_file("lib/legion/extensions/#{lex}/transport/queues/#{name}.rb")
29
+ remove_file("spec/queues/#{name}_spec.rb")
30
+ remove_file("spec/transport/queues/#{name}_spec.rb")
31
+
32
+ # puts Dir.pwd # /Users/miverso2/Rubymine/lex/wip/lex-conflux
33
+ if Dir.exist? "#{Dir.pwd}/lib/legion/extensions/#{lex}/transport/queues/"
34
+ remove_dir("#{Dir.pwd}/lib/legion/extensions/#{lex}/transport/queues") if Dir.empty?("#{Dir.pwd}/lib/legion/extensions/#{lex}/transport/queues/")
35
+ remove_dir("#{Dir.pwd}/lib/legion/extensions/#{lex}/transport") if Dir.empty?("#{Dir.pwd}/lib/legion/extensions/#{lex}/transport")
36
+ end
37
+
38
+ remove_dir("#{Dir.pwd}/spec/queues") if Dir.exist?("#{Dir.pwd}/spec/queues") && Dir.empty?("#{Dir.pwd}/spec/queues")
39
+
40
+ nil
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,70 @@
1
+ module Legion
2
+ class Cli
3
+ module Lex
4
+ class Runner < Thor
5
+ include Thor::Actions
6
+
7
+ def self.source_root
8
+ File.dirname(__FILE__)
9
+ end
10
+
11
+ no_commands do
12
+ def lex
13
+ Dir.pwd.split('/').last.split('-').last
14
+ end
15
+ end
16
+
17
+ desc 'delete :runner', 'deletes a runner'
18
+ def delete(name)
19
+ remove_file("lib/legion/extensions/#{lex}/runners/#{name}.rb")
20
+ remove_file("spec/runners/#{name}_spec.rb")
21
+ end
22
+
23
+ desc 'create name type', 'creates a new runner'
24
+ def create(name)
25
+ template('templates/runner.erb', "lib/legion/extensions/#{lex}/runners/#{name}.rb", { name: name, lex: lex })
26
+ template('templates/runner_spec.erb', "spec/runners/#{name}_spec.rb", { name: name, lex: lex })
27
+ end
28
+
29
+ desc 'add_function new_function_name *args', 'adds new function to runner, args optional'
30
+ def add_function(name, function, args = nil)
31
+ @arg_keys = []
32
+
33
+ if args.nil?
34
+ args = '**'
35
+ else
36
+ option_args = ''
37
+ required_args = ''
38
+ args.split(',').each do |arg|
39
+ key, value = arg.split('=')
40
+ @arg_keys.push key.to_s
41
+ if value.nil? || value.empty?
42
+ required_args.concat("#{key}:, ")
43
+ else
44
+ option_args.concat("#{key}: '#{value}', ")
45
+ end
46
+ end
47
+ args = required_args.concat(option_args, '**')
48
+ end
49
+ insert_into_file "lib/legion/extensions/#{lex}/runners/#{name}.rb",
50
+ after: "extend Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined? 'Helpers::Lex'\n" do
51
+ "
52
+ def #{function}(#{args})
53
+ { success: true }
54
+ end\n"
55
+ end
56
+
57
+ insert_into_file("spec/runners/#{name}_spec.rb", after: "it { should be_a Module }\n") do
58
+ result = " it { is_expected.to respond_to(:#{function}).with_any_keywords }\n"
59
+ result.concat " it { is_expected.to respond_to(:#{function}).with_keywords(:#{@arg_keys.join(', :')}) }\n" if @arg_keys.count.positive?
60
+ result
61
+ end
62
+
63
+ insert_into_file("spec/runners/#{name}_spec.rb", before: " end\n") do
64
+ " it('#{function} returns a success') { expect(test_class.#{function}[:success]).to eq true }\n"
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,6 @@
1
+ module Legion::Extensions::<%= config[:lex].split('_').collect(&:capitalize).join %>
2
+ module Actor
3
+ class <%= config[:name].split('_').collect(&:capitalize).join %> < Legion::Extensions::Actors::<%= config[:type].capitalize %>
4
+ end
5
+ end
6
+ end
File without changes
@@ -0,0 +1,69 @@
1
+ image: ruby:2.7
2
+
3
+ pipelines:
4
+ tags:
5
+ "v*":
6
+ - step:
7
+ name: Rubocop
8
+ caches:
9
+ - bundler
10
+ script:
11
+ - gem install rubocop
12
+ - gem update rubocop
13
+ - rubocop
14
+ - step:
15
+ name: RSpec
16
+ caches:
17
+ - bundler
18
+ script:
19
+ - gem install bundler
20
+ - gem update bundler
21
+ - bundle update
22
+ - bundle exec rspec
23
+ - step:
24
+ name: Push to RubyGems
25
+ deployment: RubyGems
26
+ script:
27
+ - gem install bundler gem-release rspec
28
+ - bundle install
29
+ - (umask 077 ; echo $gem_creds | base64 --decode > ~/.gem/credentials)
30
+ - gem release
31
+ artifacts:
32
+ - pkg/**
33
+ branches:
34
+ master:
35
+ - step:
36
+ caches:
37
+ - bundler
38
+ script:
39
+ - gem install rubocop
40
+ - gem update rubocop
41
+ - rubocop
42
+ - step:
43
+ caches:
44
+ - bundler
45
+ script:
46
+ - gem install bundler
47
+ - gem update bundler
48
+ - bundle update
49
+ - bundle exec rspec
50
+ develop:
51
+ - step:
52
+ caches:
53
+ - bundler
54
+ script:
55
+ - gem install rubocop
56
+ - gem update rubocop
57
+ - rubocop
58
+ - step:
59
+ caches:
60
+ - bundler
61
+ script:
62
+ - gem install bundler
63
+ - gem update bundler
64
+ - bundle update
65
+ - bundle exec rspec
66
+
67
+ definitions:
68
+ caches:
69
+ bundler: /usr/local/bundle
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,26 @@
1
+ require_relative 'lib/legion/extensions/<%= config[:lex] %>/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'lex-<%= config[:lex] %>'
5
+ spec.version = Legion::Extensions::<%= config[:class_name] %>::VERSION
6
+ spec.authors = ['Esity']
7
+ spec.email = ['matthewdiverson@gmail.com']
8
+
9
+ spec.summary = 'LEX::<%= config[:class_name] %>'
10
+ spec.description = 'Connects Legion to <%= config[:class_name] %>'
11
+ spec.homepage = 'https://bitbucket.org/legion-io/lex-<%= config[:lex] %>'
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
14
+
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = 'https://bitbucket.org/legion-io/lex-<%= config[:lex] %>/src'
17
+ spec.metadata['documentation_uri'] = 'https://legionio.atlassian.net/wiki/spaces/LEX/pages/'
18
+ spec.metadata['changelog_uri'] = 'https://legionio.atlassian.net/wiki/spaces/LEX/pages/'
19
+ spec.metadata['bug_tracker_uri'] = 'https://bitbucket.org/legion-io/lex-<%= config[:lex] %>/issues'
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'rubocop'
25
+ spec.add_development_dependency 'simplecov'
26
+ end
@@ -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
@@ -0,0 +1,9 @@
1
+ require 'legion/extensions/<%= config[:lex] %>/version'
2
+
3
+ module Legion
4
+ module Extensions
5
+ module <%= config[:class_name] %>
6
+ extend Legion::Extensions::Core if Legion::Extensions.const_defined? :Core
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ RSpec.describe Legion::Extensions::<%= config[:class_name] %> do
2
+ it 'has a version number' do
3
+ expect(Legion::Extensions::<%= config[:class_name] %>::VERSION).not_to be nil
4
+ end
5
+ end
@@ -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.
@@ -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
@@ -0,0 +1,2 @@
1
+ # Legion::Extensions::<%= config[:class_name] %>
2
+ Another Legion Extension
@@ -0,0 +1,15 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+ Metrics/MethodLength:
4
+ Max: 30
5
+ Metrics/ClassLength:
6
+ Max: 1500
7
+ Style/Documentation:
8
+ Enabled: false
9
+ AllCops:
10
+ TargetRubyVersion: 2.5
11
+ NewCops: enable
12
+ Style/FrozenStringLiteralComment:
13
+ Enabled: false
14
+ Naming/FileName:
15
+ Enabled: false