soar-authentication-identity 0.0.1 → 0.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: 921b00f418350cbcf3502a43b74e2092060ef9e9
4
- data.tar.gz: bc6ed7553575ff5d8a46eda43d0bfd9f65794bc7
3
+ metadata.gz: 5f8914d86bf3c5ca1985aef4f44b3a9350d6d3d5
4
+ data.tar.gz: db528744d5b6cffd9cd4184138eb4c80ef20f73f
5
5
  SHA512:
6
- metadata.gz: 6d1af45bee7f55541161938a3f85bc07ba9464b18b7510af40c7bc5f63ab287af0fc1423eaa3f295ffcd1ae78ff48ec3c9facab9df1672ea76be9cfd196622b2
7
- data.tar.gz: a74b19be7d9060c72aedad3ca20a1ef3922120d5ac34713a900071c4ec5559a5df2e7dee31178f696ead0df3961d33cb5ac75cc3808af6c8e44f9a64db2e7783
6
+ metadata.gz: 5475f3261b034b1eeac56233f669c4a8162db6e162b541b8fd4297cc71486cd122992f11fc0bf79c4d7b71d88d90f54623d79595ab4c7ec8142722ae453f392d
7
+ data.tar.gz: 942a55d59f9b2fce174699c6cd44d7d71278a9a5e01973843c6cde062be9d1b3c6aaf042dd34b4b427efc6fe0dc9b9357a8875ffc38ee87bf2a7e2ff2032a62d
data/.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "soar-authentication-identity"
3
- spec.version = "0.0.1"
3
+ spec.version = "0.0.2"
4
4
  spec.authors = ["Charles Mulder"]
5
5
  spec.email = ["charles.mulder@hetzner.co.za"]
6
6
 
data/.gitignore CHANGED
@@ -20,3 +20,5 @@
20
20
  .ruby-version
21
21
  .ruby-gemset
22
22
  *.gem
23
+ .byebug_history
24
+ Gemfile.lock
data/Dockerfile CHANGED
@@ -3,5 +3,5 @@ WORKDIR /usr/local/src
3
3
  ADD Gemfile .gemspec /usr/local/src/
4
4
  RUN bundle install --without development --with test
5
5
  ADD . /usr/local/src/
6
- CMD bundle exec cucumber
6
+ CMD bundle exec cucumber && bundle exec rspec
7
7
 
data/Gemfile CHANGED
@@ -5,5 +5,5 @@ gemspec
5
5
 
6
6
  group :test do
7
7
  gem 'cucumber', '~> 2.4'
8
- gem 'rspec-expectations', '~> 3.5'
8
+ gem 'rspec', '~> 3.5'
9
9
  end
data/README.md CHANGED
@@ -6,8 +6,24 @@ Used by authentication service to translate an identity identifier into an UUID
6
6
  ## Quickstart
7
7
 
8
8
  ### Staff identity provider
9
+
10
+ Example using the factory.
9
11
  ```ruby
10
- > identity = Soar::Authentication::Identity::Factory.create(authenticated_identifier: 'staff@hetzner.co.za')
12
+ > identity = Soar::Authentication::Identity::Factory.create({
13
+ authenticated_identifier: 'the authenticated identifier goes here',
14
+ directory_configurations: {
15
+ "staff" => {
16
+ "provider" => 'Soar::Registry::Directory::Provider::Stub',
17
+ "config" => {
18
+ "table" => "identity",
19
+ "primary_key" =>"uuid",
20
+ "index" => ["uuid", "email"]
21
+ }
22
+ },
23
+ "customer" => {},
24
+ "domain" => {}
25
+ }
26
+ })
11
27
  > puts identity.uuid
12
28
  "85777bfa-b743-4ba9-8308-e8a1e4d44fbe"
13
29
  ```
@@ -16,6 +32,11 @@ Used by authentication service to translate an identity identifier into an UUID
16
32
 
17
33
  ### Local
18
34
 
35
+ #### Identity factory
36
+ ```bash
37
+ $ bundle exec rspec
38
+ ```
39
+
19
40
  #### Stub identity provider
