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 ability to pull/push under different goth service accounts. #55

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

noizu
Copy link

@noizu noizu commented Sep 30, 2022

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
Copy link
Author

noizu commented Nov 23, 2022

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