ldapi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ree@ldapi
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source :rubygems
2
+
3
+ gem 'net-ldap'
4
+ gem 'json'
5
+ gem 'sinatra'
6
+
7
+ # Add dependencies required to use your gem here.
8
+ # Example:
9
+ # gem "activesupport", ">= 2.3.5"
10
+
11
+ # Add dependencies to develop your gem here.
12
+ # Include everything needed to run rake, tests, features, etc.
13
+ group :development do
14
+ gem "shoulda", ">= 0"
15
+ gem "bundler", "~> 1.0.0"
16
+ gem "jeweler", "~> 1.5.1"
17
+ gem "rcov", ">= 0"
18
+ end
@@ -0,0 +1,30 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.1)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ json (1.4.6)
10
+ net-ldap (0.1.1)
11
+ rack (1.2.1)
12
+ rake (0.8.7)
13
+ rcov (0.9.9)
14
+ shoulda (2.11.3)
15
+ sinatra (1.1.0)
16
+ rack (~> 1.1)
17
+ tilt (~> 1.1)
18
+ tilt (1.1)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bundler (~> 1.0.0)
25
+ jeweler (~> 1.5.1)
26
+ json
27
+ net-ldap
28
+ rcov
29
+ shoulda
30
+ sinatra
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Jay Zeschin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = ldapi
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to ldapi
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Jay Zeschin. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "ldapi"
16
+ gem.homepage = "http://github.com/jayzes/ldapi"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Simple read-only JSON API to an LDAP server}
19
+ gem.description = %Q{Simple read-only JSON API to an LDAP server. Written in Sinatra with net-ldap and json.}
20
+ gem.email = "jay.zeschin@factorylabs.com"
21
+ gem.authors = ["Jay Zeschin"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "ldapi #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
54
+
55
+ require File.join(File.dirname(__FILE__), 'lib', 'ldapi', 'tasks', 'ldapi')
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,78 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ldapi}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jay Zeschin"]
12
+ s.date = %q{2010-11-30}
13
+ s.description = %q{Simple read-only JSON API to an LDAP server. Written in Sinatra with net-ldap and json.}
14
+ s.email = %q{jay.zeschin@factorylabs.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rvmrc",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "ldapi.gemspec",
29
+ "lib/ldapi.rb",
30
+ "lib/ldapi/application.rb",
31
+ "lib/ldapi/backend.rb",
32
+ "lib/ldapi/configuration.rb",
33
+ "lib/ldapi/tasks/ldapi.rb",
34
+ "test/helper.rb",
35
+ "test/test_ldapi.rb"
36
+ ]
37
+ s.homepage = %q{http://github.com/jayzes/ldapi}
38
+ s.licenses = ["MIT"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.3.7}
41
+ s.summary = %q{Simple read-only JSON API to an LDAP server}
42
+ s.test_files = [
43
+ "test/helper.rb",
44
+ "test/test_ldapi.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
+ s.add_runtime_dependency(%q<net-ldap>, [">= 0"])
53
+ s.add_runtime_dependency(%q<json>, [">= 0"])
54
+ s.add_runtime_dependency(%q<sinatra>, [">= 0"])
55
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
56
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
57
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
58
+ s.add_development_dependency(%q<rcov>, [">= 0"])
59
+ else
60
+ s.add_dependency(%q<net-ldap>, [">= 0"])
61
+ s.add_dependency(%q<json>, [">= 0"])
62
+ s.add_dependency(%q<sinatra>, [">= 0"])
63
+ s.add_dependency(%q<shoulda>, [">= 0"])
64
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
65
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
66
+ s.add_dependency(%q<rcov>, [">= 0"])
67
+ end
68
+ else
69
+ s.add_dependency(%q<net-ldap>, [">= 0"])
70
+ s.add_dependency(%q<json>, [">= 0"])
71
+ s.add_dependency(%q<sinatra>, [">= 0"])
72
+ s.add_dependency(%q<shoulda>, [">= 0"])
73
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
74
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
75
+ s.add_dependency(%q<rcov>, [">= 0"])
76
+ end
77
+ end
78
+
@@ -0,0 +1,10 @@
1
+ require 'sinatra'
2
+ require 'json'
3
+ require 'net/ldap'
4
+
5
+ module Ldapi
6
+ end
7
+
8
+ require File.expand_path(File.join(File.dirname(__FILE__), 'ldapi', 'configuration'))
9
+ require File.expand_path(File.join(File.dirname(__FILE__), 'ldapi', 'backend'))
10
+ require File.expand_path(File.join(File.dirname(__FILE__), 'ldapi', 'application'))
@@ -0,0 +1,8 @@
1
+ class Ldapi::Application < Sinatra::Base
2
+
3
+ get "/:uid.json" do
4
+ content_type :json
5
+ Ldapi::Backend.new.search(params[:uid]).to_json
6
+ end
7
+
8
+ end
@@ -0,0 +1,37 @@
1
+ class Ldapi::Backend
2
+
3
+ ATTRS = [ "objectclass",
4
+ "givenname",
5
+ "sn",
6
+ "objectclass",
7
+ 'apple-imhandle',
8
+ 'cn',
9
+ 'gidnumber',
10
+ # 'jpegphoto',
11
+ 'mail',
12
+ 'uid',
13
+ 'uidnumber',
14
+ 'homedirectory' ]
15
+
16
+
17
+ def initialize
18
+ @ldap = Net::LDAP.new( :host => Ldapi.configuration.ldap_server,
19
+ :port => 389 )
20
+ end
21
+
22
+ def search(uid)
23
+ result = {}
24
+ filter = Net::LDAP::Filter.eq( "uid", uid )
25
+ @ldap.search( :base => Ldapi.configuration.search_base, :filter => filter, :attributes => ATTRS ) do |entry|
26
+ entry.each do |attribute, values|
27
+ if values.size == 1
28
+ result[attribute] = values.first
29
+ else
30
+ result[attribute] = values
31
+ end
32
+ end
33
+ end
34
+ result
35
+ end
36
+
37
+ end
@@ -0,0 +1,16 @@
1
+ module Ldapi
2
+ class << self
3
+ attr_accessor :configuration
4
+ end
5
+
6
+ def self.configure
7
+ self.configuration ||= Configuration.new
8
+ yield(configuration)
9
+ end
10
+
11
+ class Configuration
12
+ attr_accessor :ldap_server,
13
+ :search_base
14
+
15
+ end
16
+ end
@@ -0,0 +1,35 @@
1
+ task :example do
2
+
3
+ require 'net/ldap'
4
+
5
+ server = 'ldap.factorylabs.com'
6
+ ldap = Net::LDAP.new( :host => server,
7
+ :port => 389 )
8
+
9
+ filter = Net::LDAP::Filter.eq( "uid", "jayzeschin" )
10
+ treebase = "cn=users,dc=ldap,dc=factorylabs,dc=com"
11
+ attrs = [ "objectclass",
12
+ "givenname",
13
+ "sn",
14
+ "objectclass",
15
+ 'apple-imhandle',
16
+ 'cn',
17
+ 'gidnumber',
18
+ # 'jpegphoto',
19
+ 'mail',
20
+ 'uid',
21
+ 'uidnumber',
22
+ 'homedirectory' ]
23
+
24
+ ldap.search( :base => treebase, :filter => filter, :attributes => attrs ) do |entry|
25
+ puts "DN: #{entry.dn}"
26
+ entry.each do |attribute, values|
27
+ puts " #{attribute}:"
28
+ values.each do |value|
29
+ puts " --->#{value}"
30
+ end
31
+ end
32
+ end
33
+
34
+ p ldap.get_operation_result
35
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'ldapi'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestLdapi < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ldapi
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Jay Zeschin
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-30 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ type: :runtime
24
+ name: net-ldap
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ prerelease: false
37
+ type: :runtime
38
+ name: json
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ requirement: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ prerelease: false
51
+ type: :runtime
52
+ name: sinatra
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirement: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ prerelease: false
65
+ type: :development
66
+ name: shoulda
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ requirement: *id004
77
+ - !ruby/object:Gem::Dependency
78
+ prerelease: false
79
+ type: :development
80
+ name: bundler
81
+ version_requirements: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ hash: 23
87
+ segments:
88
+ - 1
89
+ - 0
90
+ - 0
91
+ version: 1.0.0
92
+ requirement: *id005
93
+ - !ruby/object:Gem::Dependency
94
+ prerelease: false
95
+ type: :development
96
+ name: jeweler
97
+ version_requirements: &id006 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ hash: 1
103
+ segments:
104
+ - 1
105
+ - 5
106
+ - 1
107
+ version: 1.5.1
108
+ requirement: *id006
109
+ - !ruby/object:Gem::Dependency
110
+ prerelease: false
111
+ type: :development
112
+ name: rcov
113
+ version_requirements: &id007 !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ requirement: *id007
123
+ description: Simple read-only JSON API to an LDAP server. Written in Sinatra with net-ldap and json.
124
+ email: jay.zeschin@factorylabs.com
125
+ executables: []
126
+
127
+ extensions: []
128
+
129
+ extra_rdoc_files:
130
+ - LICENSE.txt
131
+ - README.rdoc
132
+ files:
133
+ - .document
134
+ - .rvmrc
135
+ - Gemfile
136
+ - Gemfile.lock
137
+ - LICENSE.txt
138
+ - README.rdoc
139
+ - Rakefile
140
+ - VERSION
141
+ - ldapi.gemspec
142
+ - lib/ldapi.rb
143
+ - lib/ldapi/application.rb
144
+ - lib/ldapi/backend.rb
145
+ - lib/ldapi/configuration.rb
146
+ - lib/ldapi/tasks/ldapi.rb
147
+ - test/helper.rb
148
+ - test/test_ldapi.rb
149
+ has_rdoc: true
150
+ homepage: http://github.com/jayzes/ldapi
151
+ licenses:
152
+ - MIT
153
+ post_install_message:
154
+ rdoc_options: []
155
+
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ hash: 3
164
+ segments:
165
+ - 0
166
+ version: "0"
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ none: false
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ hash: 3
173
+ segments:
174
+ - 0
175
+ version: "0"
176
+ requirements: []
177
+
178
+ rubyforge_project:
179
+ rubygems_version: 1.3.7
180
+ signing_key:
181
+ specification_version: 3
182
+ summary: Simple read-only JSON API to an LDAP server
183
+ test_files:
184
+ - test/helper.rb
185
+ - test/test_ldapi.rb