yaleldap 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/lib/yaleldap/version.rb +3 -0
- data/lib/yaleldap.rb +64 -0
- data/yaleldap.gemspec +24 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5943d287b4b24158bc7ffb8cb6785f3df39fff70
|
4
|
+
data.tar.gz: 128656225ea369cd377915e5b4a271d62d5ea4bc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a7805a8bcd7e614b1c5c3818b2e8dbd0d4eb8779e883efb1dacdd9e3f74d02e1332d3cfba815de42e8b24a124f05d9e6073a67db7f66f92fa02589cbeee8aeb1
|
7
|
+
data.tar.gz: 9587d3fc6858642104dbdf6740346b23247056d9897611776d833ebc194b9e7a6066eebcfdbed1e3c142ab1400bd63e2822325b20c0d22444e2d24a8918673aa
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 caseywatts
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Yaleldap
|
2
|
+
|
3
|
+
Automatically connects to the LDAP server if you are on campus/VPN. Can be queried by UPI, and it will return a simple ruby hash with the relevant information.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'yaleldap'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install yaleldap
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
`YaleLDAP.lookup_by_upi("123456")` will return a hash with commonly needed LDAP attributes.
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( http://github.com/YaleSTC/yaleldap/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/yaleldap.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require "yaleldap/version"
|
2
|
+
require "net-ldap"
|
3
|
+
|
4
|
+
module YaleLDAP
|
5
|
+
LDAP_HOST = 'directory.yale.edu'
|
6
|
+
LDAP_PORT = 389
|
7
|
+
LDAP_BASE = 'ou=People,o=yale.edu'
|
8
|
+
LDAP_ATTRS = %w(uid givenname sn mail collegename college class UPI)
|
9
|
+
|
10
|
+
# test with YaleLDAP.lookup_by_upi("12714662")
|
11
|
+
def self.lookup_by_upi(upi)
|
12
|
+
ldap = Net::LDAP.new host: LDAP_HOST, port: LDAP_PORT
|
13
|
+
upifilter = Net::LDAP::Filter.eq('UPI', upi)
|
14
|
+
ldap_response = ldap.search(base: LDAP_BASE,
|
15
|
+
filter: upifilter,
|
16
|
+
attributes: LDAP_ATTRS)
|
17
|
+
extract_attributes(ldap_response)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.lookup_by_netid(netid)
|
21
|
+
ldap = Net::LDAP.new host: LDAP_HOST, port: LDAP_PORT
|
22
|
+
upifilter = Net::LDAP::Filter.eq('uid', netid)
|
23
|
+
ldap_response = ldap.search(base: LDAP_BASE,
|
24
|
+
filter: upifilter,
|
25
|
+
attributes: LDAP_ATTRS)
|
26
|
+
extract_attributes(ldap_response)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.lookup_by_email(email)
|
30
|
+
ldap = Net::LDAP.new host: LDAP_HOST, port: LDAP_PORT
|
31
|
+
upifilter = Net::LDAP::Filter.eq('mail', email)
|
32
|
+
ldap_response = ldap.search(base: LDAP_BASE,
|
33
|
+
filter: upifilter,
|
34
|
+
attributes: LDAP_ATTRS)
|
35
|
+
extract_attributes(ldap_response)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def self.extract_attributes(ldap_response)
|
40
|
+
# everyone has these
|
41
|
+
first_name = ldap_response[0][:givenname][0]
|
42
|
+
last_name = ldap_response[0][:sn][0]
|
43
|
+
upi = ldap_response[0][:UPI][0]
|
44
|
+
|
45
|
+
# not everyone has these
|
46
|
+
netid = ldap_response[0][:uid][0] || ""
|
47
|
+
email = ldap_response[0][:mail][0] || ""
|
48
|
+
collegename = ldap_response[0][:collegename][0] || ""
|
49
|
+
college = ldap_response[0][:college][0] || ""
|
50
|
+
class_year = ldap_response[0][:class][0] || ""
|
51
|
+
|
52
|
+
return {
|
53
|
+
first_name: first_name,
|
54
|
+
last_name: last_name,
|
55
|
+
yale_upi: upi,
|
56
|
+
netid: netid,
|
57
|
+
email: email,
|
58
|
+
collegename: collegename,
|
59
|
+
college: college,
|
60
|
+
class_year: class_year
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
data/yaleldap.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'yaleldap/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "yaleldap"
|
8
|
+
spec.version = Yaleldap::VERSION
|
9
|
+
spec.authors = ["caseywatts"]
|
10
|
+
spec.email = ["casey.s.watts@gmail.com"]
|
11
|
+
spec.summary = %q{Easy connection to Yale's LDAP}
|
12
|
+
spec.description = %q{Automatically connects to the LDAP server if you are on campus/VPN. Can be queried by UPI, and it will return a simple ruby hash with the relevant information.}
|
13
|
+
spec.homepage = "http://github.com/YaleSTC/yaleldap"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_runtime_dependency "net-ldap"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yaleldap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- caseywatts
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: net-ldap
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Automatically connects to the LDAP server if you are on campus/VPN. Can
|
56
|
+
be queried by UPI, and it will return a simple ruby hash with the relevant information.
|
57
|
+
email:
|
58
|
+
- casey.s.watts@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/yaleldap.rb
|
69
|
+
- lib/yaleldap/version.rb
|
70
|
+
- yaleldap.gemspec
|
71
|
+
homepage: http://github.com/YaleSTC/yaleldap
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.0.3
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Easy connection to Yale's LDAP
|
95
|
+
test_files: []
|