soar-authentication-identity_uuid_translator 1.0.0

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.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.gemspec +16 -0
  3. data/.gitignore +24 -0
  4. data/.rspec +3 -0
  5. data/Dockerfile.dynamo_db +5 -0
  6. data/Dockerfile.features +7 -0
  7. data/Dockerfile.rspec +6 -0
  8. data/Gemfile +10 -0
  9. data/README.md +86 -0
  10. data/Rakefile +14 -0
  11. data/config/config.ci.dynamo_db.yml +15 -0
  12. data/config/config.ci.ldap.yml +17 -0
  13. data/config/config.ci.mysql.yml +18 -0
  14. data/config/config.dynamo_db.yml +15 -0
  15. data/config/config.ldap.yml +17 -0
  16. data/config/config.mysql.yml +18 -0
  17. data/docker-compose.ci.customer_client_number.yml +34 -0
  18. data/docker-compose.ci.customer_email.yml +34 -0
  19. data/docker-compose.ci.factory.yml +16 -0
  20. data/docker-compose.ci.role_generator.yml +27 -0
  21. data/docker-compose.ci.staff.yml +37 -0
  22. data/docker-compose.customer.yml +18 -0
  23. data/docker-compose.dynamo_db.yml +8 -0
  24. data/docker-compose.staff.yml +21 -0
  25. data/lib/soar/authentication/identity_uuid_translator.rb +13 -0
  26. data/lib/soar/authentication/identity_uuid_translator/error.rb +11 -0
  27. data/lib/soar/authentication/identity_uuid_translator/factory.rb +23 -0
  28. data/lib/soar/authentication/identity_uuid_translator/model.rb +24 -0
  29. data/lib/soar/authentication/identity_uuid_translator/provider/customer.rb +54 -0
  30. data/lib/soar/authentication/identity_uuid_translator/provider/staff.rb +33 -0
  31. data/lib/soar/authentication/identity_uuid_translator/role_generator.rb +21 -0
  32. data/lib/soar/authentication/identity_uuid_translator/test/fixtures/client_table.sql +91 -0
  33. data/lib/soar/authentication/identity_uuid_translator/test/fixtures/roles_table.json +27 -0
  34. data/lib/soar/authentication/identity_uuid_translator/test/fixtures/staff.json +18 -0
  35. data/lib/soar/authentication/identity_uuid_translator/test/orchestration_provider/base.rb +78 -0
  36. data/lib/soar/authentication/identity_uuid_translator/test/orchestration_provider/customer.rb +50 -0
  37. data/lib/soar/authentication/identity_uuid_translator/test/orchestration_provider/customer_client_number.rb +52 -0
  38. data/lib/soar/authentication/identity_uuid_translator/test/orchestration_provider/customer_email.rb +52 -0
  39. data/lib/soar/authentication/identity_uuid_translator/test/orchestration_provider/staff.rb +79 -0
  40. data/lib/soar/authentication/identity_uuid_translator/test/orchestrator.rb +55 -0
  41. data/lib/soar/authentication/identity_uuid_translator/uuid_generator.rb +13 -0
  42. metadata +145 -0
