Module: Aserto::Directory::V3::Importer

Included in:
Client
Defined in:
lib/aserto/directory/v3/importer.rb

Instance Method Summary collapse

Instance Method Details

#import(data) ⇒ Object

Imports objects and relations

op_code =

OPCODE_UNKNOWN                                              = ;
OPCODE_SET                                                  = 1;
OPCODE_DELETE                                               = 2;

Examples:

directory.import(
  [
    { op_code: 1, object: { type: "user", id: "import-user" } },
    { op_code: 1, object: { type: "group", id: "import-group" } },
    {
      op_code: 1,
      relation: {
        object_type: "user",
        object_id: "import-user",
        relation: "member",
        subject_id: "import-group",
        subject_type: "group"
      }
    }
  ]
)

Parameters:

  • Array (Hash)

    data to be imported



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/aserto/directory/v3/importer.rb', line 34

def import(data)
  data.map! do |value|
    if value.dig(:object, :properties)
      require "google/protobuf/well_known_types"

      value[:object][:properties] = Google::Protobuf::Struct.from_hash(
        value[:object][:properties].transform_keys(&:to_s)
      )
    end

    Aserto::Directory::Importer::V3::ImportRequest.new(value)
  end
  operation = importer.import(data, return_op: true)
  response = operation.execute
  response.each { |r| } # ensures that the server sends trailing data
  operation.wait
end