idr_client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/idr_client.rb +98 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f20475104672ed1c698969b86285488f338c00f1
|
4
|
+
data.tar.gz: 319f90522a9faf84c0943625e5c377957e5b5d04
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 433ad64347ae2b4eb1065d595933e1ecf7e0a4142bb1f1ec0d19e737b38f9b99105a5022abb820788eabf13670bb89a5f3a620381ba0a003898c578f1b842c2b
|
7
|
+
data.tar.gz: fbe1fd2885a18f881dae520d186a44e72c26328261e965087bee19c06bd06e38d4a42d70647c64519db044ed6314e71c69d08a03856763210fa7f449d520c12d
|
data/lib/idr_client.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'json'
|
3
|
+
require 'net/http'
|
4
|
+
require 'soar_idm/soar_idm'
|
5
|
+
|
6
|
+
module SoarSc
|
7
|
+
|
8
|
+
class IdrClient < SoarIdm::IdmApi
|
9
|
+
|
10
|
+
class MissingRequiredAttributeError < StandardError; end
|
11
|
+
class CommunicationError < StandardError; end
|
12
|
+
class UnsupportedResponseError < StandardError; end
|
13
|
+
|
14
|
+
attr_accessor :roles_uri
|
15
|
+
attr_accessor :attributes_uri
|
16
|
+
|
17
|
+
def initialize(http=Net::HTTP)
|
18
|
+
@http = http
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_roles(subject_identifier)
|
22
|
+
begin
|
23
|
+
super(subject_identifier)
|
24
|
+
rescue MissingRequiredAttributeError => error
|
25
|
+
raise error
|
26
|
+
rescue JSON::ParserError => error
|
27
|
+
raise UnsupportedResponseError, error.message
|
28
|
+
rescue StandardError => error
|
29
|
+
raise CommunicationError, error.message
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_attributes(subject_identifier, role = nil)
|
34
|
+
begin
|
35
|
+
super(subject_identifier, role)
|
36
|
+
rescue MissingRequiredAttributeError => error
|
37
|
+
raise error
|
38
|
+
rescue JSON::ParserError => error
|
39
|
+
raise UnsupportedResponseError, error.message
|
40
|
+
rescue StandardError => error
|
41
|
+
raise CommunicationError, error.message
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def attributes_uri=(attributes_uri)
|
46
|
+
raise URI::InvalidURIError if not valid_url?(attributes_uri)
|
47
|
+
@attributes_uri = URI.parse(attributes_uri)
|
48
|
+
end
|
49
|
+
|
50
|
+
def roles_uri=(roles_uri)
|
51
|
+
raise URI::InvalidURIError if not valid_url?(roles_uri)
|
52
|
+
@roles_uri = URI.parse(roles_uri)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def calculate_identities(entity_identifier)
|
58
|
+
[entity_identifier]
|
59
|
+
end
|
60
|
+
|
61
|
+
def calculate_all_attributes(identity)
|
62
|
+
response = ask_idr(identity, nil, @attributes_uri)
|
63
|
+
response['data']['attributes']
|
64
|
+
end
|
65
|
+
|
66
|
+
def calculate_roles(identity)
|
67
|
+
raise MissingRequiredAttributeError, 'Missing required roles_uri' if @roles_uri.nil?
|
68
|
+
response = ask_idr(identity, nil, @roles_uri)
|
69
|
+
response['data']['roles']
|
70
|
+
end
|
71
|
+
|
72
|
+
def calculate_attributes(identity, role)
|
73
|
+
raise MissingRequiredAttributeError, 'Missing required @attributes_uri attribute' if @attributes_uri.nil?
|
74
|
+
response = ask_idr(identity, role, @attributes_uri)
|
75
|
+
response['data']['attributes'][role]
|
76
|
+
end
|
77
|
+
|
78
|
+
def ask_idr(identifier, role = nil, url)
|
79
|
+
response = @http.start(url.host, url.port) do |http|
|
80
|
+
params = build_params(identifier, role)
|
81
|
+
http.get(url.path + params)
|
82
|
+
end
|
83
|
+
JSON.parse(response.body)
|
84
|
+
end
|
85
|
+
|
86
|
+
def build_params(identifier, role = nil)
|
87
|
+
params = "?identifier=#{identifier}"
|
88
|
+
params += "&role=#{role}" if not role.nil?
|
89
|
+
params
|
90
|
+
end
|
91
|
+
|
92
|
+
def valid_url?(uri)
|
93
|
+
result = uri =~ /\A#{URI::regexp(['http', 'https'])}\z/
|
94
|
+
not result.nil?
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: idr_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Charles Mulder
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: soar_idm
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.3'
|
41
|
+
description: Ruby client for communicating with Hetzner identity registries
|
42
|
+
email: charles.mulder@hetzner.co.za
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/idr_client.rb
|
48
|
+
homepage: http://rubygems.org/gems/hola
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata: {}
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 2.4.6
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: Identity registry client
|
72
|
+
test_files: []
|