regiment 0.0.4 → 0.0.6

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTQ3MmQ2MmNkZmJmNmNmMWIxMTdmN2JhNjE2MTE4ZDdlODU5ZWViOQ==
4
+ NTE1MGVlMjg5ZmJiMjVhZTdhOTBkNTFiZjIwYjU0OTIyODZkNGUzZg==
5
5
  data.tar.gz: !binary |-
6
- ZGFiYTNkZjY5MDk0MmE5OGU3MDkzOTMzZGEzMjJkMTk1ZTU3MGRhMg==
6
+ ZGJiNjc1MDgxNjI4YjRjMGUyMGY1N2RlYzNhMmI5NDMxZWU1MzljYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- N2VkYzhmOTVhYjI0Y2E2MGJkOTQ4MGRjMjUxMTA0YzI2YmVhNjE4NDZjNjBh
10
- YjE5NTkyNWE3YjVhNjY4YTM1ZTk0OWMxYjc0MTRiZmQ2M2Y1NTY3Y2IxZTk4
11
- NmY0ZTM4ZDBhNmQ2MTNjNWRmZTVjZThmNDU5MmI0ZjVmMzdmYzU=
9
+ Y2YwYzIyNTkxOGI5YTQ2ZmE1ODNiMmUzNzUxOWYzYzA0NmNkZDRkZmNhOTgy
10
+ NmQ1ZmU2ZDhjOTZlOWZmMDYyMjBjMDJlZTUxMmI2MTY1N2QwNzkxNjFhMWEx
11
+ NzE0M2I0MzYxMTZiNDBhNmQ3NzdkYmQ1MjM4YTJlODBjM2I4M2Y=
12
12
  data.tar.gz: !binary |-
13
- YTlkMzVhNzg4ZjcxYzY3ZjNjMjNiOGNhMDk0ZDI1Y2FkNjgxZjliNmZjNDc2
14
- Mzk1YjllZDcxZmVmMGI3OWFhOWRiMTI3ZWVkZDQ4NjFhNDhlM2I2YTZlNWMx
15
- MWU1OGE1ZDA1MWI4MTIyNTA4MjQ4MGM0ZjA2Yjk2ZjQzMzYwNTY=
13
+ MGZkNzQ4Zjk2OTYxYjliM2FjMjgyMGRjMzAzYjVkMzM5ZjE4OTM4NWFiZTEw
14
+ YTM1Y2RiZjEyNjkwODBjMDliZWJhYmEwMzY0OTMwM2M2MjI4NzNhYjdlOTZm
15
+ NDgwZTBmOTVjMzNlZWE1ODE0MzUxYmNhYzc2ZmNkMTBkYjgxNzA=
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/README.md CHANGED
@@ -1,13 +1,37 @@
1
1
  # Regiment
2
2
  A simple, self-contained, RESTful script/job management framework in Ruby.
3
3
 
4
+ ## Script Library ##
5
+
6
+ The vision for Regiment is a world where one-off, un-monitored, snowflake scripts are a thing of the past. As such, Regiment implements a standard structure for scripts(orders) and how we store them:
7
+
8
+ - All orders must inherit from the Regiment::Order class and should override the `Regiment::Order.execute` function.
9
+ - All orders must inhabit a similarly named directory with a README.
10
+ - Any custom output(report) format should be defined by overriding the `Regiment::Order.report` function.
11
+
12
+ The directory structure for your orders library should look like this:
13
+
14
+ ```
15
+ /etc/regiment/orders
16
+ |- scriptOne/
17
+ |-- scriptOne.rb
18
+ |-- README
19
+ |- scriptTwo/
20
+ |-- scriptTwo.rb
21
+ |-- README
22
+ ```
23
+
4
24
  ## API ##
5
25
 
6
26
  Regiment implements an API through which you can trigger scripts(orders), view which orders are in progress and various other useful actions. The API can be started with the command `regiment-api`.
7
27
 
8
28
  ### Endpoints ###
