lita-cmd 0.1.0 → 0.2.0
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 +4 -4
- data/README.md +41 -4
- data/lib/lita/handlers/cmd.rb +47 -11
- data/lita-cmd.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a968328007af50c23e968ebc0725c7ded9a459f
|
4
|
+
data.tar.gz: bbe96e910dba404a8cf56dc8408c3dd91f95720b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc83dc3bc068f71f27fd03ceefc6e539bb8b640e9b320c8c1b27120d277c8394d4abdd6eed65cbe0616654a669844f5711c6043339fb457fd2b29114d249f814
|
7
|
+
data.tar.gz: d2b1635a2e104d115a553db8bf994160cec4bbc6879f6a8d95b48683c4649f602c554440e452eaf17b3067c9dcf1a2585fac0d80b427aa1eaab27310ff46a6b8
|
data/README.md
CHANGED
@@ -19,8 +19,6 @@ Lita.configure do |config|
|
|
19
19
|
end
|
20
20
|
```
|
21
21
|
|
22
|
-
Also, make sure that you are a member of the `devops` Lita Auth group. This requirement will change soon. See Roadmap below.
|
23
|
-
|
24
22
|
## Usage
|
25
23
|
|
26
24
|
- `cmd-help`
|
@@ -31,6 +29,7 @@ Also, make sure that you are a member of the `devops` Lita Auth group. This requ
|
|
31
29
|
>- dfinninger: `lita cmd-help`
|
32
30
|
- lita:
|
33
31
|
```
|
32
|
+
devops/secret
|
34
33
|
hello
|
35
34
|
name
|
36
35
|
```
|
@@ -50,13 +49,51 @@ Your name is: ... well, idk, man...
|
|
50
49
|
Your name is: Devon
|
51
50
|
```
|
52
51
|
|
52
|
+
### Group Control
|
53
|
+
|
54
|
+
You can now control what groups have access to your Lita scripts!
|
55
|
+
|
56
|
+
In your `scripts` dir make some more that match the name of your groups. Only users that are a part of those groups can see/execute those scripts.
|
57
|
+
|
58
|
+
#### Example
|
59
|
+
|
60
|
+
- scripts dir:
|
61
|
+
- Basic directory setup
|
62
|
+
|
63
|
+
```
|
64
|
+
scripts/
|
65
|
+
|- devops/
|
66
|
+
| `- secret
|
67
|
+
|- hello
|
68
|
+
`- name
|
69
|
+
```
|
70
|
+
|
71
|
+
- `lita cmd-help`
|
72
|
+
- Help text will show you scripts that you have access to with a prefix
|
73
|
+
|
74
|
+
```
|
75
|
+
devops/secret
|
76
|
+
hello
|
77
|
+
name
|
78
|
+
```
|
79
|
+
|
80
|
+
- `lita cmd devops/secret`
|
81
|
+
- Execute the command. Prefix required!
|
82
|
+
|
83
|
+
```
|
84
|
+
[stdout] I'm a secret!
|
85
|
+
```
|
86
|
+
|
87
|
+
A non-priviledged user will only see scripts without the prefix.
|
88
|
+
|
53
89
|
## Notes
|
54
90
|
|
55
91
|
- Make sure that your files are executable
|
56
92
|
- (`chmod +x FILE`)
|
57
|
-
- Make sure that you've included the correct
|
93
|
+
- Make sure that you've included the correct sha-bang
|
58
94
|
- `#!/bin/bash`, `#!/usr/bin/env ruby`, etc...
|
59
95
|
|
60
96
|
## Roadmap
|
61
97
|
|
62
|
-
- [
|
98
|
+
- [x] Include support for directory-based access control
|
99
|
+
- [ ] Help text for individual commands
|
data/lib/lita/handlers/cmd.rb
CHANGED
@@ -6,34 +6,42 @@ module Lita
|
|
6
6
|
|
7
7
|
config :scripts_dir
|
8
8
|
|
9
|
+
### CMD-HELP ##############################################
|
10
|
+
|
9
11
|
route(/^\s*cmd-help\s*$/, :cmd_help, command: true, help: {
|
10
12
|
"cmd-help" => "get a list of scripts available for execution"
|
11
13
|
})
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
Dir.glob('*').each { |d| out << d }
|
15
|
+
route(/^\s*test\s*/) do |resp|
|
16
|
+
auth = Lita::Robot.new.auth
|
17
|
+
resp.reply "true" if auth.groups_with_users[:devops].include? resp.user
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
+
def cmd_help(resp)
|
21
|
+
list = get_script_list(resp, config)
|
20
22
|
|
21
|
-
|
23
|
+
out = list.sort.join("\n")
|
24
|
+
resp.reply_privately code_blockify(out)
|
22
25
|
end
|
23
26
|
|
27
|
+
### CMD ###################################################
|
28
|
+
|
24
29
|
route(/^\s*cmd\s+(\S*)\s*(.*)$/, :cmd, command: true, help: {
|
25
30
|
"cmd SCRIPT" => "run the SCRIPT specified; use `lita cmd help` for a list"
|
26
31
|
})
|
27
32
|
|
28
33
|
def cmd(resp)
|
29
|
-
dir = config.scripts_dir
|
30
34
|
script = resp.matches[0][0]
|
31
35
|
opts = resp.matches[0][1].split(" ")
|
32
|
-
|
36
|
+
|
37
|
+
unless user_is_authorized(script, resp, config)
|
38
|
+
resp.reply_privately "Unauthorized to run '#{script}'!"
|
39
|
+
return
|
40
|
+
end
|
33
41
|
|
34
42
|
out = String.new
|
35
43
|
err = String.new
|
36
|
-
Open3.popen3("#{
|
44
|
+
Open3.popen3("#{config.scripts_dir}/#{script}", *opts) do |i, o, e, wait_thread|
|
37
45
|
o.each { |line| out << "[stdout] #{line}" }
|
38
46
|
e.each { |line| err << "[stderr] #{line}" }
|
39
47
|
end
|
@@ -55,10 +63,38 @@ module Lita
|
|
55
63
|
end
|
56
64
|
end
|
57
65
|
|
66
|
+
### HELPERS ############################################
|
67
|
+
|
68
|
+
private
|
58
69
|
def code_blockify(text)
|
59
|
-
"```\n
|
70
|
+
"```\n#{text}\n```"
|
60
71
|
end
|
61
72
|
|
73
|
+
def get_script_list(resp, config)
|
74
|
+
bot = Lita::Robot.new
|
75
|
+
auth = bot.auth
|
76
|
+
|
77
|
+
list = Dir.entries(config.scripts_dir).select { |f| File.file? "#{config.scripts_dir}/#{f}" }
|
78
|
+
|
79
|
+
groups = auth.groups_with_users.select { |group, user_list| user_list.include? resp.user }
|
80
|
+
groups.keys.each do |group|
|
81
|
+
begin
|
82
|
+
sublist = Dir.entries("#{config.scripts_dir}/#{group}").select do |f|
|
83
|
+
File.file? "#{config.scripts_dir}/#{group}/#{f}"
|
84
|
+
end
|
85
|
+
rescue SystemCallError => e
|
86
|
+
log.warn "#{group} is not a directory.\n#{e}"
|
87
|
+
end
|
88
|
+
list.concat sublist.map { |x| "#{group}/#{x}" } if sublist
|
89
|
+
end
|
90
|
+
|
91
|
+
list
|
92
|
+
end
|
93
|
+
|
94
|
+
def user_is_authorized(script, resp, config)
|
95
|
+
list = get_script_list(resp, config)
|
96
|
+
list.include? script
|
97
|
+
end
|
62
98
|
end
|
63
99
|
|
64
100
|
Lita.register_handler(Cmd)
|
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.2.0
|
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-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|