Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for AWS DocumentDB #304

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions lib/mongo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -541,26 +541,36 @@ defmodule Mongo do

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

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}}
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
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])

direct_command(conn, query, opts)
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
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