GithubHelp home page GithubHelp logo

Comments (2)

Carrotman42 avatar Carrotman42 commented on July 21, 2024

There's an easy way (which is simple, inflexible, and potentially not generic) and a hard way (which is flexible but of course requires more code).

Easy way: Set GOOGLE_APPLICATION_CREDENTIALS to the path of the JSON file pointing to your credentials; when you call mysql.Dial some underlying code (https://godoc.org/golang.org/x/oauth2/google) will inspect this environment variable during the call to google.DefaultClient

Hard way: all of the code for doing this is contained in this repository. Unfortunately, it's spread across it pretty evenly :)

  1. You must construct an http.Client which attaches the service account's authentication to requests sent to our API backend.

    This repo uses goauth.JWTConfigFromJSON [0]; see this for an example: https://github.com/GoogleCloudPlatform/cloudsql-proxy/blob/703c832fe568afe4a7ec21e09f14812eb543b72a/cmd/cloud_sql_proxy/cloud_sql_proxy.go#L207

    [0] https://godoc.org/golang.org/x/oauth2/google#JWTConfigFromJSON

  2. Pass this http.Client to proxy.Init: https://godoc.org/github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/proxy#Init

  3. Call mysql.Dial just like in the easy way

from cloud-sql-proxy.

digiexchris avatar digiexchris commented on July 21, 2024

Thanks, that's exactly what I needed. I started with the dialer_test and fleshed it out a bit to figure it out for myself, I made a pull request in case it's useful for others too.

#83

from cloud-sql-proxy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.