9
29
 
10
- `/version` - This returns the version of Regiment you have running.
30
+ `GET /version` - This returns the version of Regiment you have running.
31
+
32
+ `GET /execute/<order>` - Executes the specified order and reports back.
33
+
34
+ `GET /about/<order>` - Displays the README for the specified order.
11
35
 
12
36
  ## CLI ##
13
37
 
@@ -17,6 +41,10 @@ Regiment comes with a tool `regiment` that implements the interface of the API o
17
41
 
18
42
  `version` - Returns the version of Regiment used by the client and the version used by the endpoint.
19
43
 
44
+ `execute <order>` - Executes the specified order and reports back.
45
+
46
+ `about <order>` - Displays the README for the specified order.
47
+
20
48
  ### Options ###
21
49
 
22
50
  `--regiment` - String - The hostname(including port) of your Regiment endpoint e.g. `localhost:1234`
data/bin/regiment CHANGED
@@ -5,7 +5,7 @@ require 'thor'
5
5
 
6
6
  class RegimentCLI < Thor
7
7
  desc 'version', 'Get version of regiment client and endpoint'
8
- option :regiment
8
+ class_option :regiment
9
9
 
10
10
  def version
11
11
  client_verison = Regiment::Service::VERSION
@@ -15,6 +15,29 @@ class RegimentCLI < Thor
15
15
 
16
16
  puts "Client: #{client_verison}, Endpoint: #{endpoint_verison}"
17
17
  end
18
+
19
+ desc 'execute', 'Execute an order'
20
+ def execute(order)
21
+ client = Regiment::Client.new(options[:regiment])
22
+ puts client.execute(order)
23
+ end
24
+
25
+ desc 'about', 'Returns the README for an order. It should hopefully describe how and when it should be used.'
26
+ def about(order)
27
+ client = Regiment::Client.new(options[:regiment])
28
+ puts client.about(order)
29
+ end
30
+
31
+ desc 'create', 'Creates new script directory at the desired path'
32
+ def create(name ,path)
33
+ Dir.mkdir "#{path}/#{name}"
34
+ readme = File.new("#{path}/#{name}/README", 'w+')
35
+ order = File.new("#{path}/#{name}/#{name}.rb", 'w+')
36
+
37
+ readme.write("TODO: The README for #{name}.")
38
+ order.write("require 'regiment/order'\n\nclass #{name} < Regiment::Order\n\s\sdef initialize\n\s\s\s\ssuper\n\s\send\n\n\s\sdef execute\n\s\s\s\s# TODO: #{name} script\n\s\send\nend\n")
39
+ end
40
+
18
41
  end
19
42
 
20
43
  RegimentCLI.start(ARGV)
data/bin/regiment-api CHANGED
@@ -5,11 +5,17 @@ require 'json'
5
5
 
6
6
  class RegimentAPI < Sinatra::Base
7
7
 
8
+ configure do
9
+ set :bind, '0.0.0.0'
10
+ set :port, '8585'
11
+ end
12
+
8
13
  helpers do
9
14
  def api
10
15
  @api = Regiment::API.new
11
16
  end
12
17
  end
18
+
13
19
  #use Rack::Auth::Basic, "Regiment Auth" do |username, password|
14
20
  # credentials = JOSN.parse(File.new("/etc/regiment/access.json"))
15
21
  # username == credentials[:username] and password == credentials[:password]
@@ -19,6 +25,14 @@ class RegimentAPI < Sinatra::Base
19
25
  return api.version
20
26
  end
21
27
 
28
+ get "/execute/:order" do
29
+ return api.execute(params[:order])
30
+ end
31
+
32
+ get "/about/:order" do
33
+ return api.about(params[:order])
34
+ end
35
+
22
36
  end
23
37
 
24
38
  RegimentAPI.run!
