Skip to content

Commit

Permalink
add get_graph
Browse files Browse the repository at this point in the history
  • Loading branch information
gimmyxd committed Nov 27, 2023
1 parent 4cf9751 commit 6bdf180
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/aserto/directory/v3/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <description>
# @param [String] anchor_id <description>
# @param [String] object_type <description>
# @param [String] object_id <description>
# @param [String] relation <description>
# @param [String] subject_type <description>
# @param [String] <description>
#
# @return [Aserto::Directory::Reader::V3::GetGraphResponse]
#
# @example
# directory.get_graph(
# anchor_type: "user",
# anchor_id: "[email protected]",
# subject_id: "[email protected]",
# 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
Expand Down
22 changes: 22 additions & 0 deletions spec/integration/directory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 6bdf180

Please sign in to comment.