Class: Cerbos::Input::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/cerbos/input/resource.rb

Overview

A resource on which to check a principal's permissions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind:, id:, attr: {}, attributes: nil, policy_version: nil, scope: nil) ⇒ Resource

Specify a resource on which to check a principal's permissions.

Parameters:

  • kind (String)

    the type of resource.

  • id (String)

    a unique identifier for the resource.

  • attr (Attributes, Hash) (defaults to: {})

    application-specific attributes describing the resource.

  • attributes (Attributes, Hash) (defaults to: nil)

    deprecated (use attr instead).

  • policy_version (String, nil) (defaults to: nil)

    the policy version to use when checking the principal's permissions on the resource (nil to use the Cerbos policy decision point server's configured default version).

  • scope (String, nil) (defaults to: nil)

    the policy scope to use when checking the principal's permissions on the resource.



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cerbos/input/resource.rb', line 44

def initialize(kind:, id:, attr: {}, attributes: nil, policy_version: nil, scope: nil)
  unless attributes.nil?
    Cerbos.deprecation_warning "The `attributes` keyword argument is deprecated. Use `attr` instead."
    attr = attributes
  end

  @kind = kind
  @id = id
  @attr = Input.coerce_required(attr, Attributes)
  @policy_version = policy_version
  @scope = scope
end

Instance Attribute Details

#attrAttributes (readonly)

Application-specific attributes describing the resource.

Returns:



20
21
22
# File 'lib/cerbos/input/resource.rb', line 20

def attr
  @attr
end

#idString (readonly)

A unique identifier for the resource.

Returns:

  • (String)


15
16
17
# File 'lib/cerbos/input/resource.rb', line 15

def id
  @id
end

#kindString (readonly)

The type of resource.

Returns:

  • (String)


10
11
12
# File 'lib/cerbos/input/resource.rb', line 10

def kind
  @kind
end

#policy_versionString? (readonly)

The policy version to use when checking the principal's permissions on the resource.

Returns:

  • (String)
  • (nil)

    if not provided (in which case the Cerbos policy decision point server's configured default version will be used).



26
27
28
# File 'lib/cerbos/input/resource.rb', line 26

def policy_version
  @policy_version
end

#scopeString? (readonly)

The policy scope to use when checking the principal's permissions on the resource.

Returns:

  • (String)
  • (nil)

    if not provided.

See Also:



34
35
36
# File 'lib/cerbos/input/resource.rb', line 34

def scope
  @scope
end

Instance Method Details

#attributesAttributes

Deprecated.

Use #attr instead.

Application-specific attributes describing the resource.

Returns:



61
62
63
64
# File 'lib/cerbos/input/resource.rb', line 61

def attributes
  Cerbos.deprecation_warning "The `attributes` method is deprecated. Use `attr` instead."
  attr
end