cratus 0.3.9 → 0.4.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/lib/cratus.rb +1 -0
- data/lib/cratus/group.rb +37 -1
- data/lib/cratus/ldap.rb +15 -2
- data/lib/cratus/user.rb +14 -0
- data/lib/cratus/version.rb +2 -2
- 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: 03546e33c0cbcd721059db8bee9f197fc831b55c
|
4
|
+
data.tar.gz: 9880fb938e1a84cd89fc28d0f4d762a6b3d5371a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0aeb98394522da853724b82fda06d2a429185c29115cb0b74f275362cc8ad738902a144dcf1da5861fc970f012309915927a76c3dee9da5771d160c3d4ce927c
|
7
|
+
data.tar.gz: 80ecee4931f58e86b5cb497d1a34ac0699b9738f65f4734b4217b29273273f9f924af8a0968ba31696394d2d80f03b8eb50da28037498f7706835fea4805d1ae
|
data/lib/cratus.rb
CHANGED
data/lib/cratus/group.rb
CHANGED
@@ -23,6 +23,7 @@ module Cratus
|
|
23
23
|
all_members[:groups]
|
24
24
|
end
|
25
25
|
|
26
|
+
# Recursively determine group memberships of a group
|
26
27
|
def member_of
|
27
28
|
memrof_attr = Cratus.config.group_memberof_attribute
|
28
29
|
|
@@ -48,16 +49,49 @@ module Cratus
|
|
48
49
|
all_the_groups.uniq(&:name)
|
49
50
|
end
|
50
51
|
|
52
|
+
# Returns the LDAP dn for a Group
|
53
|
+
def dn
|
54
|
+
@raw_ldap_data[:dn].last
|
55
|
+
end
|
56
|
+
|
51
57
|
# LDAP description attribute
|
52
58
|
def description
|
53
59
|
@raw_ldap_data[Cratus.config.group_description_attribute].last
|
54
60
|
end
|
55
61
|
|
62
|
+
# Add a User to the group
|
63
|
+
def add_user(user)
|
64
|
+
raise 'InvalidUser' unless user.respond_to?(:dn)
|
65
|
+
direct_members = @raw_ldap_data[Cratus.config.group_member_attribute]
|
66
|
+
return true if direct_members.include?(user.dn)
|
67
|
+
|
68
|
+
direct_members << user.dn
|
69
|
+
Cratus::LDAP.replace_attribute(
|
70
|
+
dn,
|
71
|
+
Cratus.config.group_member_attribute,
|
72
|
+
direct_members.uniq
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Remove a User from the group
|
77
|
+
def remove_user(user)
|
78
|
+
raise 'InvalidUser' unless user.respond_to?(:dn)
|
79
|
+
direct_members = @raw_ldap_data[Cratus.config.group_member_attribute]
|
80
|
+
return true unless direct_members.include?(user.dn)
|
81
|
+
|
82
|
+
direct_members.delete(user.dn)
|
83
|
+
Cratus::LDAP.replace_attribute(
|
84
|
+
dn,
|
85
|
+
Cratus.config.group_member_attribute,
|
86
|
+
direct_members.uniq
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
56
90
|
# All the LDAP Groups
|
57
91
|
def self.all
|
58
92
|
filter = "(#{ldap_dn_attribute}=*)"
|
59
93
|
Cratus::LDAP.search(filter, basedn: ldap_search_base, attrs: ldap_dn_attribute).map do |entry|
|
60
|
-
new(entry[ldap_dn_attribute].last)
|
94
|
+
new(entry[ldap_dn_attribute.to_sym].last)
|
61
95
|
end
|
62
96
|
end
|
63
97
|
|
@@ -82,6 +116,8 @@ module Cratus
|
|
82
116
|
Cratus.config.group_basedn.to_s
|
83
117
|
end
|
84
118
|
|
119
|
+
# Compare based on the group's name
|
120
|
+
# TODO: possibly change to dn
|
85
121
|
def <=>(other)
|
86
122
|
@name <=> other.name
|
87
123
|
end
|
data/lib/cratus/ldap.rb
CHANGED
@@ -58,7 +58,16 @@ module Cratus
|
|
58
58
|
base: options[:basedn], filter: filter,
|
59
59
|
scope: scope_class, attributes: [*attrs].map(&:to_s)
|
60
60
|
)
|
61
|
-
results.nil? ? raise(
|
61
|
+
results.nil? ? raise(Exceptions::FailedLDAPSearch) : results.compact
|
62
|
+
end
|
63
|
+
|
64
|
+
# Modify an LDAP object's attribute
|
65
|
+
def self.replace_attribute(dn, attribute, values)
|
66
|
+
validate_ldap_connection
|
67
|
+
validate_ldap_bound
|
68
|
+
validate_attribute_values(values)
|
69
|
+
|
70
|
+
connection.replace_attribute(dn, attribute, values)
|
62
71
|
end
|
63
72
|
|
64
73
|
# Validation Methods
|
@@ -79,10 +88,14 @@ module Cratus
|
|
79
88
|
end
|
80
89
|
end
|
81
90
|
|
91
|
+
def self.validate_attribute_values(values)
|
92
|
+
raise 'Values Must Be Array' unless values.is_a?(Array)
|
93
|
+
end
|
94
|
+
|
82
95
|
def self.validate_connection_options(options)
|
83
96
|
raise 'Invalid Options' unless options.respond_to?(:key?)
|
84
97
|
|
85
|
-
[
|
98
|
+
%i[host port basedn username password].each do |key|
|
86
99
|
raise "Missing Option: #{key}" unless options.key?(key)
|
87
100
|
end
|
88
101
|
end
|
data/lib/cratus/user.rb
CHANGED
@@ -14,6 +14,20 @@ module Cratus
|
|
14
14
|
).last
|
15
15
|
end
|
16
16
|
|
17
|
+
# Add a user to a group
|
18
|
+
def add_to_group(group)
|
19
|
+
raise 'InvalidGroup' unless group.respond_to?(:add_user)
|
20
|
+
# just be lazy and hand off to the group to do the work...
|
21
|
+
group.add_user(self)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Remove a user from a group
|
25
|
+
def remove_from_group(group)
|
26
|
+
raise 'InvalidGroup' unless group.respond_to?(:remove_user)
|
27
|
+
# just be lazy and hand off to the group to do the work...
|
28
|
+
group.remove_user(self)
|
29
|
+
end
|
30
|
+
|
17
31
|
def department
|
18
32
|
@raw_ldap_data[Cratus.config.user_department_attribute].last
|
19
33
|
end
|
data/lib/cratus/version.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
module Cratus
|
3
3
|
def self.version
|
4
4
|
major = 0 # Breaking, incompatible releases
|
5
|
-
minor =
|
6
|
-
patch =
|
5
|
+
minor = 4 # Compatible, but new features
|
6
|
+
patch = 0 # Fixes to existing features
|
7
7
|
[major, minor, patch].map(&:to_s).join('.')
|
8
8
|
end
|
9
9
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cratus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Gnagy
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-04-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: colorize
|