legionio 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -11
  3. data/README.md +4 -1
  4. data/bin/legion +6 -47
  5. data/docs/Makefile +20 -0
  6. data/docs/_build/doctrees/environment.pickle +0 -0
  7. data/docs/_build/doctrees/index.doctree +0 -0
  8. data/docs/_build/doctrees/overview.doctree +0 -0
  9. data/docs/_build/html/.buildinfo +4 -0
  10. data/docs/_build/html/_sources/index.rst.txt +28 -0
  11. data/docs/_build/html/_sources/overview.rst.txt +0 -0
  12. data/docs/_build/html/_static/alabaster.css +701 -0
  13. data/docs/_build/html/_static/basic.css +855 -0
  14. data/docs/_build/html/_static/custom.css +1 -0
  15. data/docs/_build/html/_static/doctools.js +315 -0
  16. data/docs/_build/html/_static/documentation_options.js +12 -0
  17. data/docs/_build/html/_static/file.png +0 -0
  18. data/docs/_build/html/_static/jquery-3.5.1.js +10872 -0
  19. data/docs/_build/html/_static/jquery.js +2 -0
  20. data/docs/_build/html/_static/language_data.js +297 -0
  21. data/docs/_build/html/_static/minus.png +0 -0
  22. data/docs/_build/html/_static/plus.png +0 -0
  23. data/docs/_build/html/_static/pygments.css +82 -0
  24. data/docs/_build/html/_static/searchtools.js +514 -0
  25. data/docs/_build/html/_static/underscore-1.3.1.js +999 -0
  26. data/docs/_build/html/_static/underscore.js +31 -0
  27. data/docs/_build/html/genindex.html +101 -0
  28. data/docs/_build/html/index.html +117 -0
  29. data/docs/_build/html/objects.inv +6 -0
  30. data/docs/_build/html/overview.html +98 -0
  31. data/docs/_build/html/search.html +110 -0
  32. data/docs/_build/html/searchindex.js +1 -0
  33. data/docs/conf.py +54 -0
  34. data/docs/index.rst +28 -0
  35. data/docs/make.bat +35 -0
  36. data/exe/legion +6 -4
  37. data/lib/legion/extensions.rb +23 -62
  38. data/lib/legion/extensions/builders/runners.rb +5 -0
  39. data/lib/legion/extensions/helpers/lex.rb +29 -1
  40. data/lib/legion/extensions/transport.rb +9 -7
  41. data/lib/legion/service.rb +23 -3
  42. data/lib/legion/version.rb +1 -1
  43. metadata +34 -3
  44. data/settings/client.json +0 -25
