| 1 |
// Copyright 2018 The Go Cloud Development Kit Authors |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
// Package cloudsql contains Wire providers that are common across Google Cloud |
| 16 |
// SQL. |
| 17 |
package cloudsql // import "gocloud.dev/gcp/cloudsql" |
| 18 |
|
| 19 |
import ( |
| 20 |
"github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/certs" |
| 21 |
"github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/proxy" |
| 22 |
"github.com/google/wire" |
| 23 |
"gocloud.dev/gcp" |
| 24 |
"golang.org/x/oauth2" |
| 25 |
) |
| 26 |
|
| 27 |
// CertSourceSet is a Wire provider set that binds a Cloud SQL proxy |
| 28 |
// certificate source from an GCP-authenticated HTTP client. |
| 29 |
var CertSourceSet = wire.NewSet( |
| 30 |
NewCertSource, |
| 31 |
wire.Bind(new(proxy.CertSource), new(*certs.RemoteCertSource))) |
| 32 |
|
| 33 |
// NewCertSource creates a local certificate source that uses the given |
| 34 |
// HTTP client. The client is assumed to make authenticated requests. |
| 35 |
func NewCertSource(c *gcp.HTTPClient) *certs.RemoteCertSource { |
| 36 |
return certs.NewCertSourceOpts(&c.Client, certs.RemoteOpts{}) |
| 37 |
} |
| 38 |
|
| 39 |
// NewCertSourceWithIAM creates a local certificate source, including Token source for token information used in |
| 40 |
// cert creation, that uses the given HTTP client. The client is assumed to make authenticated requests. |
| 41 |
func NewCertSourceWithIAM(c *gcp.HTTPClient, t oauth2.TokenSource) *certs.RemoteCertSource { |
| 42 |
return certs.NewCertSourceOpts(&c.Client, certs.RemoteOpts{EnableIAMLogin: true, TokenSource: t}) |
| 43 |
} |