@@ -0,0 +1,13 @@
1
+ {
2
+ "endpoint": {
3
+ "host" : "localhost",
4
+ "port" : 8585
5
+ },
6
+ "library": {
7
+ "directory": "/etc/regiment/orders"
8
+ },
9
+ "auth": {
10
+ "username": "user",
11
+ "token": "p8NTuv0q97Yb0vQ497"
12
+ }
13
+ }
data/lib/regiment/api.rb CHANGED
@@ -1,13 +1,39 @@
1
1
  require 'regiment/service/version'
2
+ require 'pathname'
2
3
 
3
4
  module Regiment
4
- class API
5
+ class API
6
+
7
+ ORDER_PATH = "/etc/regiment/orders/"
8
+
5
9
  def initialize
6
-
7
10
  end
8
11
 
9
12
  def version
10
13
  return Regiment::Service::VERSION
11
14
  end
15
+
16
+ def execute(order, options={})
17
+ path = Pathname.new(ORDER_PATH).join(Pathname.new("#{order}/#{order}.rb")).to_s
18
+
19
+ # Classes have caps yo!
20
+ order[0] = order[0].capitalize
21
+
22
+ # Load our order, instantiate it and call do_execute
23
+ Kernel.load(path)
24
+ o = Object.const_get(order.to_sym).new
25
+
26
+ return o.do_execute
27
+ end
28
+
29
+ def about(order, options={})
30
+ begin
31
+ info = File.new(Pathname.new(ORDER_PATH).join(Pathname.new("#{order}/README")).to_s)
32
+ rescue IOError => e
33
+ return e
34
+ end
35
+ return info
36
+ end
37
+
12
38
  end
13
39
  end
@@ -17,5 +17,14 @@ module Regiment
17
17
  def version
18
18
  return RestClient.get(build_uri("/version"))
19
19
  end
20
+
21
+ def execute(order, options={})
22
+ return RestClient.get(build_uri("/execute/#{order}"))
23
+ end
24
+
25
+ def about(order, options={})
26
+ return RestClient.get(build_uri("/about/#{order}"))
27
+ end
28
+
20
29
  end
21
30
  end
@@ -1,8 +1,32 @@
1
+ # Regiment::Order
2
+ # The super-class of all orders.
3
+
1
4
  module Regiment
2
5
  class Order
3
-
4
- def initialize
6
+ # Keep track of state
7
+ @state = :initializing
8
+
9
+ def initialize(options={})
10
+ end
11
+
12
+ # do_thing methods wrap methods to be overriden in order imlpementation
13
+ def do_execute(options={})
14
+ @state = :executing
15
+ results = execute
16
+ return do_report(results)
17
+ end
18
+
19
+ def execute(options={})
20
+ end
21
+
22
+ def do_report(result, options={})
23
+ @state = :reporting
24
+ @report = result
25
+ return report(result)
26
+ end
5
27
 
28
+ def report(result ,options={})
29
+ return result
6
30
  end
7
31
  end
8
32
  end
@@ -1,5 +1,5 @@
1
1
  module Regiment
2
2
  class Service
3
- VERSION = '0.0.4'
3
+ VERSION = '0.0.6'
4
4
  end
5
5
  end
data/regiment.gemspec CHANGED
@@ -15,4 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.files = `git ls-files`.split($/)
16
16
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
+ s.add_dependency "sinatra"
18
19
  end
20
+
21
+
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regiment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh McGhee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-01 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2015-06-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: ! 'Regiment: A simple RESTful script/job management framework in Ruby.'
14
28
  email: joshua@spaceapegames.com
15
29
  executables:
@@ -18,11 +32,13 @@ executables:
18
32
  extensions: []
19
33
  extra_rdoc_files: []
20
34
  files:
35
+ - .gitignore
21
36
  - LICENSE
22
37
  - README.md
23
38
  - Rakefile
24
39
  - bin/regiment
25
40
  - bin/regiment-api
41
+ - conf/regiment.json
26
42
  - lib/regiment/api.rb
27
43
  - lib/regiment/client.rb
28
44
  - lib/regiment/order.rb