@@ -0,0 +1 @@
1
+ Search.setIndex({docnames:["index","overview"],envversion:{"sphinx.domains.c":2,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":3,"sphinx.domains.index":1,"sphinx.domains.javascript":2,"sphinx.domains.math":2,"sphinx.domains.python":2,"sphinx.domains.rst":2,"sphinx.domains.std":1,sphinx:56},filenames:["index.rst","overview.rst"],objects:{},objnames:{},objtypes:{},terms:{"class":0,"function":0,These:0,acknowledg:0,action:0,add:0,ani:0,call:0,can:0,chain:0,cluster:0,complex:0,connect:0,contain:0,content:[],creat:0,delet:0,design:0,exampl:0,extens:0,foobar:[],get:0,incid:0,index:[],input:0,instal:0,legion:0,lex:0,list:0,make:0,merg:0,modul:[],more:0,out:0,output:0,page:[],pagerduti:0,platform:0,project:0,relationship:0,resolv:0,runner:0,search:[],second:[],servic:0,them:0,thi:[],thing:0,think:0,trigger:0,updat:0,user:0,whatev:0,which:0,within:0,without:0,work:0,workflow:0,yaml:0,you:0,your:0},titles:["LegionIO Overview","<no title>"],titleterms:{about:0,document:[],indic:[],legionio:0,overview:0,tabl:[],test3:[],test:[],welcom:[]}})
@@ -0,0 +1,54 @@
1
+ # Configuration file for the Sphinx documentation builder.
2
+ #
3
+ # This file only contains a selection of the most common options. For a full
4
+ # list see the documentation:
5
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html
6
+
7
+ # -- Path setup --------------------------------------------------------------
8
+
9
+ # If extensions (or modules to document with autodoc) are in another directory,
10
+ # add these directories to sys.path here. If the directory is relative to the
11
+ # documentation root, use os.path.abspath to make it absolute, like shown here.
12
+ #
13
+ # import os
14
+ # import sys
15
+ # sys.path.insert(0, os.path.abspath('.'))
16
+
17
+
18
+ # -- Project information -----------------------------------------------------
19
+
20
+ project = 'LegionIO'
21
+ copyright = '2020, Esity'
22
+ author = 'Esity'
23
+
24
+ # The full version, including alpha/beta/rc tags
25
+ release = '0.3.1'
26
+
27
+
28
+ # -- General configuration ---------------------------------------------------
29
+
30
+ # Add any Sphinx extension module names here, as strings. They can be
31
+ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
32
+ # ones.
33
+ extensions = ['recommonmark']
34
+
35
+ # Add any paths that contain templates here, relative to this directory.
36
+ templates_path = ['_templates']
37
+
38
+ # List of patterns, relative to source directory, that match files and
39
+ # directories to ignore when looking for source files.
40
+ # This pattern also affects html_static_path and html_extra_path.
41
+ exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
42
+
43
+
44
+ # -- Options for HTML output -------------------------------------------------
45
+
46
+ # The theme to use for HTML and HTML Help pages. See the documentation for
47
+ # a list of builtin themes.
48
+ #
49
+ html_theme = 'alabaster'
50
+
51
+ # Add any paths that contain custom static files (such as style sheets) here,
52
+ # relative to this directory. They are copied after the builtin static files,
53
+ # so a file named "default.css" will overwrite the builtin "default.css".
54
+ html_static_path = ['_static']
@@ -0,0 +1,28 @@
1
+ .. LegionIO documentation master file, created by
2
+ sphinx-quickstart on Thu Oct 15 08:16:27 2020.
3
+ You can adapt this file completely to your liking, but it should at least
4
+ contain the root `toctree` directive.
5
+
6
+ LegionIO Overview
7
+ ==============================
8
+
9
+ About
10
+ ------------
11
+ LegionIO is a platform designed for connecting things. You install a LEX(Legion Extension)
12
+ which adds functionality to your Legion service?project?cluster? Whatever it's called.
13
+
14
+ A LEX contains 1 or more runners. Think of them as classes
15
+ A runner contains 1 or more functions. These are the things you can call and make relationships out of
16
+ Example
17
+
18
+ * Lex: pagerduty
19
+
20
+ * Runners: incident, user, service
21
+
22
+ * Functions within the incident runner: trigger, acknowledge, resolve, merge
23
+
24
+ * Functions within the services runner: create, delete, update, list, get
25
+
26
+ Any function can be a trigger or an action(the input or output in the relationship).
27
+
28
+ Legion works by creating chains of relationships to make make a complex workflow without complex yaml
@@ -0,0 +1,35 @@
1
+ @ECHO OFF
2
+
3
+ pushd %~dp0
4
+
5
+ REM Command file for Sphinx documentation
6
+
7
+ if "%SPHINXBUILD%" == "" (
8
+ set SPHINXBUILD=sphinx-build
9
+ )
10
+ set SOURCEDIR=.
11
+ set BUILDDIR=_build
12
+
13
+ if "%1" == "" goto help
14
+
15
+ %SPHINXBUILD% >NUL 2>NUL
16
+ if errorlevel 9009 (
17
+ echo.
18
+ echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19
+ echo.installed, then set the SPHINXBUILD environment variable to point
20
+ echo.to the full path of the 'sphinx-build' executable. Alternatively you
21
+ echo.may add the Sphinx directory to PATH.
22
+ echo.
23
+ echo.If you don't have Sphinx installed, grab it from
24
+ echo.http://sphinx-doc.org/
25
+ exit /b 1
26
+ )
27
+
28
+ %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29
+ goto end
30
+
31
+ :help
32
+ %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33
+
34
+ :end
35
+ popd
data/exe/legion CHANGED
@@ -44,7 +44,9 @@ op.on('-v', '--version') { options[:action] = :version }
44
44
  op.separator ''
45
45
  op.parse!(ARGV)
46
46
 
47
- require File.expand_path('lib/legion.rb') unless options[:action] == :help
48
- Legion.start
49
- require File.expand_path('lib/legion/process.rb') unless options[:action] == :help
50
- Legion::Process.new(options).run!
47
+ unless options[:action] == :help
48
+ require 'legion'
49
+ Legion.start
50
+ require 'legion/process'
51
+ Legion::Process.new(options).run!
52
+ end
@@ -136,8 +136,7 @@ module Legion
136
136
  end
137
137
 
138
138
  def gem_load(gem_name, name)
139
- gem_path = "#{Gem::Specification.find_by_name(gem_name).gem_dir}/lib/legion/extensions/#{name}"
140
- require gem_path
139
+ require "#{Gem::Specification.find_by_name(gem_name).gem_dir}/lib/legion/extensions/#{name}"
141
140
  true
142
141
  rescue LoadError => e
143
142
  Legion::Logging.error e.message
@@ -148,62 +147,6 @@ module Legion
148
147
 
149
148
  def find_extensions
150
149
  @extensions ||= {}
151
- # puts Gem.install('lex-esphome')
152
- # puts Gem::Installer.new('lex-esphome')
153
- # test = Gem::Installer.new('lex-esphome')
154
- # puts test.install
155
- # puts Gem::Dependency.new('lex-esphome')
156
- # $LOAD_PATH << "#{ENV['GEM_HOME']}/gems/lex-esphome-0.1.0/lib"
157
- # require 'legion/extensions/esphome'
158
- # $LOAD_PATH << "#{ENV['GEM_HOME']}/gems/lex-esphome-0.1.0/lib"
159
- # ENV['MY_RUBY_HOME'] #/Users/miverso2/.rvm/rubies/ruby-2.7.0
160
- # ENV['GEM_HOME'] # /Users/miverso2/.rvm/gems/ruby-2.7.0
161
- # require 'rubygems/dependency_installer.rb'
162
- # puts Gem::DependencyInstaller.new.install('lex-esphome')
163
- # puts Gem::Installer.new('lex-esphome').install
164
- # puts Gem::Installer.new('lex-esphome').ensure_loadable_spec
165
- # puts Gem.search('lex-esphome')
166
- # Gem.clear_paths
167
- # require 'legion/extensions/esphome'
168
-
169
- # puts Gem.use_gemdeps
170
- # pp Gem.gemdeps
171
- # puts 'gems things'
172
- # puts Gem.loaded_specs.key? 'lex-esphome'
173
- # pp Gem.loaded_specs.keys
174
- #
175
- # require 'rubygems'
176
- # require 'rubygems/command.rb'
177
- # require 'rubygems/dependency_installer.rb'
178
- #
179
- # Gem::Command.build_args = ARGV
180
- # inst = Gem::DependencyInstaller.new
181
- # puts inst.installed_gems
182
- # puts inst.install 'lex-esphome', install_as_default: true
183
- # puts inst.installed_gems
184
- # puts '....'
185
- # test = Gem::DependencyList.new
186
- # test.add(inst)
187
- # pp test.find_name('lex-esphome')
188
- # pp test.find_name('lex-logger')
189
- # pp test.specs
190
- # pp Gem::DependencyList.from_specs
191
- # pp Gem::DependencyList.from_specs.key? 'lex-logg'
192
- # pp inst
193
- #
194
- # pp Gem.new.all_specs
195
- # load 'legion/extensions/esphome.rb'
196
- # puts Gem.register_default_spec()
197
- # :use_gemdeps,
198
- # :detect_gemdeps,
199
- # :source_date_epoch,
200
- # :gemdeps,
201
- # :register_default_spec,
202
- # :find_unresolved_default_spec,
203
- # :clear_default_specs,
204
- # :loaded_specs,
205
- # :default_path,
206
-
207
150
  Gem::Specification.all_names.each do |gem|
208
151
  next unless gem[0..3] == 'lex-'
209
152
 
@@ -212,12 +155,30 @@ module Legion
212
155
  gem_name: "lex-#{lex[1]}",
213
156
  extension_name: lex[1],
214
157
  version: lex[2],
215
- extension_class: "Legion::Extensions::#{lex[1].capitalize}" }
158
+ extension_class: "Legion::Extensions::#{lex[1].split('_').collect(&:capitalize).join}" }
216
159
  end
217
160
 
218
- # Legion::Settings[:extensions].each do |extension|
219
- # puts extension unless @extensions.key? extension
220
- # end
161
+ Legion::Settings[:extensions].each do |extension, values|
162
+ next if @extensions.key? extension.to_s
163
+ next if values[:enabled] == false
164
+ next if values[:auto_install] == false
165
+
166
+ Legion::Logging.warn "#{extension} is missing, attempting to install automatically.."
167
+ install = Gem.install("lex-#{extension}")
168
+ Legion::Logging.debug(install)
169
+ lex = Gem::Specification.find_by_name("lex-#{extension}")
170
+
171
+ @extensions[extension.to_s] = {
172
+ full_gem_name: "lex-#{extension}-#{lex.version}",
173
+ gem_name: "lex-#{extension}",
174
+ extension_name: extension.to_s,
175
+ version: lex.version,
176
+ extension_class: "Legion::Extensions::#{extension.to_s.split('_').collect(&:capitalize).join}"
177
+ }
178
+
179
+ rescue StandardError, Gem::MissingSpecError => e
180
+ Legion::Logging.error "Failed to auto install #{extension}, e: #{e.message}"
181
+ end
221
182
  end
222
183
  end
223
184
  end
@@ -20,6 +20,7 @@ module Legion
20
20
  runner_name = file.split('/').last.sub('.rb', '')
21
21
  runner_class = "#{lex_class}::Runners::#{runner_name.split('_').collect(&:capitalize).join}"
22
22
  loaded_runner = Kernel.const_get(runner_class)
23
+
23
24
  @runners[runner_name.to_sym] = {
24
25
  extension: lex_class.to_s.downcase,
25
26
  extension_name: extension_name,
@@ -30,6 +31,10 @@ module Legion
30
31
  class_methods: {}
31
32
  }
32
33
 
34
+ if settings.key?(:runners) && settings[:runners].key?(runner_name.to_sym)
35
+ @runners[runner_name.to_sym][:desc] = settings[:runners][runner_name.to_sym][:desc]
36
+ end
37
+
33
38
  loaded_runner.public_instance_methods(false).each do |runner_method|
34
39
  @runners[runner_name.to_sym][:class_methods][runner_method] = {
35
40
  args: loaded_runner.instance_method(runner_method).parameters
@@ -5,6 +5,34 @@ module Legion
5
5
  include Legion::Extensions::Helpers::Core
6
6
  include Legion::Extensions::Helpers::Logger
7
7
 
8
+ def function_example(function, example)
9
+ function_set(function, :example, example)
10
+ end
11
+
12
+ def function_options(function, options)
13
+ function_set(function, :options, options)
14
+ end
15
+
16
+ def function_desc(function, desc)
17
+ function_set(function, :desc, desc)
18
+ end
19
+
20
+ def function_set(function, key, value)
21
+ unless respond_to? function
22
+ log.debug "function_#{key} called but function doesn't exist, f: #{function}"
23
+ return nil
24
+ end
25
+ settings[:functions] = {} if settings[:functions].nil?
26
+ settings[:functions][function] = {} if settings[:functions][function].nil?
27
+ settings[:functions][function][key] = value
28
+ end
29
+
30
+ def runner_desc(desc)
31
+ settings[:runners] = {} if settings[:runners].nil?
32
+ settings[:runners][actor_name.to_sym] = {} if settings[:runners][actor_name.to_sym].nil?
33
+ settings[:runners][actor_name.to_sym][:desc] = desc
34
+ end
35
+
8
36
  def self.included(base)
9
37
  base.send :extend, Legion::Extensions::Helpers::Core if base.instance_of?(Class)
10
38
  base.send :extend, Legion::Extensions::Helpers::Logger if base.instance_of?(Class)
@@ -12,7 +40,7 @@ module Legion
12
40
  end
13
41
 
14
42
  def default_settings
15
- { logger: { level: 'info' }, workers: 1 }
43
+ { logger: { level: 'info' }, workers: 1, runners: {}, functions: {} }
16
44
  end
17
45
  end
18
46
  end
@@ -67,15 +67,17 @@ module Legion
67
67
  end
68
68
 
69
69
  def auto_create_dlx_exchange
70
- return if transport_class::Exchanges.const_defined? 'Dlx'
70
+ dlx = if transport_class::Exchanges.const_defined? 'Dlx'
71
+ transport_class::Exchanges::Dlx
72
+ else
73
+ transport_class::Exchanges.const_set('Dlx', Class.new(default_exchange) do
74
+ def exchange_name
75
+ "#{super}.dlx"
76
+ end
77
+ end)
78
+ end
71
79
 
72
- dlx = transport_class::Exchanges.const_set('Dlx', Class.new(default_exchange) do
73
- def exchange_name
74
- "#{super}.dlx"
75
- end
76
- end)
77
80
  dlx.new
78
- dlx
79
81
  end
80
82
 
81
83
  def auto_create_dlx_queue
@@ -35,10 +35,30 @@ module Legion
35
35
  Legion::Data.setup
36
36
  end
37
37
 
38
- def setup_settings
38
+ # noinspection RubyArgCount
39
+ def default_paths
40
+ [
41
+ '/etc/legionio',
42
+ "#{Etc.getpwuid.dir}/legionio",
43
+ "#{ENV['home']}/legionio",
44
+ '~/legionio',
45
+ './settings'
46
+ ]
47
+ end
48
+
49
+ def setup_settings(default_dir = __dir__)
39
50
  require 'legion/settings'
40
- Legion::Logging.debug('Loading Legion::Settings')
41
- Legion::Settings.load(config_dir: './settings')
51
+ config_directory = default_dir
52
+
53
+ default_paths.each do |path|
54
+ next unless Dir.exist? path
55
+
56
+ config_directory = path
57
+ break
58
+ end
59
+
60
+ Legion::Logging.info "Using directory #{config_directory} for settings"
61
+ Legion::Settings.load(config_dir: config_directory)
42
62
  Legion::Logging.info('Legion::Settings Loaded')
43
63
  end
44
64
 
@@ -1,3 +1,3 @@
1
1
  module Legion
2
- VERSION = '0.3.1'.freeze
2
+ VERSION = '0.3.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legionio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esity
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-14 00:00:00.000000000 Z
11
+ date: 2020-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby-ext
@@ -332,6 +332,7 @@ files:
332
332
  - ".rubocop.yml"
333
333
  - CHANGELOG.md
334
334
  - Gemfile
335
+ - Gemfile.lock
335
336
  - LICENSE.txt
336
337
  - README.md
337
338
  - Rakefile
@@ -340,6 +341,37 @@ files:
340
341
  - bin/setup
341
342
  - bin/test
342
343
  - bitbucket-pipelines.yml
344
+ - docs/Makefile
345
+ - docs/_build/doctrees/environment.pickle
346
+ - docs/_build/doctrees/index.doctree
347
+ - docs/_build/doctrees/overview.doctree
348
+ - docs/_build/html/.buildinfo
349
+ - docs/_build/html/_sources/index.rst.txt
350
+ - docs/_build/html/_sources/overview.rst.txt
351
+ - docs/_build/html/_static/alabaster.css
352
+ - docs/_build/html/_static/basic.css
353
+ - docs/_build/html/_static/custom.css
354
+ - docs/_build/html/_static/doctools.js
355
+ - docs/_build/html/_static/documentation_options.js
356
+ - docs/_build/html/_static/file.png
357
+ - docs/_build/html/_static/jquery-3.5.1.js
358
+ - docs/_build/html/_static/jquery.js
359
+ - docs/_build/html/_static/language_data.js
360
+ - docs/_build/html/_static/minus.png
361
+ - docs/_build/html/_static/plus.png
362
+ - docs/_build/html/_static/pygments.css
363
+ - docs/_build/html/_static/searchtools.js
364
+ - docs/_build/html/_static/underscore-1.3.1.js
365
+ - docs/_build/html/_static/underscore.js
366
+ - docs/_build/html/genindex.html
367
+ - docs/_build/html/index.html
368
+ - docs/_build/html/objects.inv
369
+ - docs/_build/html/overview.html
370
+ - docs/_build/html/search.html
371
+ - docs/_build/html/searchindex.js
372
+ - docs/conf.py
373
+ - docs/index.rst
374
+ - docs/make.bat
343
375
  - exe/legion
344
376
  - legion.gemspec
345
377
  - lib/legion.rb
@@ -383,7 +415,6 @@ files:
383
415
  - lib/legion/service.rb
384
416
  - lib/legion/supervision.rb
385
417
  - lib/legion/version.rb
386
- - settings/client.json
387
418
  homepage: https://bitbucket.org/legion-io/legion/
388
419
  licenses:
389
420
  - MIT
@@ -1,25 +0,0 @@
1
- {
2
- "client": {
3
- "keepalive": {
4
- "thresholds": {
5
- "warning": 10
6
- }
7
- }
8
- },
9
- "data": {
10
- "connection": {
11
- "max_connections": 100,
12
- "preconnect": false
13
- }
14
- },
15
- "crypt": {
16
- "cluster_secret": "fkljwelkfjwelkfjwelkjfwe",
17
- "vault": {
18
- "read_cluster_secret": false,
19
- "connected": false,
20
- "renewer": false,
21
- "token": "s.660l1zqqjezPhPLo71tY7dsz",
22
- "protocol": "http"
23
- }
24
- }
25
- }