@@ -0,0 +1,18 @@
1
+ version: "2"
2
+ services:
3
+ mysql:
4
+ image: mysql:5.5
5
+ ports:
6
+ - "3306:3306"
7
+ environment:
8
+ - MYSQL_ROOT_PASSWORD=secret
9
+ - MYSQL_DATABASE=konsoleh_genie
10
+ - MYSQL_USER=genie
11
+ - MYSQL_PASSWORD=secret
12
+
13
+ dynamodb:
14
+ build:
15
+ context: .
16
+ dockerfile: Dockerfile.dynamo_db
17
+ ports:
18
+ - "8000:8000"
@@ -0,0 +1,8 @@
1
+ version: "2"
2
+ services:
3
+ dynamodb:
4
+ build:
5
+ context: .
6
+ dockerfile: Dockerfile.dynamo_db
7
+ ports:
8
+ - "8000:8000"
@@ -0,0 +1,21 @@
1
+ version: "2"
2
+ services:
3
+ ldap:
4
+ image: osixia/openldap:1.1.7
5
+ ports:
6
+ - "389:389"
7
+ - "636:636"
8
+ environment:
9
+ - LDAP_DOMAIN=hetzner.co.za
10
+ - LDAP_ORGANISATION=Hetzner
11
+ - LDAP_ADMIN_PASSWORD=secret
12
+ - LDAP_TLS_VERIFY_CLIENT=never
13
+ - LDAP_TLS_PROTOCOL_MIN=1.2
14
+ - LDAP_TLS_CIPHER_SUITE=SECURE128:-VERS-SSL3.0:+VERS-TLS1.2
15
+
16
+ dynamodb:
17
+ build:
18
+ context: .
19
+ dockerfile: Dockerfile.dynamo_db
20
+ ports:
21
+ - "8000:8000"
@@ -0,0 +1,13 @@
1
+ require 'soar/authentication/identity_uuid_translator/model'
2
+
3
+ module Soar
4
+ module Authentication
5
+ module IdentityUuidTranslator
6
+
7
+ def self.new(provider)
8
+ Soar::Authentication::IdentityUuidTranslator::Model.new(provider)
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module Soar
2
+ module Authentication
3
+ module IdentityUuidTranslator
4
+ module Error
5
+ class UnknownIdentityError < StandardError; end;
6
+ end
7
+ end
8
+ end
9
+ end
10
+
11
+
@@ -0,0 +1,23 @@
1
+ require 'soar/authentication/identity_uuid_translator'
2
+
3
+ module Soar
4
+ module Authentication
5
+ module IdentityUuidTranslator
6
+ module Factory
7
+
8
+ ##
9
+ # @param [String] value
10
+ # @param [ObjectSelector] selector
11
+ # @raise [ObjectSelector::Error::NoMatchError]
12
+ # @return [Soar::Registry::Identity]
13
+ ##
14
+ def self.create(selector: , value: )
15
+ provider = selector.select(value)
16
+ return Soar::Authentication::IdentityUuidTranslator.new(provider)
17
+ end
18
+
19
+
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ require 'soar/authentication/identity_uuid_translator/error'
2
+ require 'soar/authentication/identity_uuid_translator/provider/staff'
3
+ require 'soar/authentication/identity_uuid_translator/provider/customer'
4
+
5
+ module Soar
6
+ module Authentication
7
+ module IdentityUuidTranslator
8
+
9
+ class Model
10
+
11
+ attr_reader :provider
12
+
13
+ def initialize(provider)
14
+ @provider = provider
15
+ end
16
+
17
+ def uuid
18
+ @provider.uuid
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,54 @@
1
+ require 'soar/registry/identity'
2
+ require 'uuidtools'
3
+
4
+ module Soar
5
+ module Authentication
6
+ module IdentityUuidTranslator
7
+ module Provider
8
+ class Customer
9
+
10
+ ROLE = "customer_account_administrator"
11
+ PREFIX = "genie:client:id:"
12
+
13
+ ##
14
+ # @param [String] identifier
15
+ # @param [Soar::Registry::Identity] identity_registry
16
+ # @param [Soar::Authentication::IdentityUuidTranslator:UuidGenerator] uuid_generator
17
+ # @param [Soar::Registry::Directory] roles_directory
18
+ ##
19
+ def initialize(identifier: , identity_registry: , uuid_generator: nil, role_generator: nil)
20
+ @idr = identity_registry
21
+ @uuid_generator = uuid_generator
22
+ @identifier = identifier
23
+ @role_generator = role_generator
24
+ end
25
+
26
+ def uuid
27
+ return @uuid if not @uuid.nil?
28
+ @identifiers = @idr.get_identifiers(@identifier)
29
+ @uuid = @uuid_generator.nil? ? @identifiers[0] : @uuid_generator::generate("#{PREFIX}#{@identifiers[0]}")
30
+ @role_generator.generate({
31
+ "identity_uuid" => uuid,
32
+ "identity_role" => ROLE,
33
+ "identity_role_attributes" => [client_number].compact
34
+ }) if not @role_generator.nil?
35
+ return @uuid
36
+ end
37
+
38
+ ##
39
+ # @return [String|Nil]
40
+ ##
41
+ def client_number
42
+ client_number = @identifiers.map do |identifier|
43
+ next if not identifier.is_a?(String) # it's an ID
44
+ break identifier if /\A[CF]{0,1}\d+\z/i.match(identifier)
45
+ end
46
+ client_number.is_a?(Array) ? nil : client_number
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,33 @@
1
+ require 'soar/registry/identity'
2
+
3
+ module Soar
4
+ module Authentication
5
+ module IdentityUuidTranslator
6
+ module Provider
7
+ class Staff
8
+
9
+ ROLE = "hetzner_staff_member"
10
+
11
+ def initialize(identifier: , identity_registry: , role_generator: nil)
12
+ @identifier = identifier
13
+ @idr = identity_registry
14
+ @role_generator = role_generator
15
+ end
16
+
17
+ def uuid
18
+ return @uuid if not @uuid.nil?
19
+ identifiers = @idr.get_identifiers(@identifier)
20
+ @uuid = identifiers[0]
21
+ @role_generator.generate({
22
+ "identity_uuid" => uuid,
23
+ "identity_role" => ROLE
24
+ }) if not @role_generator.nil?
25
+ return @uuid
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ module Soar
2
+ module Authentication
3
+ module IdentityUuidTranslator
4
+ class RoleGenerator
5
+
6
+ def initialize(directory)
7
+ @directory = directory
8
+ end
9
+
10
+ def generate(role)
11
+ begin
12
+ @directory.put(role)
13
+ rescue Soar::Registry::Directory::Error::DuplicateEntryError => e
14
+ true
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,91 @@
1
+ DROP TABLE IF EXISTS `Client`;
2
+ CREATE TABLE `Client` (
3
+ `ID` int(11) NOT NULL AUTO_INCREMENT,
4
+ `Timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
5
+ `Client_Number` varchar(15) NOT NULL DEFAULT '',
6
+ `Privil` varchar(15) NOT NULL DEFAULT '',
7
+ `Active` enum('0','1') NOT NULL DEFAULT '0',
8
+ `ActiveUntil` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
9
+ `MaxDomains` int(11) NOT NULL DEFAULT '100',
10
+ `Title` varchar(10) DEFAULT NULL,
11
+ `First_Name` varchar(70) DEFAULT NULL,
12
+ `Surname` varchar(70) DEFAULT NULL,
13
+ `Company` varchar(70) DEFAULT NULL,
14
+ `Street` varchar(70) DEFAULT NULL,
15
+ `Postal_Code` varchar(10) DEFAULT NULL,
16
+ `Suburb` varchar(70) NOT NULL DEFAULT '',
17
+ `Country` varchar(70) NOT NULL DEFAULT '0',
18
+ `City` varchar(70) NOT NULL DEFAULT '',
19
+ `CountryGroup` enum('0','1','2') NOT NULL DEFAULT '0',
20
+ `Telephone` varchar(50) DEFAULT NULL,
21
+ `Cellphone` varchar(50) NOT NULL DEFAULT '',
22
+ `ID_Number` varchar(30) DEFAULT NULL,
23
+ `Date_Of_Birth` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
24
+ `Fax` varchar(50) DEFAULT NULL,
25
+ `RipeHandle` varchar(16) NOT NULL DEFAULT '',
26
+ `Login` varchar(15) DEFAULT NULL,
27
+ `Password` varchar(30) DEFAULT NULL,
28
+ `FromEmail1` varchar(40) NOT NULL DEFAULT '',
29
+ `FromEmail2` varchar(40) DEFAULT NULL,
30
+ `FromEmail3` varchar(40) DEFAULT NULL,
31
+ `PublicKey` mediumtext NOT NULL,
32
+ `Newsletter` enum('0','1') NOT NULL DEFAULT '0',
33
+ `Notice` enum('0','1') NOT NULL DEFAULT '1',
34
+ `Notifyemail` varchar(100) DEFAULT NULL,
35
+ `Notifyemail_Robot` varchar(100) NOT NULL DEFAULT '',
36
+ `Notifyemail_Traffic` varchar(100) DEFAULT NULL,
37
+ `Notifyemail_Invoice` text,
38
+ `FreeTraffic` decimal(4,2) DEFAULT NULL,
39
+ `Bank_Branch_Code` varchar(8) DEFAULT NULL,
40
+ `Bank_Account_Number` varchar(30) DEFAULT NULL,
41
+ `Bank_Account_Holder` varchar(60) DEFAULT NULL,
42
+ `Bank_Account_Type` enum('0','1','2','3','4','5') NOT NULL DEFAULT '0',
43
+ `Bank_Name` varchar(60) NOT NULL DEFAULT '',
44
+ `Bank_Branch_Location` varchar(60) NOT NULL DEFAULT '',
45
+ `Reseller` enum('0','1') NOT NULL DEFAULT '0',
46
+ `Reseller_Proof` varchar(60) NOT NULL DEFAULT '',
47
+ `CreditCardNumber` varchar(30) NOT NULL DEFAULT '',
48
+ `CreditCardExpiration` varchar(6) NOT NULL DEFAULT '',
49
+ `CreditCardName` varchar(15) NOT NULL DEFAULT '',
50
+ `payment_method` enum('Unspecified','Cash','Debit Order') NOT NULL DEFAULT 'Unspecified',
51
+ `Mother_ID` varchar(12) NOT NULL DEFAULT '',
52
+ `ChargeVAT` enum('0','1') NOT NULL DEFAULT '1',
53
+ `Summary_Invoice` enum('0','1') NOT NULL DEFAULT '0',
54
+ `Separate_Invoice` enum('0','1') NOT NULL DEFAULT '0',
55
+ `Email_Format` enum('0','1','2','3') NOT NULL DEFAULT '1',
56
+ `Dedi_Graph` enum('0','1') NOT NULL DEFAULT '1',
57
+ `TaxID` varchar(20) NOT NULL DEFAULT '',
58
+ `Discount` decimal(4,2) DEFAULT NULL,
59
+ `ChargeRobotSetup` enum('0','1','2') DEFAULT NULL,
60
+ `ClientCreated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
61
+ `Comment` text,
62
+ `Advice` mediumtext NOT NULL,
63
+ `Vat_Number` varchar(30) DEFAULT NULL,
64
+ `Rejection_Counter` tinyint(11) DEFAULT '0',
65
+ `Marketing` enum('Print','Brainstorm','ComputerActive','Google','ITWeb','Mouth','Website','Search','Designer','Hetzner','Other','SA Computer Magazine','Entrepreneur Magazine','Financial Mail') DEFAULT NULL,
66
+ `Marketing_other` mediumtext,
67
+ `Billing_First_Name` varchar(70) NOT NULL DEFAULT '',
68
+ `Billing_Surname` varchar(70) NOT NULL DEFAULT '',
69
+ `Billing_Telephone` varchar(50) NOT NULL DEFAULT '',
70
+ `Billing_Cellphone` varchar(50) NOT NULL DEFAULT '',
71
+ `Tech_First_Name` varchar(70) NOT NULL DEFAULT '',
72
+ `Tech_Surname` varchar(70) NOT NULL DEFAULT '',
73
+ `Notifyemail_Tech` varchar(100) NOT NULL DEFAULT '',
74
+ `Tech_Telephone` varchar(50) NOT NULL DEFAULT '',
75
+ `Tech_Cellphone` varchar(50) NOT NULL DEFAULT '',
76
+ `Verified` enum('0','1') NOT NULL DEFAULT '1',
77
+ `mass_update_notification_sent` enum('1','2','3','more','no') NOT NULL DEFAULT 'no',
78
+ `mass_update_submission_sent` enum('yes','no') NOT NULL DEFAULT 'no',
79
+ `contact_Confirmed` enum('True','False') NOT NULL DEFAULT 'True',
80
+ `is_test_profile` enum('0','1') DEFAULT '0',
81
+ `Google` enum('None','Eligible','Emailed','Issued') NOT NULL DEFAULT 'None',
82
+ `Google_Value_ID` int(11) NOT NULL DEFAULT '0',
83
+ `Google_Expiry` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
84
+ `app_installer_active` tinyint(1) DEFAULT '1',
85
+ PRIMARY KEY (`ID`),
86
+ KEY `Login` (`Login`),
87
+ KEY `Password` (`Password`),
88
+ KEY `Notifyemail_Invoice` (`Notifyemail_Invoice`(20)),
89
+ KEY `Client_Number` (`Client_Number`)
90
+ ) ENGINE=InnoDB AUTO_INCREMENT=185532 DEFAULT CHARSET=latin1;
91
+
@@ -0,0 +1,27 @@
1
+ {
2
+ "table_name": "identity_roles",
3
+ "key_schema": [
4
+ {
5
+ "attribute_name": "identity_uuid",
6
+ "key_type": "HASH"
7
+ },
8
+ {
9
+ "attribute_name": "identity_role",
10
+ "key_type": "RANGE"
11
+ }
12
+ ],
13
+ "attribute_definitions": [
14
+ {
15
+ "attribute_name": "identity_uuid",
16
+ "attribute_type": "S"
17
+ },
18
+ {
19
+ "attribute_name": "identity_role",
20
+ "attribute_type": "S"
21
+ }
22
+ ],
23
+ "provisioned_throughput": {
24
+ "read_capacity_units": 10,
25
+ "write_capacity_units": 10
26
+ }
27
+ }
@@ -0,0 +1,18 @@
1
+ [
2
+ {
3
+ "entryuuid": "62936e70-1815-439b-bf89-8492855a7e6b",
4
+ "mail": "test+publisher@hetzner.co.za"
5
+ },
6
+ {
7
+ "entryuuid": "43353f18-8afe-11e6-ae22-56b6b6499611",
8
+ "mail": "test+consumer@hetzner.co.za"
9
+ },
10
+ {
11
+ "entryuuid": "820d5660-2204-4f7d-8c04-746313439b81",
12
+ "mail": "admin@hetzner.co.za"
13
+ },
14
+ {
15
+ "entryuuid": "1ff472a6-8df3-4f13-82c3-89fde26db3cf",
16
+ "mail": "none@example.com"
17
+ }
18
+ ]
@@ -0,0 +1,78 @@
1
+ require 'soar/authentication/identity_uuid_translator/factory'
2
+ require 'soar/authentication/identity_uuid_translator/uuid_generator'
3
+ require 'soar/authentication/identity_uuid_translator/role_generator'
4
+ require 'soar/registry/directory'
5
+ require 'object_selector'
6
+ require 'faker'
7
+ require 'hashie'
8
+
9
+ module Soar
10
+ module Authentication
11
+ module IdentityUuidTranslator
12
+ module Test
13
+ module OrchestrationProvider
14
+ class Base
15
+
16
+ def given_roles_directory
17
+ roles_directory_configuration = YAML.load_file("config/#{ENV['ROLES_DIRECTORY_CONFIG_FILE']}")
18
+ @roles_directory = Soar::Registry::Directory.new(
19
+ Soar::Registry::Directory::Provider::DynamoDb.new(Hashie.symbolize_keys(roles_directory_configuration['config']))
20
+ )
21
+ @roles_directory.provider.recreate_table({
22
+ name: roles_directory_configuration['config']['table'][:name],
23
+ structure: JSON.parse(File.read("lib/soar/authentication/identity_uuid_translator/test/fixtures/roles_table.json"))
24
+ })
25
+ end
26
+
27
+ def given_role_generator
28
+ @role_generator = Soar::Authentication::IdentityUuidTranslator::RoleGenerator.new(@roles_directory)
29
+ end
30
+
31
+ def given_identity_uuid_translator
32
+ @identity_uuid_translator = Soar::Authentication::IdentityUuidTranslator::Factory::create({
33
+ value: @identifier,
34
+ selector: ObjectSelector.new(
35
+ ObjectSelector::Provider::RegexRuleList.new({
36
+ rules: [
37
+ {
38
+ regex: /\A[\w+\-.]+@hetzner.co.za\z/i,
39
+ object: Soar::Authentication::IdentityUuidTranslator::Provider::Staff.new(
40
+ identifier: @identifier,
41
+ identity_registry: @identity_registry,
42
+ role_generator: @role_generator ? @role_generator : nil
43
+ )
44
+ },
45
+ {
46
+ regex: /\A[\w+\-.]+@.+/i,
47
+ object: Soar::Authentication::IdentityUuidTranslator::Provider::Customer.new(
48
+ identifier: @identifier,
49
+ identity_registry: @identity_registry,
50
+ uuid_generator: Soar::Authentication::IdentityUuidTranslator::UuidGenerator,
51
+ role_generator: @role_generator ? @role_generator : nil
52
+ )
53
+ },
54
+ {
55
+ regex: /\A[CF]{0,1}\d+\z/,
56
+ object: Soar::Authentication::IdentityUuidTranslator::Provider::Customer.new(
57
+ identifier: @identifier,
58
+ identity_registry: @identity_registry,
59
+ uuid_generator: Soar::Authentication::IdentityUuidTranslator::UuidGenerator,
60
+ role_generator: @role_generator ? @role_generator : nil
61
+ )
62
+ }
63
+ ]
64
+ })
65
+ )
66
+ })
67
+ end
68
+
69
+ def request_identity_uuid
70
+ @uuid = @identity_uuid_translator.uuid()
71
+ end
72
+
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end