Class: Chain::AuthorizationGrant::ClientModule
- Inherits:
-
ClientModule
- Object
- ClientModule
- Chain::AuthorizationGrant::ClientModule
- Defined in:
- lib/chain/authorization_grant.rb
Constant Summary collapse
- SUBJECT_ATTRIBUTES =
{ 'C' => {array: true}, 'O' => {array: true}, 'OU' => {array: true}, 'L' => {array: true}, 'ST' => {array: true}, 'STREET' => {array: true}, 'POSTALCODE' => {array: true}, 'SERIALNUMBER' => {array: false}, 'CN' => {array: false}, }
Instance Attribute Summary
Attributes inherited from ClientModule
Class Method Summary collapse
Instance Method Summary collapse
-
#create(opts) ⇒ AuthorizationGrant
Create an authorization grant, which provides the specified credential with access to the given policy.
-
#delete(opts) ⇒ void
Delete the specified authorization grant.
-
#list_all ⇒ Array<AuthorizationGrant>
List all authorization grants.
Methods inherited from ClientModule
Constructor Details
This class inherits a constructor from Chain::ClientModule
Class Method Details
.sanitize_x509(guard_data) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/chain/authorization_grant.rb', line 112 def self.sanitize_x509(guard_data) first_key = guard_data.keys.first if guard_data.size != 1 || first_key.to_s.downcase != 'subject' raise ArgumentError.new('Guard data must contain exactly one key, "subject"') end res = {} res[first_key] = guard_data.values.first.reduce({}) do |memo, (k, v)| attrib = SUBJECT_ATTRIBUTES[k.to_s.upcase] raise ArgumentError.new("Invalid subject attrib: #{k}") unless attrib if attrib[:array] && !v.is_a?(Array) memo[k] = [v] elsif !attrib[:array] && v.is_a?(Array) raise ArgumentError.new("Invalid array value for #{k}: #{v}") else memo[k] = v end memo end res end |
Instance Method Details
#create(opts) ⇒ AuthorizationGrant
Create an authorization grant, which provides the specified credential with access to the given policy. Credentials are identified using predicates called guards. Guards identify credentials by type and by patterns specific to that type.
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/chain/authorization_grant.rb', line 72 def create(opts) # Copy input and stringify keys opts = opts.reduce({}) do |memo, (k, v)| memo[k.to_s] = v memo end if opts['guard_type'].to_s == 'x509' opts['guard_data'] = self.class.sanitize_x509(opts['guard_data']) end AuthorizationGrant.new(client.conn.request('create-authorization-grant', opts)) end |
#delete(opts) ⇒ void
This method returns an undefined value.
Delete the specified authorization grant.
95 96 97 98 |
# File 'lib/chain/authorization_grant.rb', line 95 def delete(opts) client.conn.request('delete-authorization-grant', opts) nil end |
#list_all ⇒ Array<AuthorizationGrant>
List all authorization grants. The sort order is not defined.
88 89 90 |
# File 'lib/chain/authorization_grant.rb', line 88 def list_all client.conn.request('list-authorization-grants')['items'].map { |item| AuthorizationGrant.new(item) } end |