fix dodgy pointers
This commit is contained in:
parent
3f6230470b
commit
9b121e85f9
|
@ -70,19 +70,19 @@ func (ots OauthTokenSource) Token() (*oauth2.Token, error) {
|
|||
|
||||
}
|
||||
|
||||
func NewClientGCE(account *ServiceAccount, vaultOauth string, impersonatedsa string) (*option.ClientOption, error) {
|
||||
func NewClientGCE(account *ServiceAccount, vaultOauth string, impersonatedsa string) (option.ClientOption, error) {
|
||||
var err error
|
||||
|
||||
var opts *option.ClientOption
|
||||
var opts option.ClientOption
|
||||
|
||||
if vaultOauth != "" {
|
||||
// Auth with Vault Oauth
|
||||
log.Printf("Using Vault to generate Oauth token.")
|
||||
ts := OauthTokenSource{vaultOauth}
|
||||
*opts = option.WithTokenSource(ts)
|
||||
opts = option.WithTokenSource(ts)
|
||||
|
||||
} else if impersonatedsa != "" {
|
||||
*opts = option.ImpersonateCredentials(impersonatedsa)
|
||||
opts = option.ImpersonateCredentials(impersonatedsa)
|
||||
} else if account.jwt != nil && len(account.jwt.PrivateKey) > 0 {
|
||||
// Auth with AccountFile if provided
|
||||
log.Printf("[INFO] Requesting Google token via account_file...")
|
||||
|
@ -90,14 +90,14 @@ func NewClientGCE(account *ServiceAccount, vaultOauth string, impersonatedsa str
|
|||
log.Printf("[INFO] -- Scopes: %s", DriverScopes)
|
||||
log.Printf("[INFO] -- Private Key Length: %d", len(account.jwt.PrivateKey))
|
||||
|
||||
*opts = option.WithCredentialsJSON(account.jsonKey)
|
||||
opts = option.WithCredentialsJSON(account.jsonKey)
|
||||
} else {
|
||||
log.Printf("[INFO] Requesting Google token via GCE API Default Client Token Source...")
|
||||
ts, err := google.DefaultTokenSource(context.TODO(), "https://www.googleapis.com/auth/cloud-platform")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
*opts = option.WithTokenSource(ts)
|
||||
opts = option.WithTokenSource(ts)
|
||||
// The DefaultClient uses the DefaultTokenSource of the google lib.
|
||||
// The DefaultTokenSource uses the "Application Default Credentials"
|
||||
// It looks for credentials in the following places, preferring the first location found:
|
||||
|
@ -126,13 +126,13 @@ func NewDriverGCE(ui packer.Ui, p string, account *ServiceAccount, impersonateds
|
|||
}
|
||||
|
||||
log.Printf("[INFO] Instantiating GCE client...")
|
||||
service, err := compute.NewService(context.TODO(), *opts)
|
||||
service, err := compute.NewService(context.TODO(), opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Printf("[INFO] Instantiating OS Login client...")
|
||||
osLoginService, err := oslogin.NewService(context.TODO(), *opts)
|
||||
osLoginService, err := oslogin.NewService(context.TODO(), opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -138,7 +138,7 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact
|
|||
}
|
||||
p.config.ctx.Data = generatedData
|
||||
var err error
|
||||
var opts *option.ClientOption
|
||||
var opts option.ClientOption
|
||||
opts, err = googlecompute.NewClientGCE(p.config.account, p.config.VaultGCPOauthEngine, p.config.ImpersonatedServiceAccount)
|
||||
if err != nil {
|
||||
return nil, false, false, err
|
||||
|
@ -179,8 +179,8 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact
|
|||
return gceImageArtifact, false, false, nil
|
||||
}
|
||||
|
||||
func UploadToBucket(opts *option.ClientOption, ui packer.Ui, artifact packer.Artifact, bucket string, gcsObjectName string) (string, error) {
|
||||
service, err := storage.NewService(context.TODO(), *opts)
|
||||
func UploadToBucket(opts option.ClientOption, ui packer.Ui, artifact packer.Artifact, bucket string, gcsObjectName string) (string, error) {
|
||||
service, err := storage.NewService(context.TODO(), opts)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -215,9 +215,8 @@ func UploadToBucket(opts *option.ClientOption, ui packer.Ui, artifact packer.Art
|
|||
return storageObject.SelfLink, nil
|
||||
}
|
||||
|
||||
|
||||
func CreateGceImage(opts *option.ClientOption, ui packer.Ui, project string, rawImageURL string, imageName string, imageDescription string, imageFamily string, imageLabels map[string]string, imageGuestOsFeatures []string) (packer.Artifact, error) {
|
||||
service, err := compute.NewService(context.TODO(), *opts)
|
||||
func CreateGceImage(opts option.ClientOption, ui packer.Ui, project string, rawImageURL string, imageName string, imageDescription string, imageFamily string, imageLabels map[string]string, imageGuestOsFeatures []string) (packer.Artifact, error) {
|
||||
service, err := compute.NewService(context.TODO(), opts)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -271,9 +270,8 @@ func CreateGceImage(opts *option.ClientOption, ui packer.Ui, project string, raw
|
|||
return &Artifact{paths: []string{op.TargetLink}}, nil
|
||||
}
|
||||
|
||||
|
||||
func DeleteFromBucket(opts *option.ClientOption, ui packer.Ui, bucket string, gcsObjectName string) error {
|
||||
service, err := storage.NewService(context.TODO(), *opts)
|
||||
func DeleteFromBucket(opts option.ClientOption, ui packer.Ui, bucket string, gcsObjectName string) error {
|
||||
service, err := storage.NewService(context.TODO(), opts)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue