Skip to content

Add ability to pull/push under different goth service accounts.#55

Open
noizu wants to merge 4 commits into
peburrows:masterfrom
noizu-forks:master
Open

Add ability to pull/push under different goth service accounts.#55
noizu wants to merge 4 commits into
peburrows:masterfrom
noizu-forks:master

Conversation

@noizu

@noizu noizu commented Sep 30, 2022

Copy link
Copy Markdown

I have a requirement on this functionality for synchronizing my stage/dev environments with the production data sets. It may also be useful if you have a restricted auth account by default but sometimes need to use an elevated account to make certain requests.

The feature works by pushing a value to the current process dictionary and referencing that value when preparing request tokens or determining the current project_id.

If the functionality is not referenced I've constructed the Goth calls to use the previous format (rather than just setting account to :default and using the {account, field} version of methods.) to avoid impacting any upstream users if they, for example, have overridden the module used by defp token_module() and their implementation does not support the for_scope({account, scope}) format.

The Readme has been updated with an example of how to use this feature:

require Diplomat
# copy data from prod to stage environment
# 1. Fetch data from production account
prod_data = Diplomat.with_account(alternative_account["client_email"]) do
  Diplomat.Query.new(
    "select * from `Book` where name = @name",
    %{name: "20,000 Leagues Under The Sea"}
  ) |> Diplomat.Query.execute
end
# 2. Write to stage/dev account (default environment)
Enum.map(prod_data, fn(entity) -> 
  Diplomat.Entity.upsert(entity)
end)

@noizu

noizu commented Nov 23, 2022

Copy link
Copy Markdown
Author

o_O

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant