idr_staff 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3185895cd0493d986232855d734692a59ebb0999
4
+ data.tar.gz: e9e3af19e0dca5ab6770eefbe0f3f414fad57a81
5
+ SHA512:
6
+ metadata.gz: c8de2dba34b2ba604443b6267fc785c4d60627319c5e69b180a70e6f1a5bb8eb72a7eeb40bbfd4f3a401c99621bda42f74d83c53a099d872885135fa760d62db
7
+ data.tar.gz: 3a005e5dd366e78af8959157b8744b3f58ff6ee8bea77637c1e7ca8b33b0e0e8cb4685d6f8de78821ef64240864a4384c36576764927fc31d99a7987c612b279
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in idr_staff.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ernst Van Graan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # IdrStaff
2
+
3
+ This gem provides the ability to talk to an LDAP source for Hetzner staff data, translate that into a staff entity, and present the data as a model to controllers in an identity registry.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'idr_staff'
10
+
11
+ And then execute:
12
+
13
+ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ gem install idr_staff
18
+
19
+ ## Usage
20
+ spec.add_development_dependency 'idr_staff'
21
+ bundle exec irb
22
+
23
+ ## Contributing
24
+
25
+ Bug reports and feature requests are welcome by email to ernst dot van dot graan at hetzner dot co dot za. This gem is sponsored by Hetzner (Pty) Ltd (http://hetzner.co.za)
26
+
27
+
28
+ ## License
29
+
30
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
31
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "idr_staff"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'idr_staff/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "idr_staff"
8
+ spec.version = IdrStaff::VERSION
9
+ spec.authors = ["Ernst Van Graan"]
10
+ spec.email = ["ernst.van.graan@hetzner.co.za"]
11
+
12
+ spec.summary = %q{Model for staff IDR}
13
+ spec.description = %q{Model for staff IDR}
14
+ #spec.homepage = "TODO: Put your gem's website or public repo URL here."
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ #if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ #else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ #end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.11"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+
34
+ spec.add_development_dependency "byebug"
35
+ spec.add_dependency "soar_idm"
36
+ spec.add_dependency "soar_ldap"
37
+ spec.add_dependency "jsender"
38
+ end
@@ -0,0 +1,7 @@
1
+ require 'idr_staff/configuration_validator'
2
+ require 'idr_staff/hetzner_staff_ldap'
3
+ require 'idr_staff/hetzner_staff_ldap_translator'
4
+ require 'idr_staff/staff_idr'
5
+
6
+ module IdrStaff
7
+ end
@@ -0,0 +1,84 @@
1
+ require 'jsender'
2
+
3
+ module IdrStaff
4
+ class ConfigurationValidator
5
+ include Jsender
6
+
7
+ def validate(configuration)
8
+ return fail 'invalid configuration provided' if not valid_configuration?(configuration)
9
+ return fail 'no rule set provided' if not configuration_present_for?(configuration, 'rule_set')
10
+ return fail 'no provider provided' if not configuration_present_for?(configuration, 'provider')
11
+
12
+ begin
13
+ return fail 'invalid rule set provided' if not valid_rule_set?(configuration)
14
+ rescue => ex
15
+ return fail 'failure bootstrapping rule set'
16
+ end
17
+
18
+ begin
19
+ return fail 'invalid provider provided' if not valid_provider?(configuration)
20
+ rescue => ex
21
+ return fail 'failure bootstrapping provider'
22
+ end
23
+
24
+ success
25
+ end
26
+
27
+ private
28
+
29
+ def valid_configuration?(configuration)
30
+ return false if configuration.nil?
31
+ return false if not configuration.is_a?(Hash)
32
+ return false if configuration['valid'] != 'valid'
33
+ true
34
+ end
35
+
36
+ def valid_rule_set?(configuration)
37
+ adaptor = extract_adaptor('rule_set', configuration)
38
+ return false if adaptor == ''
39
+ return false if not class_exists?(adaptor)
40
+ klass = Module.const_get(adaptor)
41
+ return false if not (klass.public_instance_methods.include?(:translate))
42
+ true
43
+ end
44
+
45
+ def valid_provider?(configuration)
46
+ adaptor = extract_adaptor('provider', configuration)
47
+ return false if adaptor == ''
48
+ return false if not class_exists?(adaptor)
49
+ raise RuntimeError if adaptor == 'RuntimeError'
50
+ klass = Module.const_get(adaptor)
51
+ # Someone please tell me why klass.is_a?(SoarIdm::DirectoryProvider) is not working here?
52
+ return false if
53
+ not (klass.superclass.name == "SoarIdm::DirectoryProvider") and
54
+ not (klass.superclass.superclass.name == "SoarIdm::DirectoryProvider")
55
+ connector = extract_category('provider', configuration)
56
+ return false if connector['path'].nil?
57
+ return false if connector['server'].nil?
58
+ return false if connector['port'].nil?
59
+ return false if connector['username'].nil?
60
+ return false if connector['password'].nil?
61
+ true
62
+ end
63
+
64
+ def configuration_present_for?(configuration, category)
65
+ not configuration[category].nil?
66
+ end
67
+
68
+ def extract_adaptor(category, configuration)
69
+ configuration[category]['adaptor'].to_s.strip
70
+ end
71
+
72
+ def extract_category(category, configuration)
73
+ configuration[category]
74
+ end
75
+
76
+
77
+ def class_exists?(class_name)
78
+ klass = Module.const_get(class_name)
79
+ return klass.is_a?(Class)
80
+ rescue NameError
81
+ return false
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,15 @@
1
+ require 'soar_ldap'
2
+
3
+ module IdrStaff
4
+ class HetznerStaffLdap < SoarLdap::LdapProvider
5
+ def find_entity(connection, identifier)
6
+ connection.search(@path, ::LDAP::LDAP_SCOPE_SUBTREE, 'objectClass=*', ['objectClass', 'cn', 'dn', 'entryuuid', 'description']) do |entry|
7
+ uuid = entry['entryUUID'].first
8
+ dn = entry.dn
9
+ return entry if uuid == identifier
10
+ return entry if dn and dn == "genieUser=#{identifier.downcase},ou=people,dc=hetzner,dc=co,dc=za"
11
+ end
12
+ nil
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,50 @@
1
+ require 'soar_idm/soar_idm'
2
+
3
+ module IdrStaff
4
+ class HetznerStaffLdapTranslator
5
+ def translate(entry)
6
+ uuid, cn, object_classes, email = extract_fields(entry)
7
+ build_entity(uuid, cn, object_classes, email)
8
+ end
9
+
10
+ private
11
+
12
+ def build_entity(uuid, cn, object_classes, email)
13
+ entity = {}
14
+ entity['roles'] = extract_entity_roles(object_classes, cn, email)
15
+ entity['uuid'] = uuid
16
+ entity
17
+ end
18
+
19
+ def extract_entity_roles(object_classes, cn, email)
20
+ roles = {}
21
+ object_classes.each do |role|
22
+ roles[role] = {}
23
+ roles[role] = { 'name_and_surname' => cn,
24
+ 'email_address' => email } if role == 'hetznerPerson'
25
+ end
26
+ roles
27
+ end
28
+
29
+ def extract_fields(entry)
30
+ uuid = extract_uuid(entry)
31
+ dn = entry.dn
32
+ cn = entry['cn'].first
33
+ object_classes = entry['objectClass']
34
+ email = extract_email(dn)
35
+ return uuid, cn, object_classes, email
36
+ end
37
+
38
+ def extract_uuid(entry)
39
+ entry['entryUUID'].first if entry['entryUUID']
40
+ end
41
+
42
+ def extract_email(dn)
43
+ email = nil
44
+ dn.split(",").each do |value|
45
+ email = value.split('=')[1] if value.include?('genie')
46
+ end
47
+ email
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,71 @@
1
+ require 'jsender'
2
+ require 'soar_idm/soar_idm'
3
+ require 'idr_staff/configuration_validator'
4
+ require 'idr_staff/hetzner_staff_ldap'
5
+
6
+ module IdrStaff
7
+ class StaffIdr < ::SoarIdm::IdmApi
8
+ attr_reader :configuration
9
+ attr_reader :status
10
+ attr_reader :translator
11
+ attr_reader :directory
12
+
13
+ def bootstrap(configuration)
14
+ validator = IdrStaff::ConfigurationValidator.new
15
+ @status = validator.validate(configuration)
16
+ @status
17
+ end
18
+
19
+ def initialize(configuration)
20
+ @configuration = configuration
21
+ bootstrap(configuration)
22
+ initialize_providers(configuration) if bootstrapped?
23
+ end
24
+
25
+ def initialize_providers(configuration)
26
+ @translator = Object::const_get(@configuration['rule_set']['adaptor']).new
27
+ provider = @configuration['provider']
28
+ @directory = Object::const_get(provider['adaptor']).new(provider)
29
+ credentials = { 'username' => provider['username'], 'password' => provider['password'] }
30
+ @directory.authenticate(credentials)
31
+ end
32
+
33
+ def bootstrapped?
34
+ @status['status'] == 'success'
35
+ end
36
+
37
+ def calculate_roles(identity)
38
+ entry = @directory.get_entity(identity)
39
+ return nil if not entry
40
+ entity = translator.translate(entry)
41
+ roles = []
42
+ entity['roles'].each do |role, attributes|
43
+ roles << role
44
+ end
45
+ roles
46
+ end
47
+
48
+ def calculate_all_attributes(identity)
49
+ attributes = {}
50
+ roles = calculate_roles(identity)
51
+ roles.each do |role|
52
+ attributes.merge!(calculate_attributes(identity, role))
53
+ end
54
+ attributes
55
+ end
56
+
57
+ def calculate_attributes(identity, role)
58
+ entry = @directory.get_entity(identity)
59
+ return nil if not entry
60
+ entity = translator.translate(entry)
61
+ { role => entity['roles'][role] }
62
+ end
63
+
64
+ def calculate_identities(entity_identifier)
65
+ entry = @directory.get_entity(entity_identifier)
66
+ return nil if not entry
67
+ entity = translator.translate(entry)
68
+ [entity['uuid']]
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,3 @@
1
+ module IdrStaff
2
+ VERSION = "0.0.6"
3
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: idr_staff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Ernst Van Graan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-15 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
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: soar_idm
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: soar_ldap
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: jsender
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Model for staff IDR
112
+ email:
113
+ - ernst.van.graan@hetzner.co.za
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - bin/console
125
+ - bin/setup
126
+ - idr_staff.gemspec
127
+ - lib/idr_staff.rb
128
+ - lib/idr_staff/configuration_validator.rb
129
+ - lib/idr_staff/hetzner_staff_ldap.rb
130
+ - lib/idr_staff/hetzner_staff_ldap_translator.rb
131
+ - lib/idr_staff/staff_idr.rb
132
+ - lib/idr_staff/version.rb
133
+ homepage:
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.4.8
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Model for staff IDR
157
+ test_files: []
158
+ has_rdoc: