unimatrix 2.0.1 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac3e057fab9840a39e41aaa924e6e1bde765ee6d
4
- data.tar.gz: e57ba7fa907551238c1d2fcfad752a30c8625daf
3
+ metadata.gz: f4f4323a1f537678c555b94d89a1510b3f33671d
4
+ data.tar.gz: f4a72ea3b407efefadc1dd99fcdc7b4fe5571e60
5
5
  SHA512:
6
- metadata.gz: 0e2011da9335656280d64a976e11244acb01b535192e58d7617db57a854f098ab06e52cf9b7d7d439011e1d4decfc5f6cd0afda319d6ed775e48627ea54b9cd0
7
- data.tar.gz: 1f39f4a77817b6a5cd8486007da18eebabc5ddbcf32349ac60afe0d9e3b2188120211ed3d2dbac88fd409768e7ff70c1057649e9aa8cb0090dd5642f4b4d7ea1
6
+ metadata.gz: c7d689ee1395611effd21805efd1181b6b157cc4fe619edec2fdec430cbc98ad5284046ffdc23520deed359be33f5fe8133941f8c72fa49a5c19593cd9d042fb
7
+ data.tar.gz: 6973f28c2a590822aaaa263d7a2cddbc5f629aca6125e3a33e542285e5e4af4bbe94680a1e6203e74b7b1438c9d75b8463c5922b3793f3bb6638dff25c602f7a
data/lib/unimatrix.rb CHANGED
@@ -60,6 +60,10 @@ require 'unimatrix/archivist/blueprint_attribute'
60
60
  require 'unimatrix/archivist/component'
61
61
 
62
62
  # authorization
63
+ require 'unimatrix/authorization/operation'
64
+ require 'unimatrix/authorization/parser'
65
+ require 'unimatrix/authorization/request'
66
+ require 'unimatrix/authorization/response'
63
67
  require 'unimatrix/authorization/filters/requires_policies' if defined?( Rails )
64
68
  require 'unimatrix/authorization/railtie' if defined?( Rails )
65
69
  require 'unimatrix/authorization/client_credentials_grant'
@@ -102,11 +102,10 @@ module Unimatrix::Authorization
102
102
  def request_policies( resource_name, access_token, realm_uuid, resource_server )
103
103
  if resource_name && access_token
104
104
  realm_uuid = realm_uuid || '*'
105
-
106
- Unimatrix::Operation.new( '/policies' ).where(
105
+ Operation.new( '/policies' ).where(
107
106
  access_token: access_token,
108
107
  resource: "realm/#{ realm_uuid }::#{ resource_server }::#{ resource_name }/*"
109
- ).query
108
+ ).read
110
109
  end
111
110
  end
112
111
 
