soar-registry-staff 0.0.3 → 0.0.4

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.
@@ -0,0 +1,22 @@
1
+ require 'soar/registry/staff/identity/base'
2
+
3
+ module Soar
4
+ module Registry
5
+ module Staff
6
+ module Identity
7
+ class Email < Base
8
+
9
+ ##
10
+ # @param [String] identifier, an email address that uniquely identifies an identity
11
+ # @return [Hash] an identity
12
+ ##
13
+ def calculate_identities(identifier)
14
+ entries = @directory.search_identities("email", identifier )
15
+ return [@translator.get_identity(entries)[0]]
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'soar/registry/staff/identity/base'
2
+
3
+ module Soar
4
+ module Registry
5
+ module Staff
6
+ module Identity
7
+
8
+ class Id < Base
9
+
10
+ ##
11
+ # @param [String] identifier, a primary key that uniquely identifies an identity
12
+ # @return [Hash] an identity
13
+ ##
14
+ def calculate_identities(identifier)
15
+ return [@translator.get_identity(@directory.fetch_identity(identifier))]
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,81 @@
1
+ module Soar
2
+ module Registry
3
+ module Staff
4
+ module Test
5
+ module Directory
6
+ class Orchestrator
7
+
8
+ attr_reader :directory
9
+
10
+ def initialize(provider)
11
+ @provider = provider.new
12
+ @directory = @provider.directory
13
+ end
14
+
15
+ def reset_data
16
+ clear_data
17
+ load_sample_identities(get_sample_identities)
18
+ end
19
+
20
+ def clear_data
21
+ @directory.bootstrap(valid_configuration['provider']['config'])
22
+ @directory.authenticate(valid_credentials)
23
+ @directory.connect
24
+ delete_data_structure
25
+ create_data_structure
26
+ end
27
+
28
+ def connection_error
29
+ @provider.connection_error
30
+ end
31
+
32
+ def networking_error
33
+ @provider.networking_error
34
+ end
35
+
36
+ def delete_data_structure
37
+ @provider.delete_data_structure
38
+ end
39
+
40
+ def create_data_structure
41
+ @provider.create_data_structure
42
+ end
43
+
44
+ def get_sample_identities
45
+ @provider.get_sample_identities
46
+ end
47
+
48
+ def load_sample_identities(identities)
49
+ @provider.load_sample_identities(identities)
50
+ end
51
+
52
+ def valid_configuration
53
+ @provider.valid_configuration
54
+ end
55
+
56
+ def valid_configuration?(config)
57
+ @provider.valid_configuration?(config)
58
+ end
59
+
60
+ def invalid_configuration(config)
61
+ @provider.invalid_configuration(config)
62
+ end
63
+
64
+ def valid_credentials?(credentials)
65
+ @provider.valid_credentials?(credentials)
66
+ end
67
+
68
+ def valid_credentials
69
+ @provider.valid_credentials
70
+ end
71
+
72
+ def invalid_credentials(credentials)
73
+ @provider.invalid_credentials(credentials)
74
+ end
75
+
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,50 @@
1
+ require 'hashie'
2
+ require 'yaml'
3
+
4
+ module Soar
5
+ module Registry
6
+ module Staff
7
+ module Test
8
+ module Directory
9
+ module Provider
10
+ class Base
11
+
12
+ attr_reader :directory
13
+
14
+ def get_sample_identities
15
+ file = File.read("lib/soar/registry/staff/test/fixtures/identity_data.json")
16
+ JSON.parse(file)
17
+ end
18
+
19
+ def valid_credentials
20
+ valid_config = valid_configuration
21
+ valid_config['provider']['credentials']
22
+ end
23
+
24
+ def valid_configuration
25
+ YAML.load_file("config/config.yml")
26
+ end
27
+
28
+ def invalid_credentials(valid_credentials)
29
+ invalid_credentials = []
30
+ ['username', 'password'].each { |index|
31
+ credentials = deep_copy(valid_credentials)
32
+ credentials.delete(index)
33
+ invalid_credentials << credentials
34
+ }
35
+ return invalid_credentials
36
+ end
37
+
38
+ private
39
+
40
+ def deep_copy(obj)
41
+ return Marshal.load(Marshal.dump(obj))
42
+ end
43
+
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,84 @@
1
+ require 'soar/registry/staff/directory/dynamo_db'
2
+ require 'soar/registry/staff/test/directory/provider/base'
3
+ require 'hashie'
4
+ require 'yaml'
5
+
6
+ module Soar
7
+ module Registry
8
+ module Staff
9
+ module Test
10
+ module Directory
11
+ module Provider
12
+ class DynamoDb < Base
13
+
14
+ def initialize
15
+ @directory = Soar::Registry::Staff::Directory::DynamoDb.new
16
+ end
17
+
18
+ def create_data_structure
19
+ if not @directory.client.list_tables.table_names.include?(valid_configuration['provider']['config']['table'])
20
+ fixture = JSON.parse(File.read("lib/soar/registry/staff/test/fixtures/identity_table.json"), {:symbolize_names => true})
21
+ @directory.client.create_table(fixture)
22
+ end
23
+ end
24
+
25
+ def delete_data_structure
26
+ @directory.client.delete_table({
27
+ table_name: valid_configuration['provider']['config']['table']
28
+ })
29
+ end
30
+
31
+ def load_sample_identities(identities)
32
+ identities.each { |identity|
33
+ @directory.client.put_item({
34
+ table_name: valid_configuration['provider']['config']['table'],
35
+ item: Hashie.symbolize_keys(deep_copy(identity))
36
+ })
37
+ }
38
+ end
39
+
40
+ def connection_error
41
+ configuration = @directory.instance_variable_get(:@configuration)
42
+ configuration['endpoint'] = 'missing'
43
+ @directory.instance_variable_set(:@configuration, configuration)
44
+ end
45
+
46
+ def networking_error
47
+ configuration = @directory.instance_variable_get(:@configuration)
48
+ configuration['endpoint'] = 'http://missing'
49
+ @directory.instance_variable_set(:@configuration, configuration)
50
+ end
51
+
52
+ def valid_configuration
53
+ YAML.load_file("config/config.yml")
54
+ end
55
+
56
+ def valid_configuration?(config)
57
+ @directory.configuration['region'] == config['provider']['config']['region'] and @directory.configuration['endpoint'] == config['provider']['config']['endpoint']
58
+ end
59
+
60
+ def valid_configuration?(config)
61
+ @directory.configuration['region'] == config['provider']['config']['region'] and @directory.configuration['endpoint'] == config['provider']['config']['endpoint']
62
+ end
63
+
64
+ def invalid_configuration(valid_config)
65
+ invalid_config = []
66
+ ['table', 'region', 'endpoint'].each { |index|
67
+ config = deep_copy(valid_config)
68
+ config['provider']['config'].delete(index)
69
+ invalid_config << config
70
+ }
71
+ return invalid_config
72
+ end
73
+
74
+ def valid_credentials?(credentials)
75
+ @directory.credentials['access_key_id'] == credentials['username'] and @directory.credentials['secret_access_key'] == credentials['password']
76
+ end
77
+
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,68 @@
1
+ require 'soar/registry/staff/directory/stub'
2
+ require 'soar/registry/staff/test/directory/provider/base'
3
+ require 'hashie'
4
+ require 'yaml'
5
+
6
+ module Soar
7
+ module Registry
8
+ module Staff
9
+ module Test
10
+ module Directory
11
+ module Provider
12
+ class Stub < Base
13
+
14
+ attr_reader :directory
15
+
16
+ def initialize
17
+ @directory = Soar::Registry::Staff::Directory::Stub.new
18
+ end
19
+
20
+ def create_data_structure
21
+ @directory.interface = Mince::HashyDb::Interface
22
+ end
23
+
24
+ def delete_data_structure
25
+ @directory.interface.clear
26
+ end
27
+
28
+ def load_sample_identities(identities)
29
+ identities.each { |identity|
30
+ @directory.interface.add('identities', identity)
31
+ }
32
+ end
33
+
34
+ def connection_error
35
+ @directory.connection = false
36
+ end
37
+
38
+ def networking_error
39
+ @directory.network = false
40
+ end
41
+
42
+ def valid_configuration
43
+ config = YAML.load_file("config/config.yml")
44
+ config['provider']['adaptor'] = "Soar::Registry::Staff::Directory::Stub"
45
+ return config
46
+ end
47
+
48
+ def valid_configuration?(config)
49
+ config['provider']['adaptor'] == "Soar::Registry::Staff::Directory::Stub"
50
+ end
51
+
52
+ def valid_credentials?(credentials)
53
+ true
54
+ end
55
+
56
+ def invalid_configuration(valid_config)
57
+ invalid_config = deep_copy(valid_config)
58
+ invalid_config['provider']['config'] = {}
59
+ [invalid_config]
60
+ end
61
+
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,60 @@
1
+ [
2
+ {
3
+ "identity_id": "identity-62936e70-1815-439b-bf89-8492855a7e6b",
4
+ "entity_id": "entity-2d931510-d99f-494a-8c67-87feb05e1594",
5
+ "email": "test+publisher@hetzner.co.za",
6
+ "roles": {
7
+ "staff": {
8
+ "department": "technical"
9
+ },
10
+ "configuration_publisher": {
11
+ "configuration_identifiers": ["*"]
12
+ }
13
+ }
14
+ },
15
+ {
16
+ "identity_id": "identity-43353f18-8afe-11e6-ae22-56b6b6499611",
17
+ "entity_id": "entity-2d931510-d99f-494a-8c67-87feb05e1594",
18
+ "email": "test+consumer@hetzner.co.za",
19
+ "roles": {
20
+ "staff": {},
21
+ "configuration_consumer": {
22
+ "configuration_identifiers": ["*"]
23
+ }
24
+
25
+ }
26
+ },
27
+ {
28
+ "identity_id": "identity-820d5660-2204-4f7d-8c04-746313439b81",
29
+ "entity_id": "entity-bad85eb9-0713-4da7-8d36-07a8e4b00eab",
30
+ "email": "admin@hetzner.co.za",
31
+ "roles": {
32
+ "staff": {},
33
+ "configuration_publisher": {
34
+ "configuration_identifiers": ["*"]
35
+ },
36
+ "configuration_consumer": {
37
+ "configuration_identifiers": ["*"]
38
+ }
39
+
40
+ },
41
+ "address": {
42
+ "detail": "Belvedere Office Park, Unit F",
43
+ "street": "Bella Rosa Street",
44
+ "suburb": "Tygervalley",
45
+ "city": "Durbanville",
46
+ "postal": "7550"
47
+ }
48
+ },
49
+ {
50
+ "identity_id": "identity-1ff472a6-8df3-4f13-82c3-89fde26db3cf",
51
+ "entity_id": "entity-bad85eb9-0713-4da7-8d36-07a8e4b00eab",
52
+ "email": "none@example.com",
53
+ "client_nr": "C123456789",
54
+ "roles": {
55
+ "customer": {},
56
+ "reseller": {}
57
+ }
58
+ }
59
+ ]
60
+
@@ -0,0 +1,63 @@
1
+ {
2
+ "table_name": "identities",
3
+ "key_schema": [
4
+ {
5
+ "attribute_name": "identity_id",
6
+ "key_type": "HASH"
7
+ }
8
+ ],
9
+ "attribute_definitions": [
10
+ {
11
+ "attribute_name": "identity_id",
12
+ "attribute_type": "S"
13
+ },
14
+ {
15
+ "attribute_name": "entity_id",
16
+ "attribute_type": "S"
17
+ },
18
+ {
19
+ "attribute_name": "email",
20
+ "attribute_type": "S"
21
+ }
22
+ ],
23
+ "global_secondary_indexes": [
24
+ {
25
+ "index_name": "email_index",
26
+ "key_schema": [
27
+ {
28
+ "attribute_name": "email",
29
+ "key_type": "HASH"
30
+ }
31
+ ],
32
+ "projection": {
33
+ "projection_type": "ALL"
34
+
35
+ },
36
+ "provisioned_throughput": {
37
+ "read_capacity_units": 10,
38
+ "write_capacity_units": 10
39
+ }
40
+ },
41
+ {
42
+ "index_name": "entity_id_index",
43
+ "key_schema": [
44
+ {
45
+ "attribute_name": "entity_id",
46
+ "key_type": "HASH"
47
+ }
48
+ ],
49
+ "projection": {
50
+ "projection_type": "ALL"
51
+
52
+ },
53
+ "provisioned_throughput": {
54
+ "read_capacity_units": 10,
55
+ "write_capacity_units": 10
56
+ }
57
+ }
58
+ ],
59
+ "provisioned_throughput": {
60
+ "read_capacity_units": 10,
61
+ "write_capacity_units": 10
62
+ }
63
+ }