diff --git a/lib/aserto/directory/v3/reader.rb b/lib/aserto/directory/v3/reader.rb index 74a68fb..6da6cbe 100644 --- a/lib/aserto/directory/v3/reader.rb +++ b/lib/aserto/directory/v3/reader.rb @@ -223,6 +223,43 @@ def check_permission(object_type:, object_id:, permission:, subject_type:, subje ) ) end + + # + # Returns object graph from anchor to subject or object. + # + # @param [String] anchor_type + # @param [String] anchor_id + # @param [String] object_type + # @param [String] object_id + # @param [String] relation + # @param [String] subject_type + # @param [String] + # + # @return [Aserto::Directory::Reader::V3::GetGraphResponse] + # + # @example + # directory.get_graph( + # anchor_type: "user", + # anchor_id: "rick@the-citadel.com", + # subject_id: "rick@the-citadel.com", + # subject_type: "user", + # relation: "member" + # ) + def get_graph(anchor_type:, anchor_id:, object_type: "", object_id: "", relation: "", subject_type: "", + subject_id: "", subject_relation: "") + reader.get_graph( + Aserto::Directory::Reader::V3::GetGraphRequest.new( + anchor_type: anchor_type, + anchor_id: anchor_id, + object_type: object_type, + object_id: object_id, + relation: relation, + subject_type: subject_type, + subject_id: subject_id, + subject_relation: subject_relation + ) + ) + end end end end diff --git a/spec/integration/directory_spec.rb b/spec/integration/directory_spec.rb index e791c8f..90034fd 100644 --- a/spec/integration/directory_spec.rb +++ b/spec/integration/directory_spec.rb @@ -85,6 +85,28 @@ end.not_to raise_error end + it "reads the graph between user and group" do + expect(directory.get_graph( + anchor_type: "user", + anchor_id: "my-user", + subject_id: "my-user", + subject_type: "user", + relation: "member" + ).results.map(&:to_h)).to eq( + [ + { depth: 1, + is_cycle: false, + object_id: "my-group", + object_type: "group", + path: ["group:my-group|member|user:my-user#"], + relation: "member", + subject_id: "my-user", + subject_relation: "", + subject_type: "user" } + ] + ) + end + it "reads a relation between user and group" do expect(directory.get_relation( subject_id: "my-user",