goodhamgupta / authzed_ex

Unofficial SpiceDB client library for Elixir
Apache License 2.0
11 stars 8 forks source link

Error serializing Consistency struct #1

Closed goodhamgupta closed 2 years ago

goodhamgupta commented 2 years ago

In the file authzed_test.exs, when we add a consistency check using the option:

    {:ok, response} =
      client.permissions_service.check_permission(
        client.channel,
        CheckPermissionRequest.new(
          resource: post_one,
          permission: "view",
          subject: emilia
          consistency: Consistency.new(requirement: :fully_consistent)
        )
      )

we get the following error:

** (Protobuf.EncodeError) Got error when encoding Authzed.Api.V1.CheckPermissionRequest#consistency: ** (Protobuf.EncodeError) Authzed.Api.V1.Consistency#requirement should be {k
ey, val}, got: {:ok, :fully_consistent}
    (protobuf 0.10.0) lib/protobuf/encoder.ex:70: Protobuf.Encoder.encode_fields/5
    (protobuf 0.10.0) lib/protobuf/encoder.ex:32: Protobuf.Encoder.encode_with_message_props/2
    (protobuf 0.10.0) lib/protobuf/encoder.ex:17: Protobuf.Encoder.encode/1
    (grpc 0.3.1) lib/grpc/stub.ex:184: GRPC.Stub.do_call/5
    (stdlib 3.15) erl_eval.erl:685: :erl_eval.do_apply/6
    (iex 1.12.2) lib/iex/evaluator.ex:298: IEx.Evaluator.handle_eval/3
    (iex 1.12.2) lib/iex/evaluator.ex:274: IEx.Evaluator.do_eval/3
    (iex 1.12.2) lib/iex/evaluator.ex:263: IEx.Evaluator.eval/3
    (iex 1.12.2) lib/iex/evaluator.ex:157: IEx.Evaluator.loop/1
    (iex 1.12.2) lib/iex/evaluator.ex:32: IEx.Evaluator.init/4
    test/authzed_test.exs:99: AuthzedTest."test basic operation"/1
    (ex_unit 1.12.2) lib/ex_unit/runner.ex:502: ExUnit.Runner.exec_test/1
    (stdlib 3.15) timer.erl:166: :timer.tc/1
    (ex_unit 1.12.2) lib/ex_unit/runner.ex:453: anonymous fn/4 in ExUnit.Runner.spawn_test_monitor/4

This error occurs irrespective of how we initialize the Consistency. For example

consistency: Consistency.new(requirement: :fully_consistent)
# OR
consistency: [requirement: :fully_consistent]

Due to this error, all consistency modes are currently not supported.

kamilkowalski commented 2 years ago

Hi, I was about to start creating an Authzed library for Elixir and then I saw you just started one - awesome! Have you tried encoding consistency as:

consistency: Consistency.new(requirement: {:fully_consistent, true})

I think it's a quirk with the Elixir gRPC library - oneof fields are encoded by passing a tuple with the oneof field name as the first element, and the value as the second element.

goodhamgupta commented 2 years ago

Hi @kamilkowalski,

Thank you so much for the hint! 😄 I wasn't aware of this feature in elixir gRPC, and struggled to find an answer to this problem.

The tests now work as expected and I've created a PR here: #2 if you would like to confirm the functionality. Thanks! 😄