soar-registry-directory 5.0.2 → 6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6dea4c5efb18d2280d073f6bce679b804f623360
4
- data.tar.gz: 0ac2542962c087002260057a9f3e9defc87fc69d
3
+ metadata.gz: c32931eb5c662b57a167f89e9f37641f1069b9f2
4
+ data.tar.gz: 1bd2a2a6fd37c124228ec8e2fa656324a78250fb
5
5
  SHA512:
6
- metadata.gz: 4e374679b5f7f74d35083bb4f6980af26559592c89922b1ca9360f940c156b681604dae1ddeab323058299f5c57e549bca2fc7636237a18b6f651bd5645db4c7
7
- data.tar.gz: 5386f8ff844f3242fba8cd3c42e1f600ce1a885ca1455a50ff332dcd0e4b95437d57192dd6a97382c9bfc6e1551dad75c3c6a67729c92a8cb6baf9dd7b694301
6
+ metadata.gz: 3f8c0d59dedfae89eed3d4fc0bfbb942c4cf583351761cfc1805fb28eb16537e0efb9197512c06cc163d24ce507292a2b94a98c2346a24d2c65941665e11fd0c
7
+ data.tar.gz: b2cf12ef9732c39407ff2796daca5266c60bce849688119dd6b16e3a7acb7f7d833146a36bab77d11483767346825fe152df5307a188b8e05231a7c9a0000c62
data/README.md CHANGED
@@ -7,13 +7,16 @@ Directory model and providers used by soar registries
7
7
  ### Example data
8
8
 
9
9
  ```json
10
- "mytable": [{
11
- "uuid": "1",
12
- "email": "test1@example.com"
13
- }, {
14
- "uuid": "2",
15
- "email": "test2@example.com"
16
- }]
10
+ mytable = [
11
+ {
12
+ "uuid": "1",
13
+ "email": "test1@example.com"
14
+ },
15
+ {
16
+ "uuid": "2",
17
+ "email": "test2@example.com"
18
+ }
19
+ ]
17
20
 
18
21
  ```
19
22
 
@@ -30,22 +33,22 @@ Create an instance of the stub provider by passing in the name, primary key and
30
33
  ```ruby
31
34
  > provider = Soar::Registry::Directory::Provider::DynamoDb.new({
32
35
  table: {
33
- name: 'identity_roles'
34
- index: {
35
- partition_key: 'partition_key'
36
- sort_key: 'sort_key'
37
- global_secondary_index: ['global_secondary_index1']
36
+ 'name' => 'identity_roles'
37
+ 'index' => {
38
+ 'partition_key' => 'partition_key'
39
+ 'sort_key ' => 'sort_key'
40
+ 'global_secondary_index' => ['global_secondary_index1']
38
41
  }
39
42
  },
40
43
  configuration: {
41
- region: 'us-west-2'
42
- endpoint: 'http://localhost:8000'
43
- http_read_timeout: 1,
44
- retry_limit: 0
44
+ 'region' => 'eu-west-1'
45
+ 'endpoint' => 'http://localhost:8000'
46
+ 'http_read_timeout' => 1,
47
+ 'retry_limit' => 0
45
48
  },
46
49
  credentials: {
47
- username: 'username'
48
- password: 'secret'
50
+ 'username' => 'username'
51
+ 'password' => 'secret'
49
52
  }
50
53
  })
51
54
 
@@ -62,15 +65,15 @@ $ sudo apt-get install libmysqlclient-dev
62
65
  > provider = Soar::Registry::Directory::Provider::Mysql.new({
63
66
  index: ['ID', 'Client_Number', 'Notifyemail_Invoice', 'Login'],
64
67
  config: {
65
- database: 'konsoleh_genie'
66
- table: 'Client'
67
- host: '0.0.0.0'
68
- port: 3306
68
+ 'database' => 'konsoleh_genie'
69
+ 'table' => 'Client'
70
+ 'host' => '0.0.0.0'
71
+ 'port' => 3306
69
72
  },
70
73
  attributes: ['Client_Number', 'Notifyemail_Invoice'],
71
74
  credentials: {
72
- username: 'genie'
73
- password: 'secret'
75
+ 'username' => 'genie'
76
+ 'password' => 'secret'
74
77
  }
75
78
  })
76
79
  ```
