webcommand 0.1.0 → 0.1.1

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d90f6edaa78ce0fdf2f1d47b517da8fa6c7f343d19746ad944850deb4c5a873
4
- data.tar.gz: 7544ff646622a5c166ede708b64f73df051f5d1a6797f8a540202e973fae305b
3
+ metadata.gz: 23065c0d5aa1922fa1078f897e5b3620394c0c00e776c70bd012bca60cf8c74a
4
+ data.tar.gz: 71255e0efa07c83f76256e7666ee4bde0b27b4a0a85a872ab4aa2acd95141a8f
5
5
  SHA512:
6
- metadata.gz: 1ce19810d533d0e8e3bb3777a0f5a13cdedd708876ff4addd185f318d9bddd4a7d6fd727f25a269e7efe5ce87e50828686822d45e29854f2459b103255c7adda
7
- data.tar.gz: 9eab9ebd5dc881afd3431d9c43ccb909197d616010db4199e47e34ae5b414a32a10bd3c3c89e208a0962b49cf7f4d780de0b340bd10dd25f07214ab021ad5287
6
+ metadata.gz: 63306cf95873e8d588f94fbe594aee3c52106d36ddd23b99f5fefea62c2bd9e4f6c233f3d59c6f1bfeafe1ecc6fba2dd29d985fdb938af064904a2db65479f61
7
+ data.tar.gz: 5eb30af8d68eb2dca38400d028f9ac427fa8f12187433cb6dd2bd648ad89c467aea83b37cfef16899fa6ca7240cc2cf206d6ee68ba8547141573156edd22a1ab
data/.travis.yml CHANGED
@@ -1,7 +1,12 @@
1
- ---
2
1
  sudo: false
3
2
  language: ruby
4
- cache: bundler
5
3
  rvm:
6
- - 2.6.5
4
+ - 2.5
5
+ - 2.6
6
+ before_script:
7
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
8
+ - chmod +x ./cc-test-reporter
9
+ - ./cc-test-reporter before-build
7
10
  before_install: gem install bundler -v 2.0.2
11
+ after_script:
12
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- webcommand (0.1.0)
4
+ webcommand (0.1.1)
5
5
  mustache (~> 1.0)
6
+ puma (~> 4.2.1)
6
7
  rack-contrib (~> 2.1.0)
7
8
  sinatra (~> 2.0.7)
8
9
  thor (~> 0.20.3)
@@ -33,6 +34,7 @@ GEM
33
34
  method_source (0.9.2)
34
35
  mustache (1.1.0)
35
36
  mustermann (1.0.3)
37
+ nio4r (2.5.2)
36
38
  parser (2.6.5.0)
37
39
  ast (~> 2.4.0)
38
40
  pastel (0.7.3)
@@ -46,6 +48,8 @@ GEM
46
48
  pry (0.12.2)
47
49
  coderay (~> 1.1.0)
48
50
  method_source (~> 0.9.0)
51
+ puma (4.2.1)
52
+ nio4r (~> 2.0)
49
53
  rack (2.0.7)
50
54
  rack-contrib (2.1.0)
