Class: SelfSDK::Services::Facts::Delegation

Inherits:
Object
  • Object
show all
Defined in:
lib/services/facts.rb

Constant Summary collapse

TYPE =
'delegation_certificate'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subjects, actions, effect, resources, opts = {}) ⇒ Delegation

Returns a new instance of Delegation.



156
157
158
159
160
161
162
163
# File 'lib/services/facts.rb', line 156

def initialize(subjects, actions, effect, resources, opts = {})
  @subjects = subjects
  @actions = actions
  @effect = effect
  @resources = resources
  @conditions = opts.fetch(:conditions, nil)
  @description = opts.fetch(:description, nil)
end

Instance Attribute Details

#actionsObject

Returns the value of attribute actions.



154
155
156
# File 'lib/services/facts.rb', line 154

def actions
  @actions
end

#conditionsObject

Returns the value of attribute conditions.



154
155
156
# File 'lib/services/facts.rb', line 154

def conditions
  @conditions
end

#descriptionObject

Returns the value of attribute description.



154
155
156
# File 'lib/services/facts.rb', line 154

def description
  @description
end

#effectObject

Returns the value of attribute effect.



154
155
156
# File 'lib/services/facts.rb', line 154

def effect
  @effect
end

#resourcesObject

Returns the value of attribute resources.



154
155
156
# File 'lib/services/facts.rb', line 154

def resources
  @resources
end

#subjectsObject

Returns the value of attribute subjects.



154
155
156
# File 'lib/services/facts.rb', line 154

def subjects
  @subjects
end

Class Method Details

.parse(input) ⇒ Object



176
177
178
179
180
181
182
183
184
185
# File 'lib/services/facts.rb', line 176

def self.parse(input)
  b = JSON.parse(Base64.urlsafe_decode64(input))
  Delegation.new(
    b['subjects'],
    b['actions'],
    b['effect'],
    b['resources'],
    conditions: b['conditions'],
    description: b['description'])
end

Instance Method Details

#encodeObject



165
166
167
168
169
170
171
172
173
174
# File 'lib/services/facts.rb', line 165

def encode
  cert = {
    subjects: @subjects,
    actions: @actions,
    effect: @effect,
    resources: @resources,
  }.to_json

  Base64.urlsafe_encode64(cert, padding: false)
end