lita-ldap 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +7 -4
- data/lib/ldaphelper/misc.rb +32 -0
- data/lib/lita/handlers/ldap.rb +74 -6
- data/lita-ldap.gemspec +1 -1
- data/locales/en.yml +17 -10
- data/spec/lita/handlers/ldap_spec.rb +25 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0de328ac9f7bd2874241a587ad9b510804ddc672
|
4
|
+
data.tar.gz: f19e2f7d0e52cf358f54d0a5e66911164655e2ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e572cca1829c967805cdc2d752f7e01a4b0da52ada3d85fb081bcb8d7ced429f2471708f0ad84053e59d806a02c5674a93cc245b7e7e9357ae9e4bb3b784109
|
7
|
+
data.tar.gz: 90cedc1cbe3c0a0f9585290a82201e304e4b4b522c73aab5cddb53c0f8b85ac461fe61233b29a7937ed79c03c4ae029037a6d0f7fc71e6787702b6810dce2b51
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#Change Log
|
2
|
+
|
3
|
+
##v0.1.2
|
4
|
+
* Fix help message
|
5
|
+
* Add function for delete entry
|
6
|
+
* Add command to delete tree
|
7
|
+
* Add command to show server root dse
|
8
|
+
|
9
|
+
##v0.1.1
|
10
|
+
* Search entry with filter
|
11
|
+
* Show entry use full dn
|
12
|
+
* Verify ldap filter
|
13
|
+
|
14
|
+
##v0.1.0
|
15
|
+
Basic search for user group
|
data/README.md
CHANGED
@@ -27,7 +27,10 @@ end
|
|
27
27
|
|
28
28
|
## Usage
|
29
29
|
|
30
|
-
*
|
31
|
-
*
|
32
|
-
*
|
33
|
-
*
|
30
|
+
* ldap search user nexus
|
31
|
+
* ldap search group nx-admin
|
32
|
+
* ldap search with filter 'cn=gerrit'
|
33
|
+
* ldap show dn 'cn=gerrit,ou=people,dc=ldap,dc=example,dc=com'
|
34
|
+
* ldap delete dn 'cn=gerrit,ou=people,dc=ldap,dc=example,dc=com'
|
35
|
+
* ldap delete tree dn 'ou=people,dc=ldap,dc=example,dc=com' #if supported
|
36
|
+
* ldap root dse
|
data/lib/ldaphelper/misc.rb
CHANGED
@@ -63,5 +63,37 @@ module LitaLDAPHelper
|
|
63
63
|
#puts results
|
64
64
|
results
|
65
65
|
end
|
66
|
+
|
67
|
+
def delete_entry_by_dn(dn)
|
68
|
+
dn_spec = dn.split(':',2)
|
69
|
+
dn_str = dn_spec[0]
|
70
|
+
if dn_spec.length>1
|
71
|
+
dn_str = dn_spec[1]
|
72
|
+
end
|
73
|
+
dn_str = dn_str.strip
|
74
|
+
client.delete :dn => dn_str
|
75
|
+
end
|
76
|
+
|
77
|
+
def delete_tree_by_dn(dn)
|
78
|
+
dn_spec = dn.split(':',2)
|
79
|
+
dn_str = dn_spec[0]
|
80
|
+
if dn_spec.length>1
|
81
|
+
dn_str = dn_spec[1]
|
82
|
+
end
|
83
|
+
dn_str = dn_str.strip
|
84
|
+
client.delete :dn => dn_str
|
85
|
+
end
|
86
|
+
|
87
|
+
def search_root_dse
|
88
|
+
begin
|
89
|
+
info = client.search_root_dse
|
90
|
+
if info
|
91
|
+
info.to_ldif
|
92
|
+
end
|
93
|
+
rescue Exception => e
|
94
|
+
e.message
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
66
98
|
end#module misc
|
67
99
|
end#module LitaLDAPHelper
|
data/lib/lita/handlers/ldap.rb
CHANGED
@@ -84,6 +84,33 @@ module Lita
|
|
84
84
|
}
|
85
85
|
)
|
86
86
|
|
87
|
+
route(
|
88
|
+
/^ldap\s+delete\s+dn\s+(["'])([^\1]+)(\1)$/,
|
89
|
+
:cmd_delete_with_dn,
|
90
|
+
command: true,
|
91
|
+
help: {
|
92
|
+
t('help.cmd_delete_with_dn_key') => t('help.cmd_delete_with_dn_value')
|
93
|
+
}
|
94
|
+
)
|
95
|
+
|
96
|
+
route(
|
97
|
+
/^ldap\s+delete\s+tree\s+dn\s+(["'])([^\1]+)(\1)$/,
|
98
|
+
:cmd_delete_tree_with_dn,
|
99
|
+
command: true,
|
100
|
+
help: {
|
101
|
+
t('help.cmd_delete_tree_with_dn_key') => t('help.cmd_delete_tree_with_dn_value')
|
102
|
+
}
|
103
|
+
)
|
104
|
+
|
105
|
+
route(
|
106
|
+
/^ldap\s+root\s+dse\s*$/,
|
107
|
+
:cmd_show_root_dse,
|
108
|
+
command: true,
|
109
|
+
help: {
|
110
|
+
t('help.cmd_show_root_dse_key') => t('help.cmd_show_root_dse_value')
|
111
|
+
}
|
112
|
+
)
|
113
|
+
|
87
114
|
|
88
115
|
def cmd_search_user(response)
|
89
116
|
search_string = response.matches[0][0]
|
@@ -105,12 +132,12 @@ module Lita
|
|
105
132
|
if ! filter_string.nil? && filter_string.strip.length>0
|
106
133
|
is_valid = valid_filter?(filter_string)
|
107
134
|
if is_valid
|
108
|
-
response.reply "Filter is valid"
|
135
|
+
response.reply "Filter is valid."
|
109
136
|
else
|
110
|
-
response.reply "Filter in not valid"
|
137
|
+
response.reply "Filter in not valid."
|
111
138
|
end
|
112
139
|
else
|
113
|
-
response.reply "Filter string is empty"
|
140
|
+
response.reply "Filter string is empty."
|
114
141
|
end
|
115
142
|
end
|
116
143
|
|
@@ -122,10 +149,10 @@ module Lita
|
|
122
149
|
results = search_with_filter(filter_string)
|
123
150
|
response.reply results
|
124
151
|
else
|
125
|
-
response.reply "Filter in not valid"
|
152
|
+
response.reply "Filter in not valid."
|
126
153
|
end
|
127
154
|
else
|
128
|
-
response.reply "Filter string is empty"
|
155
|
+
response.reply "Filter string is empty."
|
129
156
|
end
|
130
157
|
end
|
131
158
|
|
@@ -135,10 +162,51 @@ module Lita
|
|
135
162
|
results = get_entry_by_dn(dn)
|
136
163
|
response.reply results
|
137
164
|
else
|
138
|
-
response.reply "Invalid dn"
|
165
|
+
response.reply "Invalid dn provided."
|
139
166
|
end
|
140
167
|
end
|
141
168
|
|
169
|
+
def cmd_delete_with_dn(response)
|
170
|
+
dn = response.matches[0][1]
|
171
|
+
if ! dn.nil? && dn.strip.length>0
|
172
|
+
begin
|
173
|
+
success = delete_entry_by_dn(dn)
|
174
|
+
if success
|
175
|
+
response.reply "Entry deleted."
|
176
|
+
else
|
177
|
+
response.reply "Failed to delete entry, server may not support LDAP control 1.2.840.113556.1.4.805."
|
178
|
+
end
|
179
|
+
rescue Exception => e
|
180
|
+
response.reply e.message
|
181
|
+
end
|
182
|
+
else
|
183
|
+
response.reply "Invalid dn provided."
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def cmd_delete_tree_with_dn(response)
|
188
|
+
dn = response.matches[0][1]
|
189
|
+
if ! dn.nil? && dn.strip.length>0
|
190
|
+
begin
|
191
|
+
success = delete_tree_by_dn(dn)
|
192
|
+
if success
|
193
|
+
response.reply "Entry deleted."
|
194
|
+
else
|
195
|
+
response.reply "Failed to delete entry."
|
196
|
+
end
|
197
|
+
rescue Exception => e
|
198
|
+
response.reply e.message
|
199
|
+
end
|
200
|
+
else
|
201
|
+
response.reply "Invalid dn provided."
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def cmd_show_root_dse(response)
|
206
|
+
results = search_root_dse
|
207
|
+
response.reply results
|
208
|
+
end
|
209
|
+
|
142
210
|
Lita.register_handler(self)
|
143
211
|
end #class
|
144
212
|
end # module
|
data/lita-ldap.gemspec
CHANGED
data/locales/en.yml
CHANGED
@@ -2,13 +2,20 @@ en:
|
|
2
2
|
lita:
|
3
3
|
handlers:
|
4
4
|
ldap:
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
help:
|
6
|
+
cmd_search_user_key: 'ldap search user SEARCH_STRING'
|
7
|
+
cmd_search_user_value: 'Search user with search string'
|
8
|
+
cmd_search_group_key: 'ldap search user SEARCH_STRING'
|
9
|
+
cmd_search_group_value: 'Search user with search string'
|
10
|
+
cmd_check_filter_key: 'ldap check filter "FILTER_STRING"'
|
11
|
+
cmd_check_filter_value: 'Check ldap filter syntax'
|
12
|
+
cmd_search_with_filter_key: 'ldap search with filter "FILTER_STRING"'
|
13
|
+
cmd_search_with_filter_value: 'Search entry with filter "FILTER_STRING"'
|
14
|
+
cmd_search_with_dn_key: 'ldap show dn "DN_STRING"'
|
15
|
+
cmd_search_with_dn_value: 'Show entry with dn "DN_STRING"'
|
16
|
+
cmd_delete_with_dn_key: 'ldap delete dn "DN_STRING"'
|
17
|
+
cmd_delete_with_dn_value: 'Delete entry with dn "DN_STRING"'
|
18
|
+
cmd_delete_tree_with_dn_key: 'ldap delete tree dn "DN_STRING"'
|
19
|
+
cmd_delete_tree_with_dn_value: 'Delete tree entry with dn "DN_STRING"'
|
20
|
+
cmd_show_root_dse_key: 'ldap root dse'
|
21
|
+
cmd_show_root_dse_value: 'Check ldap root dse'
|
@@ -57,6 +57,10 @@ describe Lita::Handlers::Ldap, lita_handler: true do
|
|
57
57
|
is_expected.to route_command('ldap search group nx-admin').to(:cmd_search_group)
|
58
58
|
is_expected.to route_command('ldap check filter "cn=admin"').to(:cmd_check_filter)
|
59
59
|
is_expected.to route_command('ldap search with filter "cn=nexus"').to(:cmd_search_with_filter)
|
60
|
+
is_expected.to route_command("ldap show dn 'dn: cn=nx-admin,ou=groups,dc=ldap,dc=example,dc=com'").to(:cmd_search_with_dn)
|
61
|
+
is_expected.to route_command("ldap delete dn 'dn: cn=nx-admin,ou=groups,dc=ldap,dc=example,dc=com'").to(:cmd_delete_with_dn)
|
62
|
+
is_expected.to route_command("ldap delete tree dn 'dn: ou=groups,dc=ldap,dc=example,dc=com'").to(:cmd_delete_tree_with_dn)
|
63
|
+
is_expected.to route_command('ldap root dse').to(:cmd_show_root_dse)
|
60
64
|
end
|
61
65
|
|
62
66
|
describe '#search user' do
|
@@ -94,4 +98,25 @@ describe Lita::Handlers::Ldap, lita_handler: true do
|
|
94
98
|
puts replies
|
95
99
|
end
|
96
100
|
end
|
101
|
+
|
102
|
+
describe '#delete dn' do
|
103
|
+
it 'delete entry with specified dn' do
|
104
|
+
send_command("ldap delete dn 'dn: cn=nx-admin,ou=groups,dc=ldap,dc=example,dc=com'")
|
105
|
+
puts replies
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '#delete tree' do
|
110
|
+
it 'delete tree with specified dn' do
|
111
|
+
send_command("ldap delete dn 'dn: ou=groups,dc=ldap,dc=example,dc=com'")
|
112
|
+
puts replies
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#show root dse' do
|
117
|
+
it 'show directory root dse' do
|
118
|
+
send_command("ldap root dse")
|
119
|
+
puts replies
|
120
|
+
end
|
121
|
+
end
|
97
122
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-ldap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wang, Dawei
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -116,6 +116,7 @@ extensions: []
|
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
118
|
- ".gitignore"
|
119
|
+
- CHANGELOG.md
|
119
120
|
- Gemfile
|
120
121
|
- LICENSE
|
121
122
|
- README.md
|