@@ -81,20 +84,20 @@ Please note: The mysql dump of the genie database structure is out of date. Upda
81
84
 
82
85
  ```ruby
83
86
  > provider = Soar::Registry::Directory::Provider::Ldap.new({
84
- base: 'dc=hetzner,dc=co,dc=za',
85
- index: [:entryuuid, :mail],
87
+ base: 'ou=people,dc=hetzner,dc=co,dc=za',
88
+ index: ['entryuuid', 'mail'],
86
89
  config: {
87
- host: 'localhost',
88
- port: 636
90
+ 'host' => 'localhost',
91
+ 'port' => 636
89
92
  },
90
93
  attributes: ['entryuuid', 'cn', 'mail', 'sn'],
91
94
  credentials: {
92
- username: 'cn=admin,dc=hetzner,dc=co,dc=za'
93
- password: 'secret'
95
+ 'username' => 'cn=admin,dc=hetzner,dc=co,dc=za'
96
+ 'password' => 'secret'
94
97
  }
95
98
  })
96
99
  ```
97
- Please note: Primary key is assumed to be the first element of index array.
100
+ Please note: Primary key is assumed to be the first element of the index array.
98
101
 
99
102
  Command to test secure LDAP connection from terminal.
100
103
  ```bash
@@ -12,31 +12,31 @@ module Soar
12
12
  attr_accessor :client
13
13
 
14
14
  ##
15
- # @param [Hash] credentials
16
- # @option credentials [String] :username
17
- # @option credentials [String] :password
18
- # @param [String] table table name
19
- # @param [Hash] index
20
- # @option index [String] :partition_key
21
- # @option index [String] :sort_key
22
- # @option index [Array] :global_secondary_indexes
23
- # @param configuration [Hash]
24
- # @option configuration [String] :region
25
- # @option configuration [String] :endpoint
15
+ # @param [Hash{String => String}] credentials
16
+ # @option credentials [String] username
17
+ # @option credentials [String] password
18
+ # @param [Hash{String => String}] table
19
+ # @option table [String] name
20
+ # @option table [Hash{String => String}] index
21
+ # * partition_key (String)
22
+ # * sort_key (String)
23
+ # * global_secondary_indexes (Array<String>)
24
+ # @param [Hash{String => String}] configuration
25
+ # @option configuration [String] region
26
+ # @option configuration [String] endpoint
26
27
  ##
27
28
  def initialize(credentials: , table: , configuration: )
28
- @table_name = table[:name]
29
- index = table[:index]
30
- @partition_key = index[:partition_key]
31
- @sort_key = index[:sort_key] if index.key?(:sort_key)
32
- @global_secondary_indexes = index[:global_secondary_index] if index.key?(:global_secondary_index)
33
- @credentials = Hashie.symbolize_keys(credentials)
34
- configuration[:credentials] = Aws::Credentials.new(@credentials[:username], @credentials[:password])
29
+ @table_name = table['name']
30
+ index = table['index']
31
+ @partition_key = index['partition_key']
32
+ @sort_key = index['sort_key'] if index.key?('sort_key')
33
+ @global_secondary_indexes = index['global_secondary_index'] if index.key?('global_secondary_index')
34
+ configuration['credentials'] = Aws::Credentials.new(credentials['username'], credentials['password'])
35
35
  @client = Aws::DynamoDB::Client.new(Hashie.symbolize_keys(configuration))
36
36
  end
37
37
 
38
38
  ##
39
- # @param [Hash] entry
39
+ # @param [Hash{String => String, Hash, Number, Array}] entry
40
40
  # @return [Boolean]
41
41
  # @raise [Soar::Registry::Directory::Error::DuplicateEntryError]
42
42
  ##
@@ -58,10 +58,10 @@ module Soar
58
58
  end
59
59
 
60
60
  ##
61
- # @param [Hash] primary_key
62
- # @option primary_key [String] :partition_key required
63
- # @option primary_key [String] :sort_key required only when defined in schema
64
- # @return [Hash] a single matching entry
61
+ # @param [Hash{String => String}] primary_key
62
+ # @option primary_key [String] partition_key required
63
+ # @option primary_key [String] sort_key required only when defined in schema
64
+ # @return [Hash{String => Hash, String, Number, Array }] a single matching entry
65
65
  # @raise [Soar::Registry::Directory::Error::NoEntriesFoundError] if primary key not found
66
66
  ##
67
67
  def fetch(primary_key)
@@ -79,7 +79,7 @@ module Soar
79
79
  ##
80
80
  # @param [String] key
81
81
  # @param [String] value
82
- # @return [Array] list of matching entries
82
+ # @return [Array<Hash{String => Hash, String, Number, Array}>] list of matching entries
83
83
  # @raise [ArgumentError] if query or index is not specified
84
84
  ##
85
85
  def search(key, value)
@@ -103,7 +103,7 @@ module Soar
103
103
  end
104
104
 
105
105
  ##
106
- # @return [Array] a list of primary keys and global secondary indexes
106
+ # @return [Array<String>] a list of primary keys and global secondary indexes
107
107
  ##
108
108
  def index
109
109
  adapt_exceptions do
@@ -128,13 +128,13 @@ module Soar
128
128
  ##
129
129
  # Deletes existing table and creates a new one in its place
130
130
  # @param [String] name the table name
131
- # @param [Hash] structure table structure
131
+ # @param [Hash{String => Hash, Array, String, Number]] structure table structure
132
132
  # @return [Boolean]
133
133
  ##
134
- def recreate_table(name: nil, structure: nil)
134
+ def recreate_table(name:, structure:)
135
135
  adapt_exceptions do
136
136
  if @client.list_tables.table_names.include?(name)
137
- @client.delete_table({
137
+ result = @client.delete_table({
138
138
  table_name: name
139
139
  })
140
140
  end
@@ -153,6 +153,8 @@ module Soar
153
153
  raise Soar::Registry::Directory::Error::NetworkingError, e.message
154
154
  rescue Aws::DynamoDB::Errors::ConditionalCheckFailedException => e
155
155
  raise Soar::Registry::Directory::Error::DuplicateEntryError, e.message
156
+ rescue StandardError => e
157
+ raise e, e.message
156
158
  end
157
159
  end
158
160
 
@@ -1,6 +1,5 @@
1
1
  require 'soar/registry/directory/error'
2
2
  require 'net/ldap'
3
- require 'hashie'
4
3
 
5
4
  module Soar
6
5
  module Registry
@@ -11,27 +10,28 @@ module Soar
11
10
  attr_accessor :client
12
11
 
13
12
  ##
14
- # @param [Hash] config
15
- # @option config [String] :host
16
- # @option config [Number] :port
13
+ # @param [Hash{String => String, Number}] config
14
+ # @option config [String] host
15
+ # @option config [Number] port
17
16
  # @param [String] base ldap tree base eg 'dc=hetzner,dc=co,dc=za'
18
- # @param [Array] attributes array of attributes to return for queries
19
- # @param [Hash] credentials
20
- # @option credentials [String] :username
21
- # @option credentials [String] :password
17
+ # @param [Array<String>] attributes array of attributes to return for queries
18
+ # @param [Array<String>] index
19
+ # @param [Hash{String => String}] credentials
20
+ # @option credentials [String] username
21
+ # @option credentials [String] password
22
22
  ##
23
23
  def initialize(config: , base: , attributes: , index: , credentials: )
24
24
  adapt_exceptions do
25
25
  @index = index.map { |x| x.to_sym }
26
26
  @attributes = attributes
27
27
  @config = {
28
- host: config[:host],
29
- port: config[:port],
28
+ host: config['host'],
29
+ port: config['port'],
30
30
  base: base,
31
31
  auth: {
32
32
  method: :simple,
33
- username: credentials[:username],
34
- password: credentials[:password]
33
+ username: credentials['username'],
34
+ password: credentials['password']
35
35
  },
36
36
  encryption: {
37
37
  method: :simple_tls
@@ -42,7 +42,7 @@ module Soar
42
42
  end
43
43
 
44
44
  ##
45
- # @param [Hash] entry
45
+ # @param [Hash{Symbol => }] entry
46
46
  # @return [Boolean]
47
47
  # @raise [Soar::Registry::Directory::Error::DuplicateEntryError]
48
48
  ##
@@ -66,7 +66,7 @@ module Soar
66
66
 
67
67
  ##
68
68
  # @param [String] primary key of the identity ie. the first index
69
- # @return [Hash] single matching entry
69
+ # @return [Hash{Symbol => String, Number, Array}] single matching entry
70
70
  # @raise [Soar::Registry::Directory::Error::NoEntriesFoundError] if primary key not found
71
71
  # @raise [Soar::Registry::Directory::Error::MultipleEntriesFound] if multiple matches found
72
72
  ##
@@ -91,7 +91,7 @@ module Soar
91
91
  ##
92
92
  # @param [String] key
93
93
  # @param [String] value
94
- # @return [Array] list of matching entries
94
+ # @return [Array<Hash{Symbol => String, Array, Number}>] list of matching entries
95
95
  # @raise [ArgumentError] if value or named index is not specified
96
96
  ##
97
97
  def search(key, value)
@@ -115,7 +115,7 @@ module Soar
115
115
  end
116
116
 
117
117
  ##
118
- # @return [Array] a list of indexes
118
+ # @return [Array<String, Number>] a list of indexes
119
119
  ##
120
120
  def index
121
121
  adapt_exceptions do
@@ -10,35 +10,35 @@ module Soar
10
10
  attr_accessor :client
11
11
 
12
12
  ##
13
- # @param [Hash] config
14
- # @option config [String] :host
15
- # @option config [Number] :port
16
- # @option config [String] :database name
17
- # @option config [String] :table name
18
- # @param [Array] attributes array of attributes to return for queries
19
- # @param [Array] index array of indexes starting with the primary key
20
- # @param [Hash] credentials
21
- # @option credentials [String] :username
22
- # @option credentials [String] :password
13
+ # @param [Hash{String => String, Number}] config
14
+ # @option config [String] host
15
+ # @option config [Number] port
16
+ # @option config [String] database
17
+ # @option config [String] table
18
+ # @param [Array<String>] attributes array of attributes to return for queries
19
+ # @param [Array<String>] index array of indexes starting with the primary key
20
+ # @param [Hash{String => String}] credentials
21
+ # @option credentials [String] 'username'
22
+ # @option credentials [String] 'password'
23
23
  ##
24
24
  def initialize(config: , attributes: '*', index: , credentials: )
25
25
  adapt_exceptions do
26
26
  @attributes = attributes.kind_of?(Array) ? attributes.join(', ') : attributes
27
27
  @index = index
28
- @table = config[:table]
28
+ @table = config['table']
29
29
  @config = {
30
- host: config[:host],
31
- port: config[:port],
32
- database: config[:database],
33
- username: credentials[:username],
34
- password: credentials[:password]
30
+ host: config['host'],
31
+ port: config['port'],
32
+ database: config['database'],
33
+ username: credentials['username'],
34
+ password: credentials['password']
35
35
  }
36
36
  @client = ::Mysql.new(@config[:host], @config[:username], @config[:password], @config[:database])
37
37
  end
38
38
  end
39
39
 
40
40
  ##
41
- # @param [Hash] entry
41
+ # @param [Hash{Symbol => String, Number}] entry
42
42
  # @return [Boolean]
43
43
  ##
44
44
  def put(entry)
@@ -51,7 +51,7 @@ module Soar
51
51
 
52
52
  ##
53
53
  # @param [String] primary key the first index
54
- # @return [Hash] single matching entry
54
+ # @return [Hash{Symbol => String, Number}] single matching entry
55
55
  # @raise [Soar::Registry::Directory::Error::NoEntriesFoundError] if primary key not found
56
56
  # @raise [Soar::Registry::Directory::Error::MultipleEntriesFound] if multiple matches found
57
57
  ##
@@ -75,7 +75,7 @@ module Soar
75
75
  ##
76
76
  # @param [String] key should be in indexed in db schema
77
77
  # @param [String] value
78
- # @return [Array] list of matching entries
78
+ # @return [Array<Hash{Symbol => String, Number}>] list of matching entries
79
79
  # @raise [ArgumentError] if value or named index is not specified
80
80
  ##
81
81
  def search(key, value)
@@ -98,7 +98,7 @@ module Soar
98
98
  end
99
99
 
100
100
  ##
101
- # @return [Array] a list of indexes the first being the primary key
101
+ # @return [Array<String>] a list of indexes the first being the primary key
102
102
  ##
103
103
  def index
104
104
  adapt_exceptions do
@@ -11,7 +11,7 @@ module Soar
11
11
 
12
12
  ##
13
13
  # @param [String] table the table name
14
- # @param [Array] indexes primary key should be the first item
14
+ # @param [Array<String>] indexes primary key should be the first item
15
15
  ##
16
16
  def initialize(table: , index: )
17
17
  @interface = Mince::HashyDb::Interface
@@ -22,7 +22,7 @@ module Soar
22
22
  end
23
23
 
24
24
  ##
25
- # @param [Hash] entry
25
+ # @param [Hash{String => Hash, String, Number, Array}] entry
26
26
  # @raise [Soar::Registry::Directory::Error::DuplicateEntryError]
27
27
  # @return [Boolean]
28
28
  ##
@@ -38,7 +38,7 @@ module Soar
38
38
 
39
39
  ##
40
40
  # @param [String] primary_key
41
- # @return [Hash] entry
41
+ # @return [Hash{String => Hash, String, Number, Array}] entry
42
42
  # @raise [Soar::Registry:::Directory::Error::NoEntriesFoundError] if primary key not found
43
43
  ##
44
44
  def fetch(primary_key)
@@ -52,7 +52,7 @@ module Soar
52
52
  ##
53
53
  # @param [String] key
54
54
  # @param [String] value
55
- # @return [Array] list of matching entries
55
+ # @return [Array<String>] list of matching entries
56
56
  # @raise [ArgumentError] if query or index is not specified
57
57
  ##
58
58
  def search(key, value)
@@ -70,7 +70,7 @@ module Soar
70
70
  end
71
71
 
72
72
  ##
73
- # @return [Array] a list of provider specific indexes
73
+ # @return [Array<String>] a list of provider specific indexes
74
74
  ##
75
75
  def index
76
76
  adapt_exceptions do
@@ -1,6 +1,5 @@
1
1
  require 'soar/registry/directory'
2
2
  require 'aws-sdk'
3
- require 'hashie'
4
3
  require 'soar/registry/directory/error'
5
4
 
6
5
  module Soar
@@ -21,10 +20,10 @@ module Soar
21
20
 
22
21
  def given_configured_directory
23
22
  begin
24
- provider = Soar::Registry::Directory::Provider::DynamoDb.new(Hashie.symbolize_keys(@configuration['provider']['config']))
23
+ provider = Soar::Registry::Directory::Provider::DynamoDb.new(@configuration['provider']['config'].map { |k, v| [k.to_sym, v] }.to_h)
25
24
  @directory = Soar::Registry::Directory.new(provider)
26
25
  @directory.provider.recreate_table({
27
- name: @table[:name],
26
+ name: @table['name'],
28
27
  structure: JSON.parse(File.read("lib/soar/registry/directory/test/fixtures/table_structure.json"))
29
28
  })
30
29
  rescue Soar::Registry::Directory::Error::NetworkingError => e
@@ -42,8 +41,8 @@ module Soar
42
41
  end
43
42
 
44
43
  def sabotage_network
45
- @configuration['provider']['config']['configuration'][:endpoint] = 'http://does-not-exist'
46
- @directory.provider.client = Aws::DynamoDB::Client.new(Hashie.symbolize_keys(@configuration['provider']['config']['configuration']))
44
+ @configuration['provider']['config']['configuration']['endpoint'] = 'http://does-not-exist'
45
+ @directory.provider.client = Aws::DynamoDB::Client.new(@configuration['provider']['config']['configuration'].map { |k, v| [k.to_sym, v] }.to_h)
47
46
  end
48
47
 
49
48
  def put_duplicate_entry
@@ -104,9 +103,9 @@ module Soar
104
103
 
105
104
  def index?
106
105
  @index == {
107
- partition_key: @index[:partition_key],
108
- sort_key: @index[:sort_key],
109
- global_secondary_index: @index[:global_secondary_index]
106
+ "partition_key" => @index['partition_key'],
107
+ "sort_key" => @index['sort_key'],
108
+ "global_secondary_index" => @index['global_secondary_index']
110
109
  }
111
110
  end
112
111
 
@@ -1,5 +1,4 @@
1
1
  require 'soar/registry/directory'
2
- require 'hashie'
3
2
  require 'securerandom'
4
3
 
5
4
  module Soar
@@ -36,7 +35,7 @@ module Soar
36
35
  def given_configured_directory
37
36
  begin
38
37
  provider_class = Object.const_get(@configuration['provider']['class'])
39
- provider = provider_class.new(Hashie.symbolize_keys(@configuration['provider']['config']))
38
+ provider = provider_class.new(@configuration['provider']['config'].map { |k,v| [k.to_sym, v] }.to_h )
40
39
  @directory = Soar::Registry::Directory.new(provider)
41
40
  @entries.each { |entry|
42
41
  provider.delete(entry[:dn])
@@ -1,6 +1,5 @@
1
1
  require 'soar/registry/directory'
2
- require 'mysql'
3
- # http://zetcode.com/db/mysqlrubytutorial/
2
+ require 'mysql' # http://zetcode.com/db/mysqlrubytutorial/
4
3
 
5
4
  module Soar
6
5
  module Registry
@@ -34,7 +33,7 @@ module Soar
34
33
  def given_configured_directory
35
34
  begin
36
35
  provider_class = Object.const_get(@configuration['provider']['class'])
37
- provider = provider_class.new(Hashie.symbolize_keys(@configuration['provider']['config']))
36
+ provider = provider_class.new(@configuration['provider']['config'].map { |k,v| [k.to_sym, v]}.to_h )
38
37
  provider.client.query("DROP TABLE IF EXISTS `Client`")
39
38
  provider.client.query("CREATE TABLE Client ( ID int(11) NOT NULL AUTO_INCREMENT, Client_Number varchar(15) NOT NULL DEFAULT '', First_Name varchar(70) DEFAULT NULL, Surname varchar(70) DEFAULT NULL, Notifyemail_Invoice text, PRIMARY KEY (ID), KEY Notifyemail_Invoice (Notifyemail_Invoice(20)), KEY Client_Number (Client_Number))")
40
39
  @directory = Soar::Registry::Directory.new(provider)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soar-registry-directory
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.2
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Mulder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-07 00:00:00.000000000 Z
11
+ date: 2017-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashy_db
@@ -64,20 +64,20 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '3.4'
67
+ version: '3.5'
68
68
  - - ">="
69
69
  - !ruby/object:Gem::Version
70
- version: 3.4.6
70
+ version: 3.5.5
71
71
  type: :runtime
72
72
  prerelease: false
73
73
  version_requirements: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - "~>"
76
76
  - !ruby/object:Gem::Version
77
- version: '3.4'
77
+ version: '3.5'
78
78
  - - ">="
79
79
  - !ruby/object:Gem::Version
80
- version: 3.4.6
80
+ version: 3.5.5
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: net-ldap
83
83
  requirement: !ruby/object:Gem::Requirement