@@ -0,0 +1,61 @@
1
+ module Unimatrix::Authorization
2
+ class Operation < Unimatrix::Operation
3
+
4
+ def destroy
5
+ result = nil
6
+ Request.new.tap do | request |
7
+ response = request.destroy( @path, @parameters )
8
+ if response.present?
9
+ result = response.resources
10
+ end
11
+ end
12
+ result
13
+ end
14
+
15
+ def read( &block )
16
+ result = nil
17
+ response = nil
18
+ Request.new.tap do | request |
19
+ request.get( @path, @parameters ).tap do | response |
20
+ result = response.resources
21
+ if block_given?
22
+ case block.arity
23
+ when 0; yield
24
+ when 1; yield result
25
+ when 2; yield result, response
26
+ end
27
+ end
28
+ end
29
+ end
30
+ result
31
+ end
32
+
33
+ def write( node, objects, &block )
34
+ result = nil
35
+ Request.new.tap do | request |
36
+ serializer = Unimatrix::Serializer.new( objects )
37
+ response = request.post( @path, @parameters, serializer.serialize( node ) )
38
+ if response.present?
39
+ result = response.resources
40
+ if block_given?
41
+ case block.arity
42
+ when 0; yield
43
+ when 1; yield result
44
+ when 2; yield result, response
45
+ end
46
+ end
47
+ end
48
+ end
49
+ result
50
+ end
51
+
52
+ protected; def spawn( parameters )
53
+ Operation.new(
54
+ @path,
55
+ @parameters.deep_merge( parameters || {} )
56
+ )
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -0,0 +1,49 @@
1
+ module Unimatrix::Authorization
2
+
3
+ class Parser
4
+
5
+ def initialize( content = {} )
6
+ @content = content
7
+ yield self if block_given?
8
+ end
9
+
10
+ def name
11
+ @content.keys.present? ? @content.keys.first : nil
12
+ end
13
+
14
+ def type_name
15
+ self.name.present? ? name.singularize : nil
16
+ end
17
+
18
+ def resources
19
+ result = nil
20
+
21
+ unless self.name.blank?
22
+ if @content[ 'error' ]
23
+ result = parse_resource( name, @content )
24
+ else
25
+ result = @content[ name ].map do | attributes |
26
+ self.parse_resource( name, attributes )
27
+ end
28
+ end
29
+ end
30
+ result
31
+ end
32
+
33
+ def parse_resource( name, attributes )
34
+ resource = nil
35
+
36
+ if attributes.present?
37
+ class_name = name.singularize.camelize
38
+ object_class = Unimatrix::Authorization.const_get( class_name ) rescue nil
39
+
40
+ if object_class.present?
41
+ resource = object_class.new( attributes )
42
+ end
43
+ end
44
+ resource
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,50 @@
1
+ require 'net/http'
2
+ require 'addressable/uri'
3
+
4
+ module Unimatrix::Authorization
5
+ class Request < Unimatrix::Request
6
+
7
+ def initialize( default_parameters = {} )
8
+ uri = URI( Unimatrix.configuration.authorization_url )
9
+ @http = Net::HTTP.new( uri.host, uri.port )
10
+
11
+ @http.use_ssl = ( uri.scheme == 'https' )
12
+ @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
13
+
14
+ @default_parameters = default_parameters.stringify_keys
15
+ end
16
+
17
+ def get( path, parameters = {} )
18
+ response = nil
19
+
20
+ begin
21
+ response = Response.new(
22
+ @http.get( compose_request_path( path, parameters ) )
23
+ )
24
+ rescue Timeout::Error
25
+ response = nil
26
+ end
27
+
28
+ response
29
+ end
30
+
31
+ def post( path, parameters = {}, body = {} )
32
+ response = nil
33
+
34
+ begin
35
+ request = Net::HTTP::Post.new(
36
+ compose_request_path( path, parameters ),
37
+ { 'Content-Type' =>'application/json' }
38
+ )
39
+ request.body = body.to_json
40
+
41
+ response = Response.new( @http.request( request ) )
42
+ rescue Timeout::Error
43
+ response = nil
44
+ end
45
+
46
+ response
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,30 @@
1
+ module Unimatrix::Authorization
2
+
3
+ class Response < Unimatrix::Response
4
+
5
+ attr_reader :code
6
+ attr_reader :body
7
+ attr_reader :resources
8
+
9
+ def initialize( http_response )
10
+ @success = http_response.is_a?( Net::HTTPOK )
11
+ @code = http_response.code
12
+ @resources = []
13
+ @body = decode_response_body( http_response )
14
+
15
+ if ( @body && @body.respond_to?( :keys ) )
16
+ Parser.new( @body ) do | parser |
17
+ @resources = parser.resources
18
+ @success = !( parser.type_name == 'error' )
19
+ end
20
+ else
21
+ @success = false
22
+ @resources << Error.new(
23
+ message: "#{ @code }: #{ http_response.message }."
24
+ )
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -1,3 +1,3 @@
1
1
  module Unimatrix
2
- VERSION = "2.0.1"
2
+ VERSION = "2.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unimatrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jackson Souza
@@ -116,11 +116,15 @@ files:
116
116
  - lib/unimatrix/attribute_error.rb
117
117
  - lib/unimatrix/authorization/client_credentials_grant.rb
118
118
  - lib/unimatrix/authorization/filters/requires_policies.rb
119
+ - lib/unimatrix/authorization/operation.rb
120
+ - lib/unimatrix/authorization/parser.rb
119
121
  - lib/unimatrix/authorization/policy.rb
120
122
  - lib/unimatrix/authorization/railtie.rb
123
+ - lib/unimatrix/authorization/request.rb
121
124
  - lib/unimatrix/authorization/resource.rb
122
125
  - lib/unimatrix/authorization/resource_owner.rb
123
126
  - lib/unimatrix/authorization/resource_server.rb
127
+ - lib/unimatrix/authorization/response.rb
124
128
  - lib/unimatrix/bad_request_error.rb
125
129
  - lib/unimatrix/configuration.rb
126
130
  - lib/unimatrix/curator/activity_reference.rb
@@ -182,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
186
  version: '0'
183
187
  requirements: []
184
188
  rubyforge_project:
185
- rubygems_version: 2.4.8
189
+ rubygems_version: 2.5.2
186
190
  signing_key:
187
191
  specification_version: 4
188
192
  summary: Unimatrix is used to communicate with Unimatrix APIs.