Skip to content

Commit

Permalink
Merge pull request #6 from LampardNguyen234/dev/init-without-credentials
Browse files Browse the repository at this point in the history
chore(gcp): allow to init server without a credential file
  • Loading branch information
LampardNguyen234 authored Jul 17, 2023
2 parents 2cffe8e + fb223b1 commit 500d8ce
Show file tree
Hide file tree
Showing 4 changed files with 1,165 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gcpkms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ KMS key in GCP. To do this, please follow the instruction [here](https://cloud.g
Remember to choose `Purpose = Asymmetric sign` and `Algorithm = Elliptic Curve secp256k1 - SHA256 Digest` in the
`Create key` screen.

### Download Credential
### Download Credential (Optional)
Head over [the `IAM` page of the GCP](https://cloud.google.com/iam/docs/service-accounts), create a service account to use to API and download the credential.
The credential file looks like the following:
```json
Expand Down
4 changes: 0 additions & 4 deletions gcpkms/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ func (cfg Config) IsValid() (bool, error) {
return false, fmt.Errorf("empty LocationID")
}

if cfg.CredentialLocation == "" {
return false, fmt.Errorf("empty CredentialLocation")
}

if !cfg.Key.isValid() {
return false, fmt.Errorf("invalid Key")
}
Expand Down
6 changes: 5 additions & 1 deletion gcpkms/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ func NewGoogleKMSClient(ctx context.Context, cfg Config, txSigner ...types.Signe
if _, err := cfg.IsValid(); err != nil {
return nil, fmt.Errorf("invalid config")
}
client, err := kms.NewKeyManagementClient(ctx, option.WithCredentialsFile(cfg.CredentialLocation))
options := make([]option.ClientOption, 0)
if cfg.CredentialLocation != "" {
options = append(options, option.WithCredentialsFile(cfg.CredentialLocation))
}
client, err := kms.NewKeyManagementClient(ctx, options...)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 500d8ce

Please # to comment.