Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alekcz/google-credentials
A Clojure library for loading gcloud credentials from an environment variable instead of a .json file
https://github.com/alekcz/google-credentials
google google-cloud
Last synced: about 1 month ago
JSON representation
A Clojure library for loading gcloud credentials from an environment variable instead of a .json file
- Host: GitHub
- URL: https://github.com/alekcz/google-credentials
- Owner: alekcz
- License: epl-2.0
- Created: 2020-01-29T20:37:14.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-15T11:09:10.000Z (over 4 years ago)
- Last Synced: 2024-11-08T16:03:14.627Z (about 2 months ago)
- Topics: google, google-cloud
- Language: Clojure
- Homepage:
- Size: 43.9 KB
- Stars: 5
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# google-credentials
A Clojure library for loading gcloud credentials from an environment variable instead of a .json file.
![Build Status](https://github.com/alekcz/google-credentials/workflows/Clojure%20CI/badge.svg) [![codecov](https://codecov.io/gh/alekcz/google-credentials/branch/master/graph/badge.svg)](https://codecov.io/gh/alekcz/google-credentials)
[![Clojars Project](https://img.shields.io/clojars/v/alekcz/googlecredentials.svg)](https://clojars.org/alekcz/googlecredentials)
## Background
When interoping with the Google SDK the initialization process is more or less as follows:
1. Load credentials from file
2. Initialize credentials
3. Initialize the SDK by passing the credentials to it.
4. Access resource in the Google cloudThis library allows the credentials to be loaded from the environment variable: `GOOGLE_APPLICATION_CREDENTIALS`.
You can also load the credentials from a custom environment variable.
I've found this really useful when deploying applications or running CI/CD outside the Google cloud.You still need to perform steps 2 - 4 to get up and running.
## Usage
**Current:** `[alekcz/googlecredentials "3.0.1"]`_Deprecated: `[alekcz/google-credentials "x.x.x"]`_
_(The dash in the package name creates problems)_1. Get the `json` file containing your service account creditials by following the instruction here [https://cloud.google.com/docs/authentication/getting-started](https://cloud.google.com/docs/authentication/getting-started)
2. Copy the contents of your `.json` into the GOOGLE_APPLICATION_CREDENTIALS environment variable. In your `~/.bash_profile` and in Travis CI you should escape your credentials using singe quotes (`'`).```clojure
(require '[googlecredentials.core :as g-cred]);; By default load from GOOGLE_APPLICATION_CREDENTIALS
(-> (. StorageOptions newBuilder)
(.setCredentials (g-cred/load-service-credentials))
(.build)
(.getService));; Load from custom environment variable
(def firebase-options (-> (new FirebaseOptions$Builder)
(.setCredentials (g-cred/load-service-credentials :firebase-config))
(.build))
(.initializeApp FirebaseApp firebase-options);; Load from custom environment variable as string
(def firebase-options (-> (new FirebaseOptions$Builder)
(.setCredentials (g-cred/load-service-credentials "FIREBASE_CONFIG"))
(.build))
(.initializeApp FirebaseApp firebase-options);; generic example
(def cred (-> ()
(.setCredentials (g-cred/load-service-credentials))
(.build))
(/ cred)```
## License
Copyright © 2020 Alexander Oloo
This program and the accompanying materials are made available under the
terms of the Eclipse Public License 2.0 which is available at
http://www.eclipse.org/legal/epl-2.0.This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the Eclipse
Public License, v. 2.0 are satisfied: GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or (at your
option) any later version, with the GNU Classpath Exception which is available
at https://www.gnu.org/software/classpath/license.html.