yaleldap 0.0.2 → 1.0.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/.hound.yml +2 -0
- data/.travis.yml +7 -0
- data/Gemfile +1 -0
- data/Guardfile +11 -0
- data/README.md +15 -12
- data/Rakefile +15 -1
- data/lib/yaleldap/version.rb +1 -1
- data/lib/yaleldap.rb +90 -82
- data/spec/spec_helper.rb +4 -0
- data/spec/yaleldap_spec.rb +10 -0
- data/yaleldap.gemspec +4 -0
- metadata +52 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22865d39103fa944e24f2889695cb00bcb35e1ae
|
4
|
+
data.tar.gz: 9f15790fe82aa385ff9ba4816549b32a568084b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7370b4871fe629f53934c40dbd8587884d5a45332d0ad56ea1de10f179f4e0803b7fcdfa5388891ab1582d0693251b5fbe3db250d58b6ea8b55bf80a3b3a11ba
|
7
|
+
data.tar.gz: a310204d85fbd47026089a50b69be846258d0e396bb24b9998882635d762ad0622d165629b2b0fba3719761f00eb473298d3906a20a262ebd346b66f3c7d8a74
|
data/.hound.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Guardfile
ADDED
data/README.md
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
[](http://badge.fury.io/rb/yaleldap)
|
2
2
|
[](https://gemnasium.com/YaleSTC/yaleldap)
|
3
|
+
[](https://travis-ci.org/YaleSTC/yaleldap)
|
4
|
+
[](https://codeclimate.com/github/YaleSTC/yaleldap)
|
5
|
+
[](https://codeclimate.com/github/YaleSTC/yaleldap)
|
3
6
|
[](http://inch-ci.org/github/YaleSTC/yaleldap)
|
4
7
|
|
5
|
-
#
|
8
|
+
# YaleLDAP
|
6
9
|
|
7
|
-
|
10
|
+
Offers the most common Yale LDAP search queries, returning a convenient ruby hash with names you can understand. Makes it easy to conserve your Yale users' time and energy, saving them from typing again and again that basic information they *know* mother Yale already has on record.
|
11
|
+
|
12
|
+
The LDAP server can only be connected to from Yale's campus or on Yale's VPN.
|
8
13
|
|
9
14
|
## Installation
|
10
15
|
|
@@ -24,29 +29,27 @@ Or install it yourself as:
|
|
24
29
|
|
25
30
|
###UPI
|
26
31
|
```
|
27
|
-
YaleLDAP.
|
28
|
-
=> {:first_name=>"Casey", :last_name=>"Watts", :
|
32
|
+
YaleLDAP.lookup(upi: "12714662")
|
33
|
+
=> {:first_name=>"Casey", :nickname=>"", :last_name=>"Watts", :upi=>"12714662", :netid=>"csw3", :email=>"casey.watts@yale.edu", :college_name=>"", :college_abbreviation=>"", :class_year=>"", :school=>"", :telephone=>"", :address=>"ITS Student Technology Collaborative\nPO BOX 208300\nNew Haven, CT 06520-8300"}
|
29
34
|
```
|
30
35
|
|
31
36
|
###NetID
|
32
37
|
```
|
33
|
-
YaleLDAP.
|
34
|
-
=> {:first_name=>"Casey", :last_name=>"Watts", :
|
38
|
+
YaleLDAP.lookup(netid: "csw3")
|
39
|
+
=> {:first_name=>"Casey", :nickname=>"", :last_name=>"Watts", :upi=>"12714662", :netid=>"csw3", :email=>"casey.watts@yale.edu", :college_name=>"", :college_abbreviation=>"", :class_year=>"", :school=>"", :telephone=>"", :address=>"ITS Student Technology Collaborative\nPO BOX 208300\nNew Haven, CT 06520-8300"}
|
35
40
|
```
|
36
41
|
|
37
42
|
###Email
|
38
43
|
```
|
39
|
-
YaleLDAP.
|
40
|
-
=> {:first_name=>"Casey", :last_name=>"Watts", :
|
44
|
+
YaleLDAP.lookup(email: "casey.watts@yale.edu")
|
45
|
+
=> {:first_name=>"Casey", :nickname=>"", :last_name=>"Watts", :upi=>"12714662", :netid=>"csw3", :email=>"casey.watts@yale.edu", :college_name=>"", :college_abbreviation=>"", :class_year=>"", :school=>"", :telephone=>"", :address=>"ITS Student Technology Collaborative\nPO BOX 208300\nNew Haven, CT 06520-8300"}
|
41
46
|
```
|
42
47
|
|
43
48
|
|
44
49
|
## Documentation
|
45
|
-
The source code is documented on rdoc.info
|
46
|
-
|
47
|
-
<http://rdoc.info/github/YaleSTC/yaleldap/master/frames>
|
50
|
+
The source code is documented thoroughly, view it on [rdoc.info](http://rdoc.info/github/YaleSTC/yaleldap/master/frames)
|
48
51
|
|
49
|
-
For more background on how the `net-ldap` gem works, check out this [Yale-
|
52
|
+
For more background on how the `net-ldap` gem works with specific Yale examples, check out this [Yale net-ldap gist](https://gist.github.com/caseywatts/ddea3996853050d1e5ad).
|
50
53
|
|
51
54
|
## Contributing
|
52
55
|
|
data/Rakefile
CHANGED
@@ -1 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
# Default directory to look in is `/specs`
|
5
|
+
# Run with `rake spec`
|
6
|
+
# RSpec::Core::RakeTask.new(:spec) do |task|
|
7
|
+
# task.rspec_opts = ['--color', '--format', 'documentation']
|
8
|
+
# end
|
9
|
+
|
10
|
+
# task spec do
|
11
|
+
# 'bundle exec rspec spec --color --format documentation'
|
12
|
+
# end
|
13
|
+
|
14
|
+
RSpec::Core::RakeTask.new(:spec)
|
15
|
+
task :default => :spec
|
data/lib/yaleldap/version.rb
CHANGED
data/lib/yaleldap.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "yaleldap/version"
|
2
2
|
require "net-ldap"
|
3
3
|
|
4
|
-
#YaleLDAP Module
|
4
|
+
#YaleLDAP Module contains the logic for YaleLDAP
|
5
5
|
module YaleLDAP
|
6
6
|
# Yale's LDAP Host
|
7
7
|
LDAP_HOST = 'directory.yale.edu'
|
@@ -12,101 +12,109 @@ module YaleLDAP
|
|
12
12
|
# Specify to LDAP that we are searching for people
|
13
13
|
LDAP_BASE = 'ou=People,o=yale.edu'
|
14
14
|
|
15
|
-
# The most common Yale LDAP atttributes that we care about extracting
|
16
|
-
LDAP_ATTRS = %w(uid givenname sn mail collegename college class UPI)
|
17
|
-
|
18
15
|
##
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# @param
|
22
|
-
#
|
16
|
+
# lookup by an arbitrary query (netid, email, upi, etc)
|
17
|
+
#
|
18
|
+
# @param [Hash] input_hash the query we're looking up with just one key-value pair. It expects the keys 'email', 'netid', 'upi'.
|
19
|
+
#
|
20
|
+
# @return [hash]
|
21
|
+
# our standard return hash (see README.md for a description of what it returns)
|
23
22
|
#
|
24
|
-
# @return
|
25
|
-
# Standard hash (see extract_attributes)
|
26
|
-
#
|
27
23
|
# @example
|
28
|
-
# YaleLDAP.
|
24
|
+
# YaleLDAP.lookup(email: "casey.watts@yale.edu")
|
25
|
+
# YaleLDAP.lookup(netid: "csw3")
|
26
|
+
# YaleLDAP.lookup(upi: "12714662")
|
27
|
+
#
|
28
|
+
def self.lookup(input_hash)
|
29
|
+
lookup_filter = construct_filter(input_hash)
|
30
|
+
ldap_response = execute_query(lookup_filter)
|
31
|
+
attributes = extract_attributes(ldap_response)
|
32
|
+
return attributes
|
33
|
+
end
|
29
34
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
private
|
36
|
+
|
37
|
+
###
|
38
|
+
# Nickname Logic
|
39
|
+
###
|
40
|
+
|
41
|
+
def self.convert_from_nickname(attribute)
|
42
|
+
attribute = attribute.to_s
|
43
|
+
nicknames[attribute]
|
37
44
|
end
|
38
45
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
# @param
|
43
|
-
# netid as a string, ex "csw3"
|
44
|
-
#
|
45
|
-
# @return
|
46
|
-
# Standard hash (see extract_attributes)
|
47
|
-
#
|
48
|
-
# @example
|
49
|
-
# YaleLDAP.lookup_by_netid("csw3")
|
50
|
-
#
|
51
|
-
def self.lookup_by_netid(netid)
|
52
|
-
ldap = Net::LDAP.new host: LDAP_HOST, port: LDAP_PORT
|
53
|
-
upifilter = Net::LDAP::Filter.eq('uid', netid)
|
54
|
-
ldap_response = ldap.search(base: LDAP_BASE,
|
55
|
-
filter: upifilter,
|
56
|
-
attributes: LDAP_ATTRS)
|
57
|
-
extract_attributes(ldap_response)
|
46
|
+
def self.convert_to_nickname(attribute)
|
47
|
+
attribute = attribute.to_s
|
48
|
+
nicknames.invert[attribute]
|
58
49
|
end
|
59
50
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
51
|
+
def self.search_attributes
|
52
|
+
nicknames.values
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.nicknames
|
56
|
+
# a list of attributes we care about
|
57
|
+
# "nickname" => "ldapname"
|
58
|
+
# "somethingthatmakessense" => "somethingjargony"
|
59
|
+
return {
|
60
|
+
"first_name" => "givenname",
|
61
|
+
"nickname" => "eduPersonNickname",
|
62
|
+
"last_name" => "sn",
|
63
|
+
"upi" => "UPI",
|
64
|
+
"netid" => "uid",
|
65
|
+
"email" => "mail",
|
66
|
+
"college_name" => "collegename",
|
67
|
+
"college_abbreviation" => "college",
|
68
|
+
"class_year" => "class",
|
69
|
+
"school" => "organizationUnitName",
|
70
|
+
"telephone" => "officePhone",
|
71
|
+
"address" => "postalAddress"
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
###
|
78
|
+
#LDAP Search Logic
|
79
|
+
###
|
80
|
+
|
81
|
+
|
82
|
+
# Constructs a Net::LDAP::Filter object out of our user input
|
83
|
+
# @param the input hash we want users to input, such as {:email => "casey.watts@yale.edu"}
|
84
|
+
# @return a net-ldap Net::LDAP::Filter object with our desired query
|
85
|
+
def self.construct_filter(input_hash)
|
86
|
+
query_type_nickname = input_hash.keys.first
|
87
|
+
query_value = input_hash.values.first
|
88
|
+
query_type_ldapname = convert_from_nickname(query_type_nickname)
|
89
|
+
lookup_filter = Net::LDAP::Filter.eq(query_type_ldapname, query_value)
|
90
|
+
return lookup_filter
|
91
|
+
end
|
92
|
+
|
93
|
+
# Executes the query on the LDAP server.
|
94
|
+
# @param a net-ldap Net::LDAP::Filter object with our desired query
|
95
|
+
# @return the raw net-ldap LDAP response object
|
96
|
+
def self.execute_query(lookup_filter)
|
73
97
|
ldap = Net::LDAP.new host: LDAP_HOST, port: LDAP_PORT
|
74
|
-
upifilter = Net::LDAP::Filter.eq('mail', email)
|
75
98
|
ldap_response = ldap.search(base: LDAP_BASE,
|
76
|
-
filter:
|
77
|
-
attributes:
|
78
|
-
|
99
|
+
filter: lookup_filter,
|
100
|
+
attributes: search_attributes)
|
101
|
+
return ldap_response
|
79
102
|
end
|
80
103
|
|
81
|
-
|
82
|
-
#
|
83
|
-
# Input a raw LDAP response
|
84
|
-
#
|
85
|
-
# Output is a hash with keys: first_name, last_name, upi, netid, email, collegename, college, class_year
|
86
|
-
#
|
104
|
+
|
87
105
|
def self.extract_attributes(ldap_response)
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
collegename = ldap_response[0][:collegename][0] || ""
|
97
|
-
college = ldap_response[0][:college][0] || ""
|
98
|
-
class_year = ldap_response[0][:class][0] || ""
|
106
|
+
attributes = {}
|
107
|
+
nicknames.each do |nickname, ldapname|
|
108
|
+
attribute = extract_attribute(ldap_response, ldapname)
|
109
|
+
attribute = attribute.gsub(/\$/,"\n") #for address
|
110
|
+
attributes[nickname.to_sym] = attribute
|
111
|
+
end
|
112
|
+
return attributes
|
113
|
+
end
|
99
114
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
yale_upi: upi,
|
104
|
-
netid: netid,
|
105
|
-
email: email,
|
106
|
-
collegename: collegename,
|
107
|
-
college: college,
|
108
|
-
class_year: class_year
|
109
|
-
}
|
115
|
+
def self.extract_attribute(ldap_response, attribute_name)
|
116
|
+
attribute = ldap_response[0][attribute_name][0]
|
117
|
+
attribute ||= ""
|
110
118
|
end
|
111
119
|
|
112
120
|
end
|
data/spec/spec_helper.rb
ADDED
data/yaleldap.gemspec
CHANGED
@@ -20,5 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.5"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "guard"
|
25
|
+
spec.add_development_dependency "guard-rspec", "~> 3.1.0"
|
26
|
+
|
23
27
|
spec.add_runtime_dependency "net-ldap"
|
24
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaleldap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- caseywatts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,48 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.1.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.1.0
|
41
83
|
- !ruby/object:Gem::Dependency
|
42
84
|
name: net-ldap
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,12 +103,17 @@ extensions: []
|
|
61
103
|
extra_rdoc_files: []
|
62
104
|
files:
|
63
105
|
- .gitignore
|
106
|
+
- .hound.yml
|
107
|
+
- .travis.yml
|
64
108
|
- Gemfile
|
109
|
+
- Guardfile
|
65
110
|
- LICENSE.txt
|
66
111
|
- README.md
|
67
112
|
- Rakefile
|
68
113
|
- lib/yaleldap.rb
|
69
114
|
- lib/yaleldap/version.rb
|
115
|
+
- spec/spec_helper.rb
|
116
|
+
- spec/yaleldap_spec.rb
|
70
117
|
- yaleldap.gemspec
|
71
118
|
homepage: http://github.com/YaleSTC/yaleldap
|
72
119
|
licenses:
|
@@ -92,5 +139,7 @@ rubygems_version: 2.0.3
|
|
92
139
|
signing_key:
|
93
140
|
specification_version: 4
|
94
141
|
summary: Easy connection to Yale's LDAP
|
95
|
-
test_files:
|
142
|
+
test_files:
|
143
|
+
- spec/spec_helper.rb
|
144
|
+
- spec/yaleldap_spec.rb
|
96
145
|
has_rdoc:
|