ldap_tools 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7d2b4ae5491bcebae2318c2dc46951ece6f8f40
4
- data.tar.gz: ada74daf88e6dac99d8ac682237086bfc3b8053d
3
+ metadata.gz: c580acd38fa44077ad2175af8c7525b25c22dfcd
4
+ data.tar.gz: 9002e5285f2eb0964a53e587b757cbf60492392c
5
5
  SHA512:
6
- metadata.gz: 67143d818be7aa3a5ab3b81419fa070b8e55605c8dd54c41acfcaf3c940a9e29cbcd976eb0372e5ee207c19ddb1ec6394420d6e83f7f20f381c7fb38f1b73a93
7
- data.tar.gz: bc332e9380127cfc4152481720841a70707e1ff0fd7e49182fb19c577d15db7efc2f6d7679ca180eb34abab34bed4389d94a65aed263e8ce0ed2386ea1400732
6
+ metadata.gz: 372a3e9e8013fe642ddbcfbceb1f1dead4a0e68874f7b968e6957bca2709697ad0fc7d303a6730cdde21216b536a596c5f17ccd83983e49712d1b664f75fad12
7
+ data.tar.gz: d3662bc277bd26599a19dba670f96c261c55ddf617b93196f68762836c75ed4e190162e54088a1d810b2aa138bf00ddf997cc90e6e7fdf6cba3b8a697e1a746a
data/bin/ldaptools CHANGED
@@ -1,35 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'tapjoy/ldap'
3
3
 
