ldap_tools 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tapjoy/ldap/base.rb +6 -6
- data/lib/tapjoy/ldap/group/add_user.rb +3 -3
- data/lib/tapjoy/ldap/group/create.rb +3 -3
- data/lib/tapjoy/ldap/group/delete.rb +5 -5
- data/lib/tapjoy/ldap/user/create.rb +37 -35
- data/lib/tapjoy/ldap/user/delete.rb +31 -15
- data/lib/tapjoy/ldap/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87ea99ec2ff3fdf48a25f53868073540168f34fe
|
4
|
+
data.tar.gz: 918dd42c64afeb5ceec56935fc72c34ff57439fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 208965f680e094e1afc62ee1a2b5c58f2d5a23e1afe11a1491beadea8dcdb21ab72bbfadefe0a5b763dee16b081bf36a439fd1d48bb0977456a55031bb8a3e14
|
7
|
+
data.tar.gz: b52b0151ad7114e7e36ccab2347b43ac7e340ac784ca2d654ecdb19da64c27632403eb37012fbae006ad7f8045011fbd8ef59ab1cc932f7a5a24670033649bd2
|
data/lib/tapjoy/ldap/base.rb
CHANGED
@@ -39,20 +39,20 @@ module Tapjoy
|
|
39
39
|
end
|
40
40
|
|
41
41
|
# Add objects to LDAP
|
42
|
-
def add(
|
43
|
-
@conn.add(:dn =>
|
42
|
+
def add(distinguished_name, attributes)
|
43
|
+
@conn.add(:dn => distinguished_name, :attributes => attributes)
|
44
44
|
return return_result
|
45
45
|
end
|
46
46
|
|
47
47
|
# Modify objects in LDAP
|
48
|
-
def modify(
|
49
|
-
@conn.modify(:dn =>
|
48
|
+
def modify(distinguished_name, operations)
|
49
|
+
@conn.modify(:dn => distinguished_name, :operations => operations)
|
50
50
|
return return_result
|
51
51
|
end
|
52
52
|
|
53
53
|
# Delete objects from LDAP
|
54
|
-
def delete(
|
55
|
-
@conn.delete(:dn =>
|
54
|
+
def delete(distinguished_name)
|
55
|
+
@conn.delete(:dn => distinguished_name)
|
56
56
|
return return_result
|
57
57
|
end
|
58
58
|
|
@@ -4,7 +4,7 @@ module Tapjoy
|
|
4
4
|
# Add existing user to existing group
|
5
5
|
class AddUser
|
6
6
|
def add_user
|
7
|
-
puts Tapjoy::LDAP::client.modify(
|
7
|
+
puts Tapjoy::LDAP::client.modify(distinguished_name, operations)
|
8
8
|
end
|
9
9
|
|
10
10
|
private
|
@@ -19,8 +19,8 @@ module Tapjoy
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
@
|
22
|
+
def distinguished_name
|
23
|
+
@distinguished_name ||= "cn=#{opts[:group]},ou=Group,#{Tapjoy::LDAP::client.basedn}"
|
24
24
|
end
|
25
25
|
|
26
26
|
def operations
|
@@ -7,7 +7,7 @@ module Tapjoy
|
|
7
7
|
# Check for errors
|
8
8
|
Trollop::die :type, "argument must be 'user' or 'service'" unless ['user', 'service'].include?opts[:type]
|
9
9
|
|
10
|
-
puts Tapjoy::LDAP::client.add(
|
10
|
+
puts Tapjoy::LDAP::client.add(distinguished_name, ldap_attr)
|
11
11
|
end
|
12
12
|
|
13
13
|
private
|
@@ -23,8 +23,8 @@ module Tapjoy
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
27
|
-
@
|
26
|
+
def distinguished_name
|
27
|
+
@distinguished_name ||= "cn=#{opts[:name]},ou=Group,#{Tapjoy::LDAP::client.basedn}"
|
28
28
|
end
|
29
29
|
|
30
30
|
def ldap_attr
|
@@ -5,7 +5,7 @@ module Tapjoy
|
|
5
5
|
class Delete
|
6
6
|
def delete
|
7
7
|
confirm unless opts[:force]
|
8
|
-
puts Tapjoy::LDAP::client.delete(
|
8
|
+
puts Tapjoy::LDAP::client.delete(distinguished_name)
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
@@ -20,16 +20,16 @@ module Tapjoy
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
@
|
23
|
+
def distinguished_name
|
24
|
+
@distinguished_name ||= "cn=#{opts[:name]},ou=Group,#{Tapjoy::LDAP::client.basedn}"
|
25
25
|
end
|
26
26
|
|
27
27
|
def confirm
|
28
|
-
puts "Confirm that you want to delete group #{opts[:
|
28
|
+
puts "Confirm that you want to delete group #{opts[:name]} (yes/no)"
|
29
29
|
print '>'
|
30
30
|
confirm = STDIN.gets.chomp().downcase
|
31
31
|
unless confirm.eql?('y') || confirm.eql?('yes')
|
32
|
-
abort("Deletion of #{ opts[:
|
32
|
+
abort("Deletion of #{ opts[:name] } aborted")
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -5,46 +5,23 @@ module Tapjoy
|
|
5
5
|
module User
|
6
6
|
# Create LDAP user
|
7
7
|
class Create
|
8
|
-
def opts
|
9
|
-
@opts ||= Trollop::options do
|
10
|
-
# Set help message
|
11
|
-
usage 'user create [options]'
|
12
|
-
synopsis "\nThis command is for creating new LDAP users"
|
13
|
-
|
14
|
-
# Username is two arguments
|
15
|
-
# Trollop will accept more, but we will only parse two later
|
16
|
-
# TODO: support given names that include a space
|
17
|
-
opt :user, "Specify user's first and last name", type: :strings, required: true
|
18
|
-
|
19
|
-
# Groupname is a single string, for primary group setting
|
20
|
-
opt :group, 'Specify name of primary group', type: :string, required: true
|
21
|
-
opt :type, 'Specfy if this is a user or service account', type: :string, default: 'user'
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def uidnumber
|
26
|
-
@uidnumber ||= Tapjoy::LDAP::client.get_max_id('user', opts[:type])
|
27
|
-
end
|
28
|
-
|
29
|
-
def gidnumber
|
30
|
-
@gidnumber ||= Tapjoy::LDAP::Group.lookup_id(opts[:group])
|
31
|
-
end
|
32
|
-
|
33
8
|
def create
|
34
9
|
# Check for errors
|
35
10
|
Trollop::die :user, 'argument count must be two' if opts[:user].size != 2
|
36
11
|
Trollop::die :type, "argument must be 'user' or 'service'" unless ['user', 'service'].include?opts[:type]
|
37
12
|
|
38
|
-
puts Tapjoy::LDAP::client.add(
|
13
|
+
puts Tapjoy::LDAP::client.add(distinguished_name, ldap_attr)
|
39
14
|
end
|
40
15
|
|
41
16
|
private
|
42
17
|
def create_password
|
43
18
|
# Super-Salt: bad for blood pressure, good for secure passwords
|
44
19
|
# We can get away with this, since we're not planning on using passwords
|
45
|
-
|
46
|
-
|
47
|
-
|
20
|
+
@create_password ||= begin
|
21
|
+
salt = SecureRandom.base64(32)
|
22
|
+
password = SecureRandom.base64(64)
|
23
|
+
password = Digest::SHA1.base64digest(password + salt)
|
24
|
+
end
|
48
25
|
end
|
49
26
|
|
50
27
|
def username
|
@@ -68,22 +45,47 @@ module Tapjoy
|
|
68
45
|
}
|
69
46
|
end
|
70
47
|
|
71
|
-
def
|
72
|
-
@
|
48
|
+
def distinguished_name
|
49
|
+
@distinguished_name ||= "uid=#{username},ou=#{organizational_unit},#{Tapjoy::LDAP::client.basedn}"
|
73
50
|
end
|
74
51
|
|
75
|
-
def
|
76
|
-
@
|
52
|
+
def organizational_unit
|
53
|
+
@organizational_unit ||= begin
|
77
54
|
case opts[:type]
|
78
55
|
when 'user'
|
79
|
-
|
56
|
+
'People'
|
80
57
|
when 'service'
|
81
|
-
|
58
|
+
Tapjoy::LDAP::client.service_ou
|
82
59
|
else
|
83
60
|
puts 'Unknown type'
|
84
61
|
end
|
85
62
|
end
|
86
63
|
end
|
64
|
+
|
65
|
+
def uidnumber
|
66
|
+
@uidnumber ||= Tapjoy::LDAP::client.get_max_id('user', opts[:type])
|
67
|
+
end
|
68
|
+
|
69
|
+
def gidnumber
|
70
|
+
@gidnumber ||= Tapjoy::LDAP::Group.lookup_id(opts[:group])
|
71
|
+
end
|
72
|
+
|
73
|
+
def opts
|
74
|
+
@opts ||= Trollop::options do
|
75
|
+
# Set help message
|
76
|
+
usage 'user create [options]'
|
77
|
+
synopsis "\nThis command is for creating new LDAP users"
|
78
|
+
|
79
|
+
# Username is two arguments
|
80
|
+
# Trollop will accept more, but we will only parse two later
|
81
|
+
# TODO: support given names that include a space
|
82
|
+
opt :user, "Specify user's first and last name", type: :strings, required: true
|
83
|
+
|
84
|
+
# Groupname is a single string, for primary group setting
|
85
|
+
opt :group, 'Specify name of primary group', type: :string, required: true
|
86
|
+
opt :type, 'Specfy if this is a user or service account', type: :string, default: 'user'
|
87
|
+
end
|
88
|
+
end
|
87
89
|
end
|
88
90
|
end
|
89
91
|
end
|
@@ -3,33 +3,49 @@ module Tapjoy
|
|
3
3
|
module User
|
4
4
|
# Delete LDAP user
|
5
5
|
class Delete
|
6
|
+
def delete
|
7
|
+
confirm unless opts[:force]
|
8
|
+
puts Tapjoy::LDAP::client.delete(distinguished_name)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
6
12
|
def opts
|
7
13
|
@opts ||= Trollop::options do
|
8
14
|
# Set help message
|
9
15
|
usage "user delete [options]"
|
10
16
|
|
11
|
-
opt
|
12
|
-
opt
|
17
|
+
opt :user, 'Specify username', type: :string, required: true
|
18
|
+
opt :force, 'Force delete'
|
19
|
+
opt :type, 'Specfy if this is a user or service account', type: :string, default: 'user'
|
13
20
|
end
|
14
21
|
end
|
15
22
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
def distinguished_name
|
24
|
+
@distinguished_name ||= "uid=#{opts[:user]},ou=#{organizational_unit},#{Tapjoy::LDAP::client.basedn}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def confirm
|
28
|
+
puts "Confirm that you want to delete user: #{opts[:user]} (yes/no)"
|
29
|
+
print '>'
|
30
|
+
confirm = STDIN.gets.chomp().downcase
|
31
|
+
unless confirm.eql?('y') || confirm.eql?('yes')
|
32
|
+
abort("Deletion of #{ opts[:user] } aborted")
|
26
33
|
end
|
34
|
+
end
|
27
35
|
|
28
|
-
|
36
|
+
def organizational_unit
|
37
|
+
@organizational_unit ||= begin
|
38
|
+
case opts[:type]
|
39
|
+
when 'user'
|
40
|
+
'People'
|
41
|
+
when 'service'
|
42
|
+
Tapjoy::LDAP::client.service_ou
|
43
|
+
else
|
44
|
+
puts 'Unknown type'
|
45
|
+
end
|
46
|
+
end
|
29
47
|
end
|
30
48
|
end
|
31
49
|
end
|
32
50
|
end
|
33
51
|
end
|
34
|
-
# def delete
|
35
|
-
# options = {}
|
data/lib/tapjoy/ldap/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ldap_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ali Tayarani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trollop
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
55
69
|
description: A set of tools to make managing LDAP users, groups, and keys easier
|
56
70
|
email: ali.tayarani@tapjoy.com
|
57
71
|
executables:
|