Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
as part of fixing elixir-mongo#273
  • Loading branch information
jethro-solve authored and Austin Lanari committed Sep 9, 2019
1 parent 43c0ca2 commit 48fe208
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
51 changes: 37 additions & 14 deletions lib/mongo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -541,26 +541,49 @@ defmodule Mongo do

@doc false
def raw_find(conn, coll, query, select, opts) do
params = [query, select]
query = %Query{action: :find, extra: coll}
query = filter_nils([
find: coll,
filter: query,
projection: select,
batchSize: opts[:batch_size],
skip: opts[:skip],
])

opts = Keyword.drop(opts, [:skip, :batch_size])

with {:ok, %{"cursor" => %{"id" => id, "firstBatch" => docs}}} <-
direct_command(conn, query, opts) do
{:ok, %{from: 0, num: Enum.count(docs), cursor_id: id, docs: docs}}
end

with {:ok, _query, reply} <- DBConnection.execute(conn, query, params, defaults(opts)),
:ok <- maybe_failure(reply),
op_reply(docs: docs, cursor_id: cursor_id, from: from, num: num) = reply,
do: {:ok, %{from: from, num: num, cursor_id: cursor_id, docs: docs}}
# params = [query, select]
# query = %Query{action: :find, extra: coll}
# with {:ok, reply} <- DBConnection.execute(conn, query, params, defaults(opts)),
# :ok <- maybe_failure(reply),
# op_reply(docs: docs, cursor_id: cursor_id, from: from, num: num) = reply,
# do: {:ok, %{from: from, num: num, cursor_id: cursor_id, docs: docs}}
end

@doc false
def get_more(conn, coll, cursor, opts) do
query =
filter_nils(
getMore: cursor,
collection: coll,
batchSize: Keyword.get(opts, :batch_size),
maxTimeMS: Keyword.get(opts, :max_time_ms)
)
query = filter_nils([
getMore: cursor,
collection: coll,
batchSize: opts[:batch_size],
])

opts = Keyword.drop(opts, [:batch_size])

with {:ok, %{"cursor" => %{"id" => id, "nextBatch" => docs}}} <-
direct_command(conn, query, opts) do
{:ok, %{from: 0, num: Enum.count(docs), cursor_id: id, docs: docs}}
end

direct_command(conn, query, opts)
# query = %Query{action: :get_more, extra: {coll, cursor}}
# with {:ok, reply} <- DBConnection.execute(conn, query, [], defaults(opts)),
# :ok <- maybe_failure(reply),
# op_reply(docs: docs, cursor_id: cursor_id, from: from, num: num) = reply,
# do: {:ok, %{from: from, num: num, cursor_id: cursor_id, docs: docs}}
end

@doc false
Expand Down
10 changes: 5 additions & 5 deletions lib/mongo/auth/scram.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ defmodule Mongo.Auth.SCRAM do
end

defp first(
%{"conversationId" => 1, "payload" => server_payload, "done" => false},
%{"conversationId" => conversation_id, "payload" => server_payload, "done" => false},
first_bare,
username,
password,
Expand All @@ -54,18 +54,18 @@ defmodule Mongo.Auth.SCRAM do
server_signature = generate_signature(salted_password, auth_message)
proof = generate_proof(salted_password, auth_message)
client_final_message = %BSON.Binary{binary: "#{client_message},#{proof}"}
message = [saslContinue: 1, conversationId: 1, payload: client_final_message]
message = [saslContinue: 1, conversationId: conversation_id, payload: client_final_message]

{message, server_signature}
end

defp second(%{"conversationId" => 1, "payload" => payload, "done" => false}, signature) do
defp second(%{"conversationId" => conversation_id, "payload" => payload}, signature) do
params = parse_payload(payload)
^signature = Base.decode64!(params["v"])
[saslContinue: 1, conversationId: 1, payload: %BSON.Binary{binary: ""}]
[saslContinue: 1, conversationId: conversation_id, payload: %BSON.Binary{binary: ""}]
end

defp final(%{"conversationId" => 1, "payload" => %BSON.Binary{binary: ""}, "done" => true}) do
defp final(%{"conversationId" => _, "payload" => %BSON.Binary{binary: ""}, "done" => true}) do
:ok
end

Expand Down

0 comments on commit 48fe208

Please sign in to comment.