4
- # @TODO: Remove this in favor of newer methods
5
- def commands(synopsis, object, sub_commands)
6
- Trollop::options do
7
- usage "#{object} [SUB_COMMAND] [options]"
8
- synopsis "\n#{synopsis}.\nAvailable subcommands are: #{sub_commands}"
9
- stop_on sub_commands
10
- end
11
- end
12
-
13
- SUB_COMMANDS = %w(user group key audit)
14
- Trollop::options do
15
- usage '[SUB_COMMAND] [options]'
16
- synopsis "\nTool to manage LDAP resources.\nAvailable subcommands are: #{SUB_COMMANDS}"
17
- version "#{File.basename($PROGRAM_NAME)} #{Tapjoy::LDAP::VERSION} \u00A9 2015 Tapjoy, Inc."
18
- stop_on SUB_COMMANDS
19
- end
20
-
21
- cmd = ARGV.shift # get the subcommand
22
- case cmd
23
- when 'user' # run commands associated with user object
24
- Tapjoy::LDAP::User.commands
25
- when 'group'
26
- Tapjoy::LDAP::Group.commands
27
- when 'key'
28
- Tapjoy::LDAP::Key.commands
29
- when 'audit'
30
- # AUDIT_SUB_COMMANDS = %w(by_user by_group raw)
31
- # commands(, cmd, AUDIT_SUB_COMMANDS)
32
- Tapjoy::LDAP::Audit.commands
33
- else
34
- raise Tapjoy::LDAP::InvalidArgument
35
- end
4
+ Tapjoy::LDAP::CLI.commands
5
+ # Tapjoy::LDAP::API::User.create('ali', 'tayarani', 'user', 'users')
6
+ # Tapjoy::LDAP::API::User.destroy('ali.tayarani', 'user')
@@ -0,0 +1,112 @@
1
+ require 'memoist'
2
+ module Tapjoy
3
+ module LDAP
4
+ module API
5
+ module User
6
+ class << self
7
+ extend Memoist
8
+ def create(fname, lname, type, group)
9
+ # Properly capitalize names
10
+ fname, lname = [fname, lname].map(&:capitalize)
11
+
12
+ Tapjoy::LDAP::client.add(
13
+ distinguished_name(fname, lname, type),
14
+ ldap_attr(fname, lname, type, group)
15
+ )
16
+ end
17
+
18
+ def destroy(username, type)
19
+ Tapjoy::LDAP::client.delete(
20
+ distinguished_name(*name_of_user(username), type)
21
+ )
22
+ end
23
+
24
+ def index
25
+ Tapjoy::LDAP::client.search('*', filter(uid: '*'))
26
+ end
27
+
28
+ def show(username)
29
+ Tapjoy::LDAP::client.search('*', filter(uid: username))
30
+ end
31
+
32
+ private
33
+
34
+ # Filter users for #show and #index
35
+ def filter(uid: '*')
36
+ Net::LDAP::Filter.eq('uid', uid)
37
+ end
38
+
39
+ # Given a username, return First and Last names
40
+ def name_of_user(username)
41
+ username.split('.').map(&:capitalize)
42
+ end
43
+ memoize :name_of_user
44
+
45
+ # Given First and Last names, return a username
46
+ def username(fname, lname)
47
+ [fname, lname].join('.').downcase
48
+ end
49
+ memoize :username
50
+
51
+ def distinguished_name(fname, lname, type)
52
+ %W(
53
+ uid=#{username(fname, lname)}
54
+ ou=#{organizational_unit(type)}
55
+ #{Tapjoy::LDAP::client.basedn}).join(',')
56
+ end
57
+ memoize :distinguished_name
58
+
59
+ def organizational_unit(type)
60
+ case type
61
+ when 'user'
62
+ 'People'
63
+ when 'service'
64
+ Tapjoy::LDAP::client.service_ou
65
+ else
66
+ puts 'Unknown type'
67
+ end
68
+ end
69
+ memoize :organizational_unit
70
+
71
+ def ldap_attr(fname, lname, type, group)
72
+ uid = username(fname, lname)
73
+ {
74
+ uid: uid,
75
+ cn: [fname, lname].join(' '),
76
+ objectclass: %w(top posixAccount shadowAccount inetOrgPerson
77
+ organizationalPerson person ldapPublicKey),
78
+ sn: lname,
79
+ givenname: fname,
80
+ # Empty string is an alias for the root of the FS
81
+ homedirectory: File.join('','home', uid),
82
+ loginshell: File.join('','bin', 'bash'),
83
+ mail: "#{uid}@tapjoy.com",
84
+ uidnumber: uidnumber(type),
85
+ gidnumber: gidnumber(group),
86
+ userpassword: '{SSHA}' + create_password
87
+ }
88
+ end
89
+ memoize :ldap_attr
90
+
91
+ def uidnumber(type)
92
+ Tapjoy::LDAP::client.get_max_id('user', type)
93
+ end
94
+ memoize :uidnumber
95
+
96
+ def gidnumber(group)
97
+ Tapjoy::LDAP::Group.lookup_id(group)
98
+ end
99
+ memoize :gidnumber
100
+
101
+ def create_password
102
+ # Super-Salt: bad for blood pressure, good for secure passwords
103
+ # We can get away with this, since we're not planning on using passwords
104
+ salt = SecureRandom.base64(32)
105
+ password = SecureRandom.base64(64)
106
+ password = Digest::SHA1.base64digest(password + salt)
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,42 @@
1
+ module Tapjoy
2
+ module LDAP
3
+ module CLI
4
+ module User
5
+ # Manipulates data to a format usable by the API structure
6
+ class Create
7
+ # Tapjoy::LDAP::CLI::User::Create#create
8
+ # Make the API call to create an LDAP user
9
+ def create
10
+ verify_arguments
11
+ fname, lname = opts[:user]
12
+ puts Tapjoy::LDAP::API::User.create(fname, lname,
13
+ opts[:type], opts[:group])
14
+ end
15
+
16
+ private
17
+ def opts
18
+ @opts ||= Trollop::options do
19
+ # Set help message
20
+ usage 'user create [options]'
21
+ synopsis "\nThis command is for creating new LDAP users"
22
+
23
+ # Username is two arguments
24
+ # Trollop will accept more, but we will only parse two later
25
+ # TODO: support given names that include a space
26
+ opt :user, "Specify user's first and last name", type: :strings, required: true
27
+
28
+ # Groupname is a single string, for primary group setting
29
+ opt :group, 'Specify name of primary group', type: :string, required: true
30
+ opt :type, 'Specfy if this is a user or service account', type: :string, default: 'user'
31
+ end
32
+ end
33
+
34
+ def verify_arguments
35
+ Trollop::die :user, 'argument count must be two' if opts[:user].size != 2
36
+ Trollop::die :type, "argument must be 'user' or 'service'" unless %w(user service).include?opts[:type]
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,43 @@
1
+ module Tapjoy
2
+ module LDAP
3
+ module CLI
4
+ module User
5
+ # Manipulates data to a format usable
6
+ # by the API structure for user removal
7
+ class Delete
8
+ # Make the API call to remove an LDAP user
9
+ def delete
10
+ verify_arguments
11
+ confirm unless opts[:force]
12
+ puts Tapjoy::LDAP::API::User.destroy(opts[:user], opts[:type])
13
+ end
14
+
15
+ private
16
+ def opts
17
+ @opts ||= Trollop::options do
18
+ # Set help message
19
+ usage "user delete [options]"
20
+
21
+ opt :user, 'Specify username', type: :string, required: true
22
+ opt :force, 'Force delete'
23
+ opt :type, 'Specfy if this is a user or service account', type: :string, default: 'user'
24
+ end
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")
33
+ end
34
+ end
35
+
36
+ def verify_arguments
37
+ Trollop::die :type, "argument must be 'user' or 'service'" unless %w(user service).include?opts[:type]
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,34 @@
1
+ module Tapjoy
2
+ module LDAP
3
+ module CLI
4
+ module User
5
+ # Manipulates data to a format usable
6
+ # by the API structure for user display
7
+ class Show
8
+ # Make the API call to show an LDAP user
9
+ def show
10
+ Tapjoy::LDAP::API::User.show(opts[:user]).each do |entry|
11
+ puts "DN: #{entry.dn}"
12
+ entry.each do |attribute, values|
13
+ puts " #{attribute}:"
14
+ values.each do |value|
15
+ puts " --->#{value}"
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ private
22
+ def opts
23
+ @opts ||= Trollop::options do
24
+ # Set help message
25
+ usage "user show [options]"
26
+
27
+ opt :user, 'Specify username', type: :string, required: true
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,62 @@
1
+ require_relative 'user/create'
2
+ require_relative 'user/delete'
3
+ require_relative 'user/show'
4
+ require_relative '../api/user'
5
+ module Tapjoy
6
+ module LDAP
7
+ module CLI
8
+ # CLI Module for all user commands
9
+ module User
10
+ class << self
11
+ SUB_COMMANDS = %w(create delete index show)
12
+
13
+ def commands
14
+ Trollop::options do
15
+ usage 'user [SUB_COMMAND] [options]'
16
+ synopsis "\nThis object is used for user management\nAvailable subcommands are: #{SUB_COMMANDS}"
17
+
18
+ stop_on SUB_COMMANDS
19
+ end
20
+
21
+ cmd = ARGV.shift
22
+
23
+ case cmd
24
+ when 'create', 'delete', 'index', 'show'
25
+ send(cmd) # call method with respective name
26
+ else
27
+ raise Tapjoy::LDAP::InvalidArgument
28
+ end
29
+ end
30
+
31
+ def create
32
+ user = Tapjoy::LDAP::CLI::User::Create.new
33
+ user.create
34
+ end
35
+
36
+ def delete
37
+ user = Tapjoy::LDAP::CLI::User::Delete.new
38
+ user.delete
39
+ end
40
+
41
+ def index
42
+ Tapjoy::LDAP::API::User.index.each do |entry|
43
+ puts "DN: #{entry.dn}"
44
+ entry.each do |attribute, values|
45
+ puts " #{attribute}:"
46
+ values.each do |value|
47
+ puts " --->#{value}"
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ def show
54
+ user = Tapjoy::LDAP::CLI::User::Show.new
55
+ user.show
56
+ end
57
+
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'cli/user'
2
+
3
+ module Tapjoy
4
+ module LDAP
5
+ module CLI
6
+ class << self
7
+ def commands
8
+ subcommand = %w(user group key audit)
9
+ Trollop::options do
10
+ usage '[SUB_COMMAND] [options]'
11
+ synopsis "\nTool to manage LDAP resources.\nAvailable subcommands are: #{subcommand}"
12
+ version "#{File.basename($PROGRAM_NAME)} #{Tapjoy::LDAP::VERSION} \u00A9 2015 Tapjoy, Inc."
13
+ stop_on subcommand
14
+ end
15
+
16
+ cmd = ARGV.shift # get the subcommand
17
+ case cmd
18
+ when 'user'
19
+ Tapjoy::LDAP::CLI::User.commands
20
+ when 'group'
21
+ Tapjoy::LDAP::Group.commands
22
+ when 'key'
23
+ Tapjoy::LDAP::Key.commands
24
+ when 'audit'
25
+ Tapjoy::LDAP::Audit.commands
26
+ else
27
+ raise Tapjoy::LDAP::InvalidArgument
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -2,8 +2,8 @@ module Tapjoy
2
2
  module LDAP
3
3
  module Version
4
4
  MAJOR = 0
5
- MINOR = 7
6
- PATCH = 2
5
+ MINOR = 8
6
+ PATCH = 0
7
7
  end
8
8
 
9
9
  VERSION = [Version::MAJOR, Version::MINOR, Version::PATCH].join('.')
data/lib/tapjoy/ldap.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'net/ldap'
2
2
  require 'yaml'
3
3
  require 'trollop'
4
+ require_relative 'ldap/cli'
4
5
  require_relative 'ldap/base'
5
6
  require_relative 'ldap/group'
6
7
  require_relative 'ldap/key'
7
- require_relative 'ldap/user'
8
8
  require_relative 'ldap/audit'
9
9
  require_relative 'ldap/version'
10
10
 
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.7.2
4
+ version: 0.8.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: 2016-01-25 00:00:00.000000000 Z
11
+ date: 2016-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: memoist
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0.14'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.2'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rspec
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +94,90 @@ dependencies:
66
94
  - - "~>"
67
95
  - !ruby/object:Gem::Version
68
96
  version: '3.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.8'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.8'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.13'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.13'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-bundler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.1'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.1'
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard-rubycritic
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '2.9'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2.9'
153
+ - !ruby/object:Gem::Dependency
154
+ name: guard-yard
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '2.1'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '2.1'
167
+ - !ruby/object:Gem::Dependency
168
+ name: guard-yardstick
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '0.1'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '0.1'
69
181
  description: A set of tools to make managing LDAP users, groups, and keys easier
70
182
  email: ali.tayarani@tapjoy.com
71
183
  executables:
@@ -75,10 +187,16 @@ extra_rdoc_files: []
75
187
  files:
76
188
  - bin/ldaptools
77
189
  - lib/tapjoy/ldap.rb
190
+ - lib/tapjoy/ldap/api/user.rb
78
191
  - lib/tapjoy/ldap/audit.rb
79
192
  - lib/tapjoy/ldap/audit/by_group.rb
80
193
  - lib/tapjoy/ldap/audit/by_user.rb
81
194
  - lib/tapjoy/ldap/base.rb
195
+ - lib/tapjoy/ldap/cli.rb
196
+ - lib/tapjoy/ldap/cli/user.rb
197
+ - lib/tapjoy/ldap/cli/user/create.rb
198
+ - lib/tapjoy/ldap/cli/user/delete.rb
199
+ - lib/tapjoy/ldap/cli/user/show.rb
82
200
  - lib/tapjoy/ldap/group.rb
83
201
  - lib/tapjoy/ldap/group/add_user.rb
84
202
  - lib/tapjoy/ldap/group/create.rb
@@ -89,9 +207,6 @@ files:
89
207
  - lib/tapjoy/ldap/key/install.rb
90
208
  - lib/tapjoy/ldap/key/remove.rb
91
209
  - lib/tapjoy/ldap/key/show.rb
92
- - lib/tapjoy/ldap/user.rb
93
- - lib/tapjoy/ldap/user/create.rb
94
- - lib/tapjoy/ldap/user/delete.rb
95
210
  - lib/tapjoy/ldap/version.rb
96
211
  homepage: https://github.com/Tapjoy/ldap_tools
97
212
  licenses:
@@ -105,7 +220,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
220
  requirements:
106
221
  - - ">="
107
222
  - !ruby/object:Gem::Version
108
- version: '2.1'
223
+ version: '2.2'
109
224
  required_rubygems_version: !ruby/object:Gem::Requirement
110
225
  requirements:
111
226
  - - ">="
@@ -118,3 +233,4 @@ signing_key:
118
233
  specification_version: 4
119
234
  summary: Tapjoy LDAP Tools
120
235
  test_files: []
236
+ has_rdoc:
@@ -1,92 +0,0 @@
1
- require 'digest'
2
- require 'securerandom'
3
- module Tapjoy
4
- module LDAP
5
- module User
6
- # Create LDAP user
7
- class Create
8
- def create
9
- # Check for errors
10
- Trollop::die :user, 'argument count must be two' if opts[:user].size != 2
11
- Trollop::die :type, "argument must be 'user' or 'service'" unless ['user', 'service'].include?opts[:type]
12
-
13
- puts Tapjoy::LDAP::client.add(distinguished_name, ldap_attr)
14
- end
15
-
16
- private
17
- def create_password
18
- # Super-Salt: bad for blood pressure, good for secure passwords
19
- # We can get away with this, since we're not planning on using passwords
20
- @create_password ||= begin
21
- salt = SecureRandom.base64(32)
22
- password = SecureRandom.base64(64)
23
- password = Digest::SHA1.base64digest(password + salt)
24
- end
25
- end
26
-
27
- def username
28
- @username ||= opts[:user].join('.').downcase
29
- end
30
-
31
- def ldap_attr
32
- @ldap_attr ||= {
33
- :uid => username,
34
- :cn => "#{opts[:user].join}",
35
- :objectclass => ['top','posixAccount','shadowAccount','inetOrgPerson',
36
- 'organizationalPerson','person', 'ldapPublicKey'],
37
- :sn => opts[:user][1],
38
- :givenname => opts[:user][0],
39
- :homedirectory => "/home/#{ username }",
40
- :loginshell => '/bin/bash',
41
- :mail => "#{username}@tapjoy.com".downcase,
42
- :uidnumber => uidnumber,
43
- :gidnumber => gidnumber,
44
- :userpassword => '{SSHA}' + create_password
45
- }
46
- end
47
-
48
- def distinguished_name
49
- @distinguished_name ||= "uid=#{username},ou=#{organizational_unit},#{Tapjoy::LDAP::client.basedn}"
50
- end
51
-
52
- def organizational_unit
53
- @organizational_unit ||= begin
54
- case opts[:type]
55
- when 'user'
56
- 'People'
57
- when 'service'
58
- Tapjoy::LDAP::client.service_ou
59
- else
60
- puts 'Unknown type'
61
- end
62
- end
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
89
- end
90
- end
91
- end
92
- end
@@ -1,51 +0,0 @@
1
- module Tapjoy
2
- module LDAP
3
- module User
4
- # Delete LDAP user
5
- class Delete
6
- def delete
7
- confirm unless opts[:force]
8
- puts Tapjoy::LDAP::client.delete(distinguished_name)
9
- end
10
-
11
- private
12
- def opts
13
- @opts ||= Trollop::options do
14
- # Set help message
15
- usage "user delete [options]"
16
-
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'
20
- end
21
- end
22
-
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")
33
- end
34
- end
35
-
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
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,41 +0,0 @@
1
- require_relative 'user/create'
2
- require_relative 'user/delete'
3
-
4
- module Tapjoy
5
- module LDAP
6
- # Entry point for all user subcommands
7
- module User
8
- class << self
9
- SUB_COMMANDS = %w(create delete)
10
-
11
- def commands
12
- Trollop::options do
13
- usage 'user [SUB_COMMAND] [options]'
14
- synopsis "\nThis object is used for user management\nAvailable subcommands are: #{SUB_COMMANDS}"
15
-
16
- stop_on SUB_COMMANDS
17
- end
18
-
19
- cmd = ARGV.shift
20
-
21
- case cmd
22
- when 'create', 'delete'
23
- send(cmd) # call method with respective name
24
- else
25
- raise Tapjoy::LDAP::InvalidArgument
26
- end
27
- end
28
-
29
- def create
30
- user = Tapjoy::LDAP::User::Create.new
31
- user.create
32
- end
33
-
34
- def delete
35
- user = Tapjoy::LDAP::User::Delete.new
36
- user.delete
37
- end
38
- end
39
- end
40
- end
41
- end