https://github.com/xingxing/gotham
GCP authentication
https://github.com/xingxing/gotham
elixir gcp
Last synced: 4 months ago
JSON representation
GCP authentication
- Host: GitHub
- URL: https://github.com/xingxing/gotham
- Owner: xingxing
- License: apache-2.0
- Created: 2019-06-18T08:00:00.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-08-02T03:24:12.000Z (almost 4 years ago)
- Last Synced: 2025-10-21T17:51:11.426Z (8 months ago)
- Topics: elixir, gcp
- Language: Elixir
- Homepage: https://hex.pm/packages/gotham
- Size: 35.2 KB
- Stars: 3
- Watchers: 0
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://circleci.com/gh/xingxing/gotham/tree/master)
# Gotham
*Support multiple GCP service account*
Google + Auth + Batman = Gotham
[](https://user-images.githubusercontent.com/120734/60244733-9a01ef80-98ed-11e9-91cd-54e0b864f82f.png)
## Installation
1. Add Gotham to you mix.exs
```elixir
def deps do
[
{:gotham, "~> 0.1.0"}
]
end
```
2. Configure service accounts
```elixir
config :gotham,
default_account: :account1,
accounts: [
{:account1, file_path: "path/to/google/json/creds.json"},
{:account2, file_path: "path/to/google/json/creds.json"}
{:account3, env_var: "GOOGLE_APPLICATION_CREDENTIALS"},
{:account4, content: """
{
"type": "service_account",
"project_id": "fake_project",
"private_key_id": "46900d88664ebba4eb08f745b365254e2b0625ab",
...
}
"""
}
```
## Usage
```elixir
# Use default account
{:ok, token} = Gotham.for_scope("https://www.googleapis.com/auth/pubsub")
%Gotham.Token{
project_id: "test",
access_token: "TOKEN",
account_name: :account1,
expire_at: 1561090622,
scope: "https://www.googleapis.com/auth/pubsub",
token_type: "Bearer"
}
# Change acocunt
Gotham.put_account_name(:account2)
Gotham.for_scope("https://www.googleapis.com/auth/pubsub")
{:ok,
%Gotham.Token{
project_id: "test",
access_token: "TOKEN",
account_name: :account2,
expire_at: 1561092261,
scope: "https://www.googleapis.com/auth/pubsub",
token_type: "Bearer"
}}
# Run a function with a specific account
Gotham.with_account_name(:account2, fn ->
Gotham.for_scope("https://www.googleapis.com/auth/pubsub")
end)
{:ok,
%Gotham.Token{
project_id: "test",
access_token: "TOKEN",
account_name: :account2,
expire_at: 1561092261,
scope: "https://www.googleapis.com/auth/pubsub",
token_type: "Bearer"
}}
```