Skip to content

Commit

Permalink
Apply review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aleDsz committed May 26, 2022
1 parent 732bcf8 commit f156057
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 30 deletions.
31 changes: 13 additions & 18 deletions lib/kino_db/connection_cell.ex
Original file line number Diff line number Diff line change
Expand Up @@ -133,32 +133,27 @@ defmodule KinoDB.ConnectionCell do
end
end

# TODO: Support :refresh_token and :metadata for Goth source type
# See: https://github.com/peburrows/goth/blob/e62ca4afddfabdb3d599c3594fee02c49a2350e4/lib/goth/token.ex#L159-L172
defp to_quoted(%{"type" => "bigquery"} = attrs) do
goth_source_type =
if type = attrs["credentials"]["type"],
do: String.to_atom(type),
else: :service_account

quote do
scopes = ["https://www.googleapis.com/auth/cloud-platform"]

credentials = unquote(Macro.escape(attrs["credentials"]))

goth_opts = [
name: Goth,
http_client: &Req.request/1,
source: {unquote(goth_source_type), credentials, scopes: scopes}
]

opts = [
goth: Goth,
project_id: unquote(attrs["project_id"]),
default_dataset_id: unquote(attrs["default_dataset_id"])
name: ReqBigQuery.Goth,
http_client: &Req.request/1,
source: {:service_account, credentials, []}
]

unquote(quoted_var(attrs["variable"])) = ReqBigQuery.attach(Req.new(), opts)
unquote(quoted_var(attrs["variable"])) =
Req.new(http_errors: :raise)
|> ReqBigQuery.attach(
goth: ReqBigQuery.Goth,
project_id: unquote(attrs["project_id"]),
default_dataset_id: unquote(attrs["default_dataset_id"])
)

{:ok, _goth_pid} = Kino.start_child({Goth, goth_opts})
{:ok, _goth_pid} = Kino.start_child({Goth, opts})
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/kino_db/sql_cell.ex
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ defmodule KinoDB.SQLCell do

req_opts =
if opts == [],
do: [[bigquery: bigquery]],
else: [Keyword.put(Enum.at(opts, 0), :bigquery, bigquery)]
do: [bigquery: bigquery],
else: Keyword.put(Enum.at(opts, 0), :bigquery, bigquery)

quote do
unquote(quoted_var(attrs["result_variable"])) =
Req.post!(
unquote(quoted_var(attrs["connection"]["variable"])),
unquote_splicing(req_opts)
unquote(req_opts)
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule KinoDB.MixProject do
{:exqlite, "~> 0.11", optional: true},
{:myxql, "~> 0.6.2 or ~> 0.7", optional: true},
{:db_connection, "~> 2.4.2", optional: true},
{:req_bigquery, git: "[email protected]:livebook-dev/req_bigquery.git", optional: true},
{:req_bigquery, github: "livebook-dev/req_bigquery", optional: true},
{:ex_doc, "~> 0.28", only: :dev, runtime: false}
]
end
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"nimble_pool": {:hex, :nimble_pool, "0.2.6", "91f2f4c357da4c4a0a548286c84a3a28004f68f05609b4534526871a22053cde", [:mix], [], "hexpm", "1c715055095d3f2705c4e236c18b618420a35490da94149ff8b580a2144f653f"},
"postgrex": {:hex, :postgrex, "0.16.3", "fac79a81a9a234b11c44235a4494d8565303fa4b9147acf57e48978a074971db", [:mix], [{:connection, "~> 1.1", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "aeaae1d2d1322da4e5fe90d241b0a564ce03a3add09d7270fb85362166194590"},
"req": {:git, "https://github.com/wojtekmach/req.git", "e91967962e03ec22d6a691de993840ae9ddb9c47", []},
"req_bigquery": {:git, "git@github.com:livebook-dev/req_bigquery.git", "ea0d7e996d0d7102d6794e0bfd561ab22aefbfc9", []},
"req_bigquery": {:git, "https://github.com/livebook-dev/req_bigquery.git", "ea0d7e996d0d7102d6794e0bfd561ab22aefbfc9", []},
"table": {:hex, :table, "0.1.1", "e8d3c75bb14b8dac227e17d85a626e695d96c271569e94e4a2d15494a7cb0b49", [:mix], [], "hexpm", "6a73280b2f5ad70474594feeb8c034ad490b97dbd5adaeb678f71c250cbc928c"},
"telemetry": {:hex, :telemetry, "1.1.0", "a589817034a27eab11144ad24d5c0f9fab1f58173274b1e9bae7074af9cbee51", [:rebar3], [], "hexpm", "b727b2a1f75614774cff2d7565b64d0dfa5bd52ba517f16543e6fc7efcc0df48"},
}
15 changes: 8 additions & 7 deletions test/kino_db/connection_cell_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,19 @@ defmodule KinoDB.ConnectionCellTest do

assert source ==
"""
scopes = ["https://www.googleapis.com/auth/cloud-platform"]
credentials = %{}
goth_opts = [
name: Goth,
opts = [
name: ReqBigQuery.Goth,
http_client: &Req.request/1,
source: {:service_account, credentials, scopes: scopes}
source: {:service_account, credentials, []}
]
opts = [goth: Goth, project_id: "", default_dataset_id: ""]
db = ReqBigQuery.attach(Req.new(), opts)
{:ok, _goth_pid} = Kino.start_child({Goth, goth_opts})\
db =
Req.new(http_errors: :raise)
|> ReqBigQuery.attach(goth: ReqBigQuery.Goth, project_id: "", default_dataset_id: "")
{:ok, _goth_pid} = Kino.start_child({Goth, opts})\
"""
end
end
Expand Down

0 comments on commit f156057

Please sign in to comment.