hiera-ldapprovider 1.0.1 → 1.0.2

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: e5d271b46f30bae9ed197672dbc51020b1a49621
4
- data.tar.gz: ad294bda6f73cd555202dd5197e461353aa354a4
3
+ metadata.gz: f9dcce63a21cecc44d7d78fccb8e63834fe6228e
4
+ data.tar.gz: 7ca58c58013a8f9bd01465460a74fd5cbfcee36d
5
5
  SHA512:
6
- metadata.gz: 0925bfc814d814b0d565c52e42838d5f92adbf5674bf4932b5cbf87bb9b3159467e050cf7b71e6e4d76b3b20c56f19620b89d67e0fc1f2ef7e6c19222c0fbd50
7
- data.tar.gz: b923cfa345c33756b4e72f8d89784cb0c555e9fce767ba7d4af34421f3c4a2bd470b5b82a4dcd07eefeee80541ad25392e1c72008b05cf3b7f8570653e3c6dce
6
+ metadata.gz: c667b30b72e476d9f47c97fc77660ad0c81fa1aa06114205c420ed1dbddcddf649377aa77a32b7f8b86e26d6ba377fe0afad1a2576963463e3b4c5feae2b4434
7
+ data.tar.gz: b1d945b0817353de2c1e6182a42bfaa96503897a054cbf56dd752d8d2456574854375b9f3e34154cdf06acfae2610f40ed1fa72cf1baf7ccfd3cd62c552f808a
@@ -0,0 +1,13 @@
1
+ require 'json'
2
+
3
+ class String
4
+
5
+ # == Validates if valid JSON was found
6
+ def valid_json?
7
+ require 'json'
8
+ JSON.parse(self)
9
+ true
10
+ rescue JSON::ParserError
11
+ false
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ require 'yaml'
2
+
3
+ class String
4
+
5
+ # == Public: Validates if valid yaml was found
6
+ def valid_yaml?
7
+ YAML.load(self)
8
+ true
9
+ rescue Psych::SyntaxError
10
+ false
11
+ rescue Exception
12
+ false
13
+ end
14
+ end
@@ -1,7 +1,7 @@
1
1
  class Hiera
2
2
  module Backend
3
3
  module LDAP
4
- VERSION="1.0.1"
4
+ VERSION="1.0.2"
5
5
  end
6
6
  end
7
7
  end
@@ -1,50 +1,16 @@
1
1
  require 'rubygems'
2
+ require 'core_ext/string/json'
3
+ require 'core_ext/string/yaml'
2
4
  require 'net/ldap'
5
+ require 'net/ldap/connection'
3
6
  require 'hiera/backend/ldap'
4
7
 
5
- # Monkey patch Net::LDAP::Connection to ensure SSL certs aren't verified
6
- class Net::LDAP::Connection
7
- def self.wrap_with_ssl(io)
8
- raise Net::LDAP::LdapError, "OpenSSL is unavailable" unless Net::LDAP::HasOpenSSL
9
- ctx = OpenSSL::SSL::SSLContext.new
10
- ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
11
- conn = OpenSSL::SSL::SSLSocket.new(io, ctx)
12
- conn.connect
13
- conn.sync_close = true
14
-
15
- conn.extend(GetbyteForSSLSocket) unless conn.respond_to?(:getbyte)
16
-
17
- conn
18
- end
19
- end
20
-
21
- class String
22
- def valid_json?
23
- require 'json'
24
- JSON.parse(self)
25
- true
26
- rescue JSON::ParserError
27
- false
28
- end
29
-
30
- def valid_yaml?
31
- YAML.load(self)
32
- true
33
- rescue Psych::SyntaxError
34
- false
35
- rescue Exception
36
- false
37
- end
38
-
39
- end
40
8
  class Hiera
41
9
  module Backend
42
10
  class Ldap_backend
43
11
  def initialize
44
12
  @attr = get_config_value(:attribute, "cn")
45
-
46
13
  Hiera.debug("Hiera LDAP backend starting")
47
-
48
14
  @connection = Net::LDAP.new(
49
15
  :host => conf[:host],
50
16
  :port => get_config_value(:port, "389"),
@@ -66,22 +32,16 @@ class Hiera
66
32
 
67
33
  def lookup(key, scope, order_override, resolution_type)
68
34
  answer = nil
69
-
70
35
  Hiera.debug("Looking up #{key} in LDAP backend")
71
-
72
36
  Backend.datasources(scope, order_override) do |source|
73
37
  Hiera.debug("Looking for data source #{source}")
74
38
  base = @conf[:base]
75
-
76
39
  Hiera.debug("Searching on base: #{base}")
77
-
78
-
79
40
  filter = Net::LDAP::Filter.eq(@attr, source)
80
41
  Hiera.debug("Searching with filter: %s" % filter.to_s)
81
42
  searchresult = @connection.search(:filter => filter, :return_result => true)
82
43
  result = []
83
44
  alt_key = key.downcase.to_sym
84
-
85
45
  begin
86
46
  searchresult.each do |entry|
87
47
  if entry.attribute_names.include?(alt_key)
@@ -109,6 +69,11 @@ class Hiera
109
69
  elsif res.valid_yaml?
110
70
  res = YAML.load(res)
111
71
  end
72
+ if !res.kind_of? Hash
73
+ res_old = res.dup
74
+ res = {}
75
+ res[key] = result
76
+ end
112
77
  answer = Backend.merge_answer(res,answer)
113
78
  end
114
79
  else
@@ -120,7 +85,6 @@ class Hiera
120
85
  break
121
86
  end
122
87
  Hiera.debug("Answer: #{answer}")
123
-
124
88
  end
125
89
  return answer
126
90
  end
@@ -0,0 +1,18 @@
1
+ module Net
2
+ class LDAP
3
+ class Connection
4
+
5
+ # == Public: Monkey patch to ensure SSL certificates aren't verified
6
+ def self.wrap_with_ssl(io)
7
+ raise Net::LDAP::LdapError, "OpenSSL is unavailable" unless Net::LDAP::HasOpenSSL
8
+ ctx = OpenSSL::SSL::SSLContext.new
9
+ ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
10
+ conn = OpenSSL::SSL::SSLSocket.new(io, ctx)
11
+ conn.connect
12
+ conn.sync_close = true
13
+ conn.extend(GetbyteForSSLSocket) unless conn.respond_to?(:getbyte)
14
+ conn
15
+ end
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiera-ldapprovider
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Kasper
@@ -49,8 +49,11 @@ files:
49
49
  - README.md
50
50
  - Rakefile
51
51
  - hiera-ldap.gemspec
52
+ - lib/core_ext/string/json.rb
53
+ - lib/core_ext/string/yaml.rb
52
54
  - lib/hiera/backend/ldap.rb
53
55
  - lib/hiera/backend/ldap_backend.rb
56
+ - lib/net/ldap/connection.rb
54
57
  homepage: http://github.com/Corscience/hiera-ldap
55
58
  licenses:
56
59
  - MIT