Exception: Parse::Agent::AccessDenied

Inherits:
AgentError
  • Object
show all
Defined in:
lib/parse/agent/errors.rb

Overview

Raised by agent tools when a request targets a Parse class that has been marked ‘agent_hidden` (see Parse::Agent::MetadataDSL). The rescue path in Parse::Agent#execute translates this to a `:access_denied` error_response without leaking the class name to the wire beyond the sanitized message the caller used.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_name = nil, message = nil, kind: nil, denied_field: nil, allowed_fields: nil, suggested_rewrite: nil) ⇒ AccessDenied

Returns a new instance of AccessDenied.

Parameters:

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

    the Parse class being refused. May be nil when the denial is not class-scoped (e.g., an env-gate refusal triggered by a ‘call_method` invocation of a :write method).

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

    optional override for the message. When not provided, a default “Class ‘X’ is not accessible to this agent” message is used.

  • kind (Symbol, nil) (defaults to: nil)

    a finer-grained denial subcode. Lets MCP consumers branch on the specific refusal reason without parsing prose. Known values:

    :hidden_class            — target class is `agent_hidden`
    :field_denied            — projection/sort/match/expr field is
                               outside the class's `agent_fields`
                               allowlist
    :storage_form_field_ref  — same as :field_denied but the
                               offending name is the Parse-on-Mongo
                               storage column (`_p_*`); the rewrite
                               hint points at the bare pointer name
    
  • denied_field (String, nil) (defaults to: nil)

    the offending column / field name when the refusal is field-scoped. Nil for class-scoped denials.

  • allowed_fields (Array<String>, nil) (defaults to: nil)

    the class’s effective ‘agent_fields` allowlist (capped for wire compactness). Nil when the refusal is not field-scoped.

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

    a one-shot rewrite suggestion the caller can apply to fix the request. Currently emitted for storage-form references (e.g., “use ‘$author` instead of `$_p_author`”).



68
69
70
71
72
73
74
75
76
77
# File 'lib/parse/agent/errors.rb', line 68

def initialize(class_name = nil, message = nil,
               kind: nil, denied_field: nil, allowed_fields: nil,
               suggested_rewrite: nil)
  @class_name        = class_name.to_s
  @kind              = kind
  @denied_field      = denied_field
  @allowed_fields    = allowed_fields&.map(&:to_s)
  @suggested_rewrite = suggested_rewrite
  super(message || "Class '#{@class_name}' is not accessible to this agent")
end

Instance Attribute Details

#allowed_fieldsObject (readonly)

Returns the value of attribute allowed_fields.



41
42
43
# File 'lib/parse/agent/errors.rb', line 41

def allowed_fields
  @allowed_fields
end

#class_nameObject (readonly)

Returns the value of attribute class_name.



41
42
43
# File 'lib/parse/agent/errors.rb', line 41

def class_name
  @class_name
end

#denied_fieldObject (readonly)

Returns the value of attribute denied_field.



41
42
43
# File 'lib/parse/agent/errors.rb', line 41

def denied_field
  @denied_field
end

#kindObject (readonly)

Returns the value of attribute kind.



41
42
43
# File 'lib/parse/agent/errors.rb', line 41

def kind
  @kind
end

#suggested_rewriteObject (readonly)

Returns the value of attribute suggested_rewrite.



41
42
43
# File 'lib/parse/agent/errors.rb', line 41

def suggested_rewrite
  @suggested_rewrite
end

Instance Method Details

#to_detailsObject

Structured details for the error_response payload. Returns a Hash with only the populated keys so the wire envelope doesn’t carry unused nil fields.



82
83
84
85
86
87
88
89
# File 'lib/parse/agent/errors.rb', line 82

def to_details
  {
    kind:              kind,
    denied_field:      denied_field,
    allowed_fields:    allowed_fields,
    suggested_rewrite: suggested_rewrite,
  }.compact
end