lita-cmd 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/LICENSE +25 -0
- data/README.md +60 -55
- data/lib/lita/handlers/cmd.rb +35 -33
- data/lita-cmd.gemspec +1 -1
- metadata +5 -4
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95c014b178540ac78fea8382a329a46edc1fd3fb
|
4
|
+
data.tar.gz: eafa77669e9e74df536f60884ab8e27baaee251f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e7b4d4f78418f742d86a96b6a5e63ed58d4571972a79475c1e53f897d5bd3ef017c57209f866915a73c2b6d0bc6599d6901c6a1f4ac8fefa985c654ae715caa
|
7
|
+
data.tar.gz: 50035f127e8286d385a920517b5f7577211a69bd7456016891ee2dd7fe6b78a59649b1b74fdc11fc1a3f78feb2fdbedb2eeeacf8cdf70135d7ba48ca20bc1dce
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
## 0.3.0
|
2
|
+
|
3
|
+
- [6aa45ca](https://github.com/dfinninger/lita-cmd/commit/6aa45ca0acc68c8677562704a0d4436189f102f3): Customize stdout/stderr prefixes and code format.
|
4
|
+
- [@DannyBen](https://github.com/DannyBen), [@groob](https://github.com/groob), [@manicholls](https://github.com/manicholls)
|
5
|
+
- [0574baa](https://github.com/dfinninger/lita-cmd/commit/0574baa85e422c71cb064b83dd50479f14194fac): Add MIT License
|
6
|
+
- [mekhanique](https://github.com/mekhanique)
|
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2015 Devon Finninger
|
2
|
+
|
3
|
+
|
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
|
+
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be included in
|
15
|
+
all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
25
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# lita-cmd
|
2
2
|
|
3
|
-
Run scripts from your lita machine and get
|
3
|
+
Run scripts from your lita machine and get the output back.
|
4
4
|
|
5
|
-
##
|
5
|
+
## Install
|
6
6
|
|
7
7
|
Add lita-cmd to your Lita instance's Gemfile:
|
8
8
|
|
@@ -12,88 +12,93 @@ gem "lita-cmd"
|
|
12
12
|
|
13
13
|
## Configuration
|
14
14
|
|
15
|
+
| Config Option | Description | Type | Notes |
|
16
|
+
|----------------|--------------------------------------|--------|----------|
|
17
|
+
|`scripts_dir` |Full path to location of scripts |`String`|*required*|
|
18
|
+
|`stdout_prefix` |Prefix for text returned to STDOUT |`String`| |
|
19
|
+
|`stderr_prefix` |Prefix for text returned to STDERR |`String`| |
|
20
|
+
|`output_format` |Format string used to encapsulate code|`String`| |
|
21
|
+
|`command_prefix`|Command to use for executing scripts |`String`| |
|
22
|
+
|
23
|
+
|
24
|
+
### Example
|
25
|
+
|
15
26
|
```ruby
|
16
27
|
Lita.configure do |config|
|
17
|
-
# Lita CMD
|
28
|
+
# Lita CMD - required parameters
|
18
29
|
config.handlers.cmd.scripts_dir = "/path/to/dir/you/expose"
|
30
|
+
|
31
|
+
# Lita CMD - optional parameters
|
32
|
+
|
33
|
+
# Set the output format. Default: "%s"
|
34
|
+
# Note that %s will contain the returned text
|
35
|
+
config.handlers.cmd.output_format = "/code %s"
|
36
|
+
|
37
|
+
# Set the prefix of stdout and stderr.
|
38
|
+
config.handlers.cmd.stdout_prefix = ""
|
39
|
+
config.handlers.cmd.stderr_prefix = "ERROR: "
|
40
|
+
|
41
|
+
# Set the prefix for running scripts.
|
42
|
+
config.handlers.cmd.command_prefix = "run "
|
43
|
+
|
19
44
|
end
|
20
45
|
```
|
21
46
|
|
22
47
|
## Usage
|
23
48
|
|
24
|
-
|
25
|
-
- Query the configured directory for filenames and return them
|
26
|
-
- `cmd`
|
27
|
-
- Execute a file in the configured directory
|
49
|
+
In your chatroom, try one of these commands
|
28
50
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
name
|
35
|
-
```
|
36
|
-
- dfinninger: `lita cmd hello`
|
37
|
-
- lita:
|
38
|
-
```
|
39
|
-
Hello!
|
40
|
-
```
|
41
|
-
- dfinninger: `lita cmd name`
|
42
|
-
- lita:
|
43
|
-
```
|
44
|
-
Your name is: ... well, idk, man...
|
45
|
-
```
|
46
|
-
- dfinninger: `lita cmd name Devon`
|
47
|
-
- lita:
|
48
|
-
```
|
49
|
-
Your name is: Devon
|
50
|
-
```
|
51
|
+
### `lita cmd list`
|
52
|
+
|
53
|
+
Query the configured directory for filenames and return the list
|
54
|
+
|
55
|
+
### `lita cmd <file>`
|
51
56
|
|
52
|
-
|
57
|
+
Execute a file in the configured directory
|
53
58
|
|
54
|
-
You can now control what groups have access to your Lita scripts!
|
55
59
|
|
56
|
-
|
60
|
+
## Group Control
|
57
61
|
|
58
|
-
|
62
|
+
You can control what groups have access to your Lita scripts.
|
59
63
|
|
60
|
-
|
61
|
-
|
64
|
+
In your `scripts` directory make a sub directory named after each of your
|
65
|
+
groups. Only users that belong to these groups can list and execute the
|
66
|
+
scripts inside them.
|
67
|
+
|
68
|
+
This is the basic directory structure
|
62
69
|
|
63
70
|
```
|
64
71
|
scripts/
|
65
72
|
|- devops/
|
66
|
-
|
|
67
|
-
|-
|
68
|
-
|
73
|
+
| - secret_script
|
74
|
+
|- script1
|
75
|
+
|- script2
|
69
76
|
```
|
70
77
|
|
71
|
-
|
72
|
-
|
78
|
+
When you run `lita cmd list` you will only see scripts that you have access
|
79
|
+
to. For example:
|
73
80
|
|
74
81
|
```
|
75
|
-
|
76
|
-
hello
|
77
|
-
name
|
78
|
-
```
|
82
|
+
me: lita cmd list
|
79
83
|
|
80
|
-
|
81
|
-
|
84
|
+
lita: devops/secret_script
|
85
|
+
script1
|
86
|
+
script2
|
82
87
|
|
83
|
-
|
84
|
-
[stdout] I'm a secret!
|
85
|
-
```
|
88
|
+
me: lita cmd devops/secret_script
|
86
89
|
|
87
|
-
|
90
|
+
lita: Executing the secret script
|
91
|
+
```
|
88
92
|
|
89
93
|
## Notes
|
90
94
|
|
91
|
-
-
|
92
|
-
|
93
|
-
- Make sure that
|
94
|
-
|
95
|
+
- The user name of the calling user will be saved in an environment variable
|
96
|
+
called `LITA_USER`.
|
97
|
+
- Make sure that your files are executables (`chmod +x FILE`)
|
98
|
+
- Make sure that your files have the proper sheband (`#!/bin/bash`)
|
95
99
|
|
96
|
-
##
|
100
|
+
## Todo
|
97
101
|
|
98
102
|
- [x] Include support for directory-based access control
|
99
103
|
- [ ] Help text for individual commands
|
104
|
+
- [ ] Add tests
|
data/lib/lita/handlers/cmd.rb
CHANGED
@@ -3,37 +3,29 @@ require 'open3'
|
|
3
3
|
module Lita
|
4
4
|
module Handlers
|
5
5
|
class Cmd < Handler
|
6
|
-
|
7
|
-
config :scripts_dir
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
def cmd_help(resp)
|
21
|
-
list = get_script_list(resp, config)
|
22
|
-
|
23
|
-
out = list.sort.join("\n")
|
24
|
-
resp.reply_privately code_blockify(out)
|
6
|
+
on :connected, :create_routes
|
7
|
+
config :scripts_dir, required: true
|
8
|
+
|
9
|
+
config :output_format, default: "%s"
|
10
|
+
config :stdout_prefix, default: ""
|
11
|
+
config :stderr_prefix, default: "ERROR: "
|
12
|
+
config :command_prefix, default: "cmd "
|
13
|
+
|
14
|
+
def create_routes(payload)
|
15
|
+
self.class.route(/^\s*#{config.command_prefix}(\S+)\s*(.*)$/, :run_action, command: true, help: {
|
16
|
+
"#{config.command_prefix}ACTION" => "run the specified ACTION. use `#{robot.name} #{config.command_prefix}list` for a list of available actions."
|
17
|
+
})
|
25
18
|
end
|
26
19
|
|
27
|
-
|
28
|
-
|
29
|
-
route(/^\s*cmd\s+(\S*)\s*(.*)$/, :cmd, command: true, help: {
|
30
|
-
"cmd SCRIPT" => "run the SCRIPT specified; use `lita cmd help` for a list"
|
31
|
-
})
|
32
|
-
|
33
|
-
def cmd(resp)
|
20
|
+
def run_action(resp)
|
34
21
|
script = resp.matches[0][0]
|
35
22
|
opts = resp.matches[0][1].split(" ")
|
36
23
|
|
24
|
+
# the script will be the robot name if command_prefix is empty
|
25
|
+
return if script =~ /@?#{robot.name}/i
|
26
|
+
|
27
|
+
return show_help(resp) if script == 'list'
|
28
|
+
|
37
29
|
unless user_is_authorized(script, resp, config)
|
38
30
|
resp.reply_privately "Unauthorized to run '#{script}'!"
|
39
31
|
return
|
@@ -41,9 +33,13 @@ module Lita
|
|
41
33
|
|
42
34
|
out = String.new
|
43
35
|
err = String.new
|
44
|
-
|
45
|
-
|
46
|
-
|
36
|
+
|
37
|
+
script_path = "#{config.scripts_dir}/#{script}"
|
38
|
+
env_vars = { 'LITA_USER' => resp.user.name }
|
39
|
+
|
40
|
+
Open3.popen3(env_vars, script_path, *opts) do |i, o, e, wait_thread|
|
41
|
+
o.each { |line| out << "#{config.stdout_prefix}#{line}" }
|
42
|
+
e.each { |line| err << "#{config.stderr_prefix}#{line}" }
|
47
43
|
end
|
48
44
|
|
49
45
|
if err != String.new
|
@@ -59,15 +55,21 @@ module Lita
|
|
59
55
|
ascii_out = out.encode(Encoding.find('ASCII'), encoding_options)
|
60
56
|
|
61
57
|
ascii_out.split("\n").each_slice(50) do |slice|
|
62
|
-
resp.reply
|
58
|
+
resp.reply code_format(slice.join("\n"))
|
63
59
|
end
|
64
60
|
end
|
65
61
|
|
66
|
-
|
62
|
+
def show_help(resp)
|
63
|
+
list = get_script_list(resp, config)
|
64
|
+
|
65
|
+
out = list.sort.join("\n")
|
66
|
+
resp.reply_privately code_format(out)
|
67
|
+
end
|
67
68
|
|
68
69
|
private
|
69
|
-
|
70
|
-
|
70
|
+
|
71
|
+
def code_format(text)
|
72
|
+
config.output_format % text
|
71
73
|
end
|
72
74
|
|
73
75
|
def get_script_list(resp, config)
|
data/lita-cmd.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-cmd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Devon Finninger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -102,8 +102,9 @@ extensions: []
|
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
104
|
- ".gitignore"
|
105
|
-
-
|
105
|
+
- CHANGELOG.md
|
106
106
|
- Gemfile
|
107
|
+
- LICENSE
|
107
108
|
- README.md
|
108
109
|
- Rakefile
|
109
110
|
- lib/lita-cmd.rb
|
@@ -134,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
135
|
version: '0'
|
135
136
|
requirements: []
|
136
137
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.4.
|
138
|
+
rubygems_version: 2.4.8
|
138
139
|
signing_key:
|
139
140
|
specification_version: 4
|
140
141
|
summary: Run commands from Lita
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby-2.1.5@lita-cmd
|