51
55
  rack (~> 2.0)
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # Webcommand
2
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/webcommand`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Build Status](https://travis-ci.org/catks/webcommand.svg?branch=master)](https://travis-ci.org/catks/webcommand)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/c998fcc99367d0e26fca/maintainability)](https://codeclimate.com/github/catks/webcommand/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/c998fcc99367d0e26fca/test_coverage)](https://codeclimate.com/github/catks/webcommand/test_coverage)
4
6
 
5
- TODO: Delete this and the text above, and describe your gem
7
+
8
+ Webcommand lets you run commands through a Web API
6
9
 
7
10
  ## Installation
8
11
 
@@ -22,17 +25,47 @@ Or install it yourself as:
22
25
 
23
26
  ## Usage
24
27
 
25
- TODO: Write usage instructions here
28
+ Create a config file specifying the commands you want to expose with the permitted params.
29
+ ```yaml
30
+ # my_config.yml
31
+ commands:
32
+ hello_world:
33
+ # Parameter without validations
34
+ command: 'echo "Hello {{world}}"'
35
+ hehe:
36
+ command: 'echo "{{name}}, are you {{state}}"'
37
+ params:
38
+ # Validation can be configured with any REGEXP
39
+ name: '^[a-zA-Z]+$'
40
+ state: '^\S+$'
41
+ ```
42
+
43
+ Run the webserver with the cli (*OBS: See the `webcommand help server
44
+ ` for additional options*):
45
+
46
+ `WEBCOMMAND_CONFIGURATION=./my_config.yml webcommand server --port 3000`
47
+
48
+ After that you can execute your commands throught the web api:
49
+
50
+ ```sh
51
+ curl -X POST http://localhost:3000/executions \
52
+ -d '{"command": "hehe", "params": { "name": "Annie", "state": "Okay"} }' \
53
+ -H "Content-Type: application/json"
54
+
55
+ #=> {"stdout":"Annie, are you Okay\n","stderr":"","exit_status":0}%
56
+ ```
57
+
58
+ ### With Rails
26
59
 
27
- ## Development
60
+ *...TODO...*
28
61
 
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.
62
+ ### With Docker
30
63
 
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).
64
+ *...TODO...*
32
65
 
33
66
  ## Contributing
34
67
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/webcommand.
68
+ Bug reports and pull requests are welcome on GitHub at https://github.com/catks/webcommand.
36
69
 
37
70
  ## License
38
71
 
data/config.ru ADDED
@@ -0,0 +1,3 @@
1
+ require_relative './lib/webcommand.rb'
2
+
3
+ run Webcommand::Server
data/examples/config.yml CHANGED
@@ -7,4 +7,9 @@ commands:
7
7
  params:
8
8
  filename: '^[a-z]+$' # Some Regexp
9
9
  contents: '^[a-zA-Z0-9]*$'
10
+ hehe:
11
+ command: 'echo "{{name}}, are you {{state}}"'
12
+ params:
13
+ name: '^[a-zA-Z]+$'
14
+ state: '^\S+$'
10
15
 
data/exe/webcommand CHANGED
@@ -3,14 +3,4 @@
3
3
  require 'thor'
4
4
  require_relative '../lib/webcommand'
5
5
 
6
- module Webcommand
7
- class CLI < Thor
8
- desc "server", "Start the Webcommand server"
9
- option :port
10
- def server
11
- ::WebCommand::Server.start!
12
- end
13
- end
14
- end
15
-
16
6
  Webcommand::CLI.start(ARGV)
@@ -0,0 +1,16 @@
1
+ module Webcommand
2
+ class CLI < Thor
3
+ desc "server", "Start the Webcommand server"
4
+ option :port, aliases: :p, default: 9292
5
+ option :bind, aliases: :b, default: '0.0.0.0'
6
+ option :threads, aliases: :t, default: 8
7
+ option :workers, aliases: :w, default: 1
8
+ def server
9
+ exec "puma " \
10
+ "-p #{options[:port]} " \
11
+ "-t #{options[:threads]}:#{options[:threads]} " \
12
+ "-w #{options[:workers]} " \
13
+ "#{Webcommand.root_path.join('config.ru')}"
14
+ end
15
+ end
16
+ end
@@ -1,10 +1,12 @@
1
1
  module Webcommand
2
2
  class Server < Sinatra::Application
3
3
  use Rack::PostBodyContentTypeParser
4
+
4
5
  before do
5
6
  content_type 'application/json'
6
7
  end
7
8
 
9
+
8
10
  using Webcommand::Extensions::HashExtension
9
11
 
10
12
  post '/executions' do
@@ -1,3 +1,3 @@
1
1
  module Webcommand
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/webcommand.rb CHANGED
@@ -4,13 +4,15 @@ require 'json'
4
4
  require 'rack/contrib'
5
5
  require 'yaml'
6
6
  require 'tty-command'
7
+ require 'thor'
8
+ require 'pathname'
7
9
 
8
- require_relative 'webcommand/version'
9
10
  require_relative 'webcommand/extensions/hash_extension'
10
11
  require_relative 'webcommand/command'
11
12
  require_relative 'webcommand/server'
12
13
  require_relative 'webcommand/config'
13
14
  require_relative 'webcommand/commands'
15
+ require_relative 'webcommand/cli'
14
16
 
15
17
  module Webcommand
16
18
  def self.config
data/webcommand.gemspec CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency "mustache", "~> 1.0"
30
30
  spec.add_dependency "rack-contrib", "~> 2.1.0"
31
31
  spec.add_dependency "tty-command", "~> 0.9.0"
32
+ spec.add_dependency "puma", "~> 4.2.1"
32
33
  spec.add_development_dependency "byebug"
33
34
  spec.add_development_dependency "pry"
34
35
  spec.add_development_dependency "bundler", "~> 2.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webcommand
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Atkinson Ferreira Filho
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-25 00:00:00.000000000 Z
11
+ date: 2019-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.9.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: puma
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 4.2.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 4.2.1
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: byebug
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -168,9 +182,11 @@ files:
168
182
  - Rakefile
169
183
  - bin/console
170
184
  - bin/setup
185
+ - config.ru
171
186
  - examples/config.yml
172
187
  - exe/webcommand
173
188
  - lib/webcommand.rb
189
+ - lib/webcommand/cli.rb
174
190
  - lib/webcommand/command.rb
175
191
  - lib/webcommand/commands.rb
176
192
  - lib/webcommand/config.rb