idr_client 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/idr_client.rb +78 -3
  3. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f20475104672ed1c698969b86285488f338c00f1
4
- data.tar.gz: 319f90522a9faf84c0943625e5c377957e5b5d04
3
+ metadata.gz: ab0992f262a2a01f0f4bfd7c712900c1ffb4408f
4
+ data.tar.gz: 8ec5f04a3a7c132985e1d8d46eaa60c4fd64b8e7
5
5
  SHA512:
6
- metadata.gz: 433ad64347ae2b4eb1065d595933e1ecf7e0a4142bb1f1ec0d19e737b38f9b99105a5022abb820788eabf13670bb89a5f3a620381ba0a003898c578f1b842c2b
7
- data.tar.gz: fbe1fd2885a18f881dae520d186a44e72c26328261e965087bee19c06bd06e38d4a42d70647c64519db044ed6314e71c69d08a03856763210fa7f449d520c12d
6
+ metadata.gz: 583b0c19fb5256f8f3b8c5886ef23679815bdbb6fc9f14982968ee47bc6aaec3fe6a8f8223fa232e1659fce855c54a0fba0c1fec3419821bcadbe2c0b7d7f300
7
+ data.tar.gz: c2eff14423272b0432d582d461cdea0085cff59836bca791ee7c55fe91b6e237f4b5ea8f31c91adc80bc57dc72c29978fc0e9ed5c8813e0d77838feaccc1b5b9
@@ -5,19 +5,53 @@ require 'soar_idm/soar_idm'
5
5
 
6
6
  module SoarSc
7
7
 
8
+ ##
9
+ # SOAR Idr Client
10
+ # Simplifies communication with Hetzner identity registries.
11
+ # @example Get roles
12
+ # idr_client = SoarSc::IdrClient.new
13
+ # idr_client.roles_uri = SoarSc::Providers::ServiceRegistry::find_first_service_uri('idr-staff-get-roles')
14
+ # subject_identifier = 'charles.mulder@example.org'
15
+ # roles = idr_client.get_roles(subject_identifier)
16
+ # @example Get all attributes
17
+ # idr_client = SoarSc::IdrClient.new
18
+ # idr_client.attributes_uri = SoarSc::Providers::ServiceRegistry::find_first_service_uri('idr-staff-get-attributes')
19
+ # subject_identifier = 'charles.mulder@example.org'
20
+ # attributes = idr_client.get_attributes(subject_identifier)
21
+ # @example Get attributes filtered by role
22
+ # idr_client = SoarSc::IdrClient.new
23
+ # idr_client.roles_uri = SoarSc::Providers::ServiceRegistry::find_first_service_uri('idr-staff-get-roles')
24
+ # idr_client.attributes_uri = SoarSc::Providers::ServiceRegistry::find_first_service_uri('idr-staff-get-attributes')
25
+ # subject_identifier = 'charles.mulder@example.org'
26
+ # role = 'technical'
27
+ # attributes = idr_client.get_attributes(subject_identifier, role)
8
28
  class IdrClient < SoarIdm::IdmApi
9
29
 
10
30
  class MissingRequiredAttributeError < StandardError; end
11
31
  class CommunicationError < StandardError; end
12
32
  class UnsupportedResponseError < StandardError; end
13
33
 
14
- attr_accessor :roles_uri
15
- attr_accessor :attributes_uri
34
+ # @!attribute [w] roles_uri
35
+ attr_writer :roles_uri
16
36
 
37
+ # @!attribute [w] attributes_uri
38
+ attr_writer :attributes_uri
39
+
40
+ ##
41
+ # Creates an instance of IdrClient
42
+ # @param http optional [Object]
43
+ # @return [Object] instance of IdrClient
17
44
  def initialize(http=Net::HTTP)
18
45
  @http = http
19
46
  end
20
47
 
48
+ ##
49
+ # Get roles
50
+ # @param subject_identifier [String]
51
+ # @raise MissingRequiredAttributeError when missing subject_identifier param
52
+ # @raise UnsupportedResponseError when remote response is not json
53
+ # @raise CommunicationError when network error
54
+ # @return [Array] list of roles
21
55
  def get_roles(subject_identifier)
22
56
  begin
23
57
  super(subject_identifier)
