Class: Conjur::Policy::Executor::CreateRecord

Inherits:
Create show all
Includes:
Annotate
Defined in:
lib/conjur/policy/executor/create.rb

Overview

Generic ‘create’ implementation which POSTs to a resources URL.

Direct Known Subclasses

CreateHostFactory, CreateVariable

Instance Attribute Summary

Attributes inherited from Base

#actions, #statement

Instance Method Summary collapse

Methods included from Annotate

#annotate, #update_annotation_path

Methods inherited from Create

#record

Methods inherited from Base

#action, #initialize, #resource_path, #role_path

Methods included from Logger

included

Constructor Details

This class inherits a constructor from Conjur::Policy::Executor::Base

Instance Method Details

#annotate_recordObject



22
23
24
# File 'lib/conjur/policy/executor/create.rb', line 22

def annotate_record
  record
end

#create_parametersObject

Each record is assumed to have an ‘id’ attribute required for creation. In addition, other create parameters can be specified by the custom_attribute_names method on the record.



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/conjur/policy/executor/create.rb', line 37

def create_parameters
  {
    record.id_attribute => record.id
  }.tap do |params|
    custom_attrs = record.custom_attribute_names.inject({}) do |memo, attr|
      value = record.send(attr)
      memo[attr.to_s] = value if value
      memo
    end
    params.merge! custom_attrs
    params["ownerid"] = record.owner.roleid if record.owner
  end
end

#create_pathObject



26
27
28
# File 'lib/conjur/policy/executor/create.rb', line 26

def create_path
  [ kind_path ].join('/')
end

#executeObject



13
14
15
16
17
18
19
20
# File 'lib/conjur/policy/executor/create.rb', line 13

def execute
  action({
    'method' => 'post',
    'path' => create_path,
    'parameters' => create_parameters
  })
  annotate
end

#kind_pathObject



30
31
32
# File 'lib/conjur/policy/executor/create.rb', line 30

def kind_path
  record.resource_kind.pluralize
end