Skip to content
A Clojure library for loading gcloud credentials from an environment variable instead of a .json file
Clojure
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows
doc
src/google_credentials
test/google_credentials
.gitignore
CHANGELOG.md
LICENSE
README.md
project.clj

README.md

google-credentials

A Clojure library for loading gcloud credentials from an environment variable instead of a .json file.

Build Status codecov

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 pass the credentials to it.
  4. Access resource in the Google cloud

This library allows the credentials to be loaded from the environment variable: GOOGLE_APPLICATION_CREDENTIALS. 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

[alekcz/google-credentials "0.2.1"]

  1. Get the json file containing your service account creditials by following the instruction here 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.
(require '[google-credentials.core :as g-cred])

    ;; Cloud Storage
    (-> (. StorageOptions newBuilder)
        (.setCredentials (g-cred/load-credentials)) 
        (.build) 
        (.getService))

    ;; Firebase
    (def firebase-options   (-> (new FirebaseOptions$Builder) 
                                (.setCredentials (g-cred/load-credentials)) 
                                (.build))   
    (.initializeApp FirebaseApp firebase-options)   

     ;; generic example
    (def cred   (-> (<options-builder>)
                    (.setCredentials (g-cred/load-credentials)) 
                    (.build))  
    (<cloud-library>/<initialisation-function> 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.

You can’t perform that action at this time.