@@ -30,6 +64,14 @@ module SoarSc
30
64
  end
31
65
  end
32
66
 
67
+ ##
68
+ # Get attributes optionally filtered by role
69
+ # @param subject_identifier [String]
70
+ # @param role optional [String]
71
+ # @raise MissingRequiredAttributeError
72
+ # @raise UnsupportedResponseError
73
+ # @raise CommunicationError
74
+ # @return [Hash] dictionary of roles and attributes, optionally filtered by role
33
75
  def get_attributes(subject_identifier, role = nil)
34
76
  begin
35
77
  super(subject_identifier, role)
@@ -42,11 +84,19 @@ module SoarSc
42
84
  end
43
85
  end
44
86
 
87
+ ##
88
+ # Set remote uri used by get_attributes method
89
+ # @param attributes_uri [String]
90
+ # @return [Nil]
45
91
  def attributes_uri=(attributes_uri)
46
92
  raise URI::InvalidURIError if not valid_url?(attributes_uri)
47
93
  @attributes_uri = URI.parse(attributes_uri)
48
94
  end
49
95
 
96
+ ##
97
+ # Set remote uri used by get_roles method
98
+ # @param roles_uri [String]
99
+ # @return [Nil]
50
100
  def roles_uri=(roles_uri)
51
101
  raise URI::InvalidURIError if not valid_url?(roles_uri)
52
102
  @roles_uri = URI.parse(roles_uri)
@@ -54,27 +104,45 @@ module SoarSc
54
104
 
55
105
  private
56
106
 
107
+ ##
108
+ # @param entity_identifier [String]
109
+ # @return [Array]
57
110
  def calculate_identities(entity_identifier)
58
111
  [entity_identifier]
59
112
  end
60
113
 
114
+ ##
115
+ # @param identity [String]
116
+ # @return [Hash] attributes keyed by role
61
117
  def calculate_all_attributes(identity)
62
118
  response = ask_idr(identity, nil, @attributes_uri)
63
119
  response['data']['attributes']
64
120
  end
65
121
 
122
+ ##
123
+ # @param identity [String]
124
+ # @return [Array] list of roles
66
125
  def calculate_roles(identity)
67
126
  raise MissingRequiredAttributeError, 'Missing required roles_uri' if @roles_uri.nil?
68
127
  response = ask_idr(identity, nil, @roles_uri)
69
128
  response['data']['roles']
70
129
  end
71
130
 
72
- def calculate_attributes(identity, role)
131
+ ##
132
+ # @param identity [String]
133
+ # @param role optional [String]
134
+ # @return [Hash] dictionairy of attributes
135
+ def calculate_attributes(identity, role = nil)
73
136
  raise MissingRequiredAttributeError, 'Missing required @attributes_uri attribute' if @attributes_uri.nil?
74
137
  response = ask_idr(identity, role, @attributes_uri)
75
138
  response['data']['attributes'][role]
76
139
  end
77
140
 
141
+ ##
142
+ # @param identifier [String]
143
+ # @param role optional [String]
144
+ # @param url [URI::HTTP, URI::HTTPS]
145
+ # @return [Hash] parsed json response
78
146
  def ask_idr(identifier, role = nil, url)
79
147
  response = @http.start(url.host, url.port) do |http|
80
148
  params = build_params(identifier, role)
@@ -83,12 +151,19 @@ module SoarSc
83
151
  JSON.parse(response.body)
84
152
  end
85
153
 
154
+ ##
155
+ # @param identifier [String]
156
+ # @param role optional [String]
157
+ # @return [String] url query parameters
86
158
  def build_params(identifier, role = nil)
87
159
  params = "?identifier=#{identifier}"
88
160
  params += "&role=#{role}" if not role.nil?
89
161
  params
90
162
  end
91
163
 
164
+ ##
165
+ # @param uri [String]
166
+ # @return [Boolean]
92
167
  def valid_url?(uri)
93
168
  result = uri =~ /\A#{URI::regexp(['http', 'https'])}\z/
94
169
  not result.nil?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: idr_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Mulder
@@ -70,3 +70,4 @@ signing_key:
70
70
  specification_version: 4
71
71
  summary: Identity registry client
72
72
  test_files: []
73
+ has_rdoc: