* feat: GCP authentication
Add authentication support for:
- authentication with service account key
- authentication with impersonating service account key
- authentication with application default credentials which are read from the environment
A HTTP client with a token set will be returned and used for authentication with all clients. for example
```
gcpClient, err := gcpConfig.GetClient(ctx)
if err != nil {
log.Fatalf("Failed to get client: %v", err)
}
client, err := computeCloud.NewInstancesRESTClient(ctx, option.WithHTTPClient(gcpClient))
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
```
31 lines
795 B
Go
31 lines
795 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package credential
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type CredentialType int
|
|
|
|
// PersistedState is the persisted state for the GCP credential.
|
|
type PersistedState struct {
|
|
// CredentialsConfig is the credential configuration for the GCP credential.
|
|
CredentialsConfig *Config
|
|
// CredsLastRotatedTime is the last rotation of service account key for the GCP credential.
|
|
CredsLastRotatedTime time.Time
|
|
}
|
|
|
|
// NewPersistedState - create a new PersistedState
|
|
func NewPersistedState(opt ...Option) (*PersistedState, error) {
|
|
s := new(PersistedState)
|
|
opts, err := getOpts(opt...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
s.CredentialsConfig = opts.WithCredentialsConfig
|
|
s.CredsLastRotatedTime = opts.WithCredsLastRotatedTime
|
|
return s, nil
|
|
}
|