Skip to content

Commit

Permalink
Pass options through to GRPC.Stub.connect (#25)
Browse files Browse the repository at this point in the history
* Pass options through to GRPC.Stub.connect

* fix compilation error setting default value for multiple fn heads

* bump up a patch version
  • Loading branch information
pwcsquared authored Jun 19, 2024
1 parent 67e5f98 commit 340b8e9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
29 changes: 21 additions & 8 deletions lib/api/v1/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,36 @@ defmodule Authzed.Api.V1.Client do

defstruct @keys

def new(endpoint, auth_header) when is_list(auth_header) do
{:ok, channel} = GRPC.Stub.connect(endpoint, headers: auth_header)
@doc """
Establishes a gRPC connection with the Authzed service.
## Options:
https://hexdocs.pm/grpc/GRPC.Stub.html#connect/2-options
"""
def new(endpoint, auth_header_or_ssl_cred, opts \\ [])

def new(endpoint, auth_header, opts) when is_list(auth_header) do
grpc_opts = Keyword.merge(opts, headers: auth_header)
{:ok, channel} = GRPC.Stub.connect(endpoint, grpc_opts)
%__MODULE__{channel: channel}
end

def new(endpoint, ssl_cred) do
{:ok, channel} = GRPC.Stub.connect(endpoint, cred: ssl_cred)
def new(endpoint, ssl_cred, opts) do
grpc_opts = Keyword.merge(opts, cred: ssl_cred)
{:ok, channel} = GRPC.Stub.connect(endpoint, grpc_opts)
%__MODULE__{channel: channel}
end

def new(host, port, auth_header) when is_list(auth_header) do
{:ok, channel} = GRPC.Stub.connect(host, port, headers: auth_header)
def new(host, port, auth_header, opts) when is_list(auth_header) do
grpc_opts = Keyword.merge(opts, headers: auth_header)
{:ok, channel} = GRPC.Stub.connect(host, port, grpc_opts)
%__MODULE__{channel: channel}
end

def new(host, port, ssl_cred) do
{:ok, channel} = GRPC.Stub.connect(host, port, cred: ssl_cred)
def new(host, port, ssl_cred, opts) do
grpc_opts = Keyword.merge(opts, cred: ssl_cred)
{:ok, channel} = GRPC.Stub.connect(host, port, grpc_opts)
%__MODULE__{channel: channel}
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Authzed.MixProject do
use Mix.Project

@version "0.0.11"
@version "0.0.12"
@repo_url "https://github.com/goodhamgupta/authzed_ex/"

def project do
Expand Down

0 comments on commit 340b8e9

Please sign in to comment.