20
41
  ```bash
21
42
  $ TEST_ORCHESTRATION_PROVIDER=Stub cucumber
@@ -1,10 +1,8 @@
1
-
2
1
  module Soar
3
2
  module Authentication
4
3
  module Identity
5
4
  module Error
6
- class UnknownIdentityError < StandardError
7
- end
5
+ class UnknownIdentityError < StandardError; end;
8
6
  end
9
7
  end
10
8
  end
@@ -1,4 +1,5 @@
1
1
  require 'soar/authentication/identity'
2
+ require 'soar/registry/directory'
2
3
 
3
4
  module Soar
4
5
  module Authentication
@@ -6,23 +7,41 @@ module Soar
6
7
  module Factory
7
8
 
8
9
  ##
10
+ # @param directory_configurations [Hash]
9
11
  # @param authenticated_identifier [String]
12
+ # @return [Soar::Authentication::Identity]
10
13
  # @raise [ArgumentError]
11
- # @return [Soar::Authentication::Identity::Model]
12
14
  ##
13
- def self.create(directory: nil, authenticated_identifier: nil)
14
- raise ArgumentError if authenticated_identifier.nil? or directory.nil?
15
- provider = get_provider(directory, authenticated_identifier)
15
+ def self.create(directory_configurations: nil, authenticated_identifier: nil)
16
+ raise ArgumentError, 'Missing required directory configuration' if directory_configurations.nil?
17
+ raise ArgumentError, 'Missing required authenticated identifier' if authenticated_identifier.nil?
18
+ provider = get_provider(directory_configurations, authenticated_identifier)
16
19
  Soar::Authentication::Identity.new(provider)
17
20
  end
18
21
 
19
- private
22
+ private
23
+
24
+ ##
25
+ # @param identity [String]
26
+ # @return [Soar::Registry::Directory]
27
+ # @raise [KeyError] if config is missing provider and config keys
28
+ ##
29
+ def self.get_directory(config)
30
+ provider_class = Object.const_get(config.fetch('provider'))
31
+ provider = provider_class.new(config.fetch('config').symbolize_keys)
32
+ Soar::Registry::Directory.new(provider)
33
+ end
20
34
 
21
- def self.get_provider(directory, authenticated_identifier)
35
+ ##
36
+ # @param authenticated_identifier [String]
37
+ # @raise [Soar::Authentication::Identity::Error::UnknownIdentityError, KeyError]
38
+ # @return [Soar::Authentication::Identity::Provider]
39
+ ##
40
+ def self.get_provider(directory_configurations, authenticated_identifier)
22
41
  case authenticated_identifier
23
42
  when /@hetzner.co.za\z/
24
43
  Soar::Authentication::Identity::Provider::Staff.new({
25
- directory: directory,
44
+ directory: get_directory(directory_configurations.fetch('staff')),
26
45
  authenticated_identifier: authenticated_identifier
27
46
  })
28
47
  when /D\d*$/
@@ -6,6 +6,8 @@ module Soar
6
6
  module Authentication
7
7
  module Identity
8
8
  class Model
9
+
10
+ attr_reader :provider
9
11
 
10
12
  def initialize(provider)
11
13
  @provider = provider
@@ -15,6 +17,10 @@ module Soar
15
17
  @provider.uuid
16
18
  end
17
19
 
20
+ def directory
21
+ @provider.directory
22
+ end
23
+
18
24
  end
19
25
  end
20
26
  end
@@ -6,16 +6,19 @@ module Soar
6
6
  module Provider
7
7
  class Staff
8
8
 
9
+ attr_reader :directory
10
+
9
11
  def initialize(directory: nil, authenticated_identifier: nil)
10
12
  @directory = directory
13
+ @authenticated_identifier = authenticated_identifier
11
14
  identity_provider = Soar::Registry::Identity::Provider::Staff::Email.new(directory: @directory)
12
- identity_registry = Soar::Registry::Identity.new(identity_provider)
13
- @attributes = identity_registry.get_attributes(authenticated_identifier)
15
+ @identity_registry = Soar::Registry::Identity.new(identity_provider)
14
16
  end
15
17
 
16
18
  def uuid
19
+ attributes = @identity_registry.get_attributes(@authenticated_identifier)
17
20
  primary_key = @directory.index[0]
18
- @attributes[primary_key]
21
+ attributes[primary_key]
19
22
  end
20
23
 
21
24
  end
@@ -5,6 +5,8 @@ module Soar
5
5
  module Identity
6
6
  module Provider
7
7
  class Stub
8
+
9
+ attr_reader :directory
8
10
 
9
11
  def initialize(directory: nil, authenticated_identifier: nil)
10
12
  @directory = directory
@@ -1,5 +1,4 @@
1
1
  require 'soar/authentication/identity/factory'
2
- require 'soar/registry/directory'
3
2
  require 'securerandom'
4
3
 
5
4
  module Soar
@@ -9,38 +8,40 @@ module Soar
9
8
  module OrchestrationProvider
10
9
  class Staff
11
10
 
12
- def initialize()
13
- directory_provider = Soar::Registry::Directory::Provider::Stub.new({
14
- table: "mytable",
15
- primary_key: "uuid",
16
- index: ["uuid", "email"]
11
+ def initialize
12
+ @entry = {
13
+ "uuid" => SecureRandom.uuid,
14
+ "email" => 'test@hetzner.co.za'
15
+ }
16
+ @identity = Soar::Authentication::Identity::Factory.create({
17
+ authenticated_identifier: @entry["email"],
18
+ directory_configurations: {
19
+ "staff" => {
20
+ "provider" => 'Soar::Registry::Directory::Provider::Stub',
21
+ "config" => {
22
+ "table" => "identity",
23
+ "primary_key" =>"uuid",
24
+ "index" => ["uuid", "email"]
25
+ }
26
+ },
27
+ "customer" => {},
28
+ "domain" => {}
29
+ }
17
30
  })
18
- @directory = Soar::Registry::Directory.new(directory_provider)
19
-
20
31
  end
21
32
 
22
33
  ##
23
34
  # @return [Nil]
24
35
  ##
25
36
  def given_existing_identity
26
-
27
- @entry = {
28
- "uuid" => SecureRandom.uuid,
29
- "email" => 'test@hetzner.co.za'
30
- }
31
-
32
- @directory.put(@entry)
33
-
37
+ @identity.directory.put(@entry)
34
38
  end
35
39
 
36
40
  ##
37
41
  # @return [Nil]
38
42
  ##
39
43
  def given_authenticated_identifier
40
- @identity = Soar::Authentication::Identity::Factory.create({
41
- directory: @directory,
42
- authenticated_identifier: @entry["email"]
43
- })
44
+ @entry["email"]
44
45
  end
45
46
 
46
47
  ##
@@ -1,4 +1,5 @@
1
1
  require 'soar/authentication/identity/model'
2
+ require 'soar/authentication/identity/factory'
2
3
  require 'soar/authentication/identity/error'
3
4
 
4
5
  module Soar
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soar-authentication-identity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Mulder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-02 00:00:00.000000000 Z
11
+ date: 2016-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: soar-registry-identity
@@ -52,10 +52,8 @@ files:
52
52
  - ".ruby-version"
53
53
  - Dockerfile
54
54
  - Gemfile
55
- - Gemfile.lock
56
55
  - README.md
57
56
  - Rakefile
58
- - config/config.yml
59
57
  - docker-compose.staff.yml
60
58
  - docker-compose.stub.yml
61
59
  - lib/soar/authentication/identity.rb
data/Gemfile.lock DELETED
@@ -1,74 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- soar-authentication-identity (0.0.0)
5
- soar-registry-directory (~> 1.0)
6
- soar-registry-identity (~> 1.0)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activemodel (3.2.22.5)
12
- activesupport (= 3.2.22.5)
13
- builder (~> 3.0.0)
14
- activesupport (3.2.22.5)
15
- i18n (~> 0.6, >= 0.6.4)
16
- multi_json (~> 1.0)
17
- aws-sdk (2.6.32)
18
- aws-sdk-resources (= 2.6.32)
19
- aws-sdk-core (2.6.32)
20
- aws-sigv4 (~> 1.0)
21
- jmespath (~> 1.0)
22
- aws-sdk-resources (2.6.32)
23
- aws-sdk-core (= 2.6.32)
24
- aws-sigv4 (1.0.0)
25
- builder (3.0.4)
26
- cucumber (2.4.0)
27
- builder (>= 2.1.2)
28
- cucumber-core (~> 1.5.0)
29
- cucumber-wire (~> 0.0.1)
30
- diff-lcs (>= 1.1.3)
31
- gherkin (~> 4.0)
32
- multi_json (>= 1.7.5, < 2.0)
33
- multi_test (>= 0.1.2)
34
- cucumber-core (1.5.0)
35
- gherkin (~> 4.0)
36
- cucumber-wire (0.0.1)
37
- diff-lcs (1.2.5)
38
- gherkin (4.0.0)
39
- hashie (3.4.6)
40
- hashy_db (2.1.0)
41
- i18n (0.7.0)
42
- jmespath (1.3.1)
43
- jsender (0.2.2)
44
- mince (2.3.0)
45
- activemodel (~> 3.0)
46
- activesupport (~> 3.0)
47
- multi_json (1.12.1)
48
- multi_test (0.1.2)
49
- rspec-expectations (3.5.0)
50
- diff-lcs (>= 1.2.0, < 2.0)
51
- rspec-support (~> 3.5.0)
52
- rspec-support (3.5.0)
53
- soar-registry-directory (1.0.0)
54
- aws-sdk (~> 2.6, >= 2.6.6)
55
- aws-sdk-core (~> 2.6, >= 2.6.28)
56
- hashie (~> 3.4, >= 3.4.6)
57
- hashy_db (~> 2.1)
58
- mince (~> 2.3)
59
- soar-registry-identity (1.0.0)
60
- soar-registry-directory (~> 1.0.0)
61
- soar_idm (~> 0.0.2)
62
- soar_idm (0.0.2)
63
- jsender
64
-
65
- PLATFORMS
66
- ruby
67
-
68
- DEPENDENCIES
69
- cucumber (~> 2.4)
70
- rspec-expectations (~> 3.5)
71
- soar-authentication-identity!
72
-
73
- BUNDLED WITH
74
- 1.13.6
data/config/config.yml DELETED
@@ -1,7 +0,0 @@
1
- provider:
2
- class: 'Soar::Registry::Staff::Directory::Stub'
3
- config:
4
- endpoint: 'stub'
5
- credentials:
6
- username: 'username'
7
- password: 'secret'