createKMSClient creates a HuaweiCloud KMS client with the appropriate credentials and region configuration.
(ctx context.Context)
| 261 | // createKMSClient creates a HuaweiCloud KMS client with the appropriate credentials |
| 262 | // and region configuration. |
| 263 | func (key *MasterKey) createKMSClient(ctx context.Context) (*huaweikms.KmsClient, error) { |
| 264 | var cred auth.ICredential |
| 265 | var err error |
| 266 | |
| 267 | if key.credentials != nil { |
| 268 | cred = key.credentials |
| 269 | } else { |
| 270 | // Use default credential provider chain (env -> profile -> metadata) |
| 271 | credentialProviderChain := provider.BasicCredentialProviderChain() |
| 272 | cred, err = credentialProviderChain.GetCredentials() |
| 273 | if err != nil { |
| 274 | return nil, fmt.Errorf("failed to get HuaweiCloud credentials: %w", err) |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | // Get KMS region with endpoint |
| 279 | reg, err := kmsregion.SafeValueOf(key.Region) |
| 280 | if err != nil { |
| 281 | return nil, fmt.Errorf("invalid region %q: %w", key.Region, err) |
| 282 | } |
| 283 | |
| 284 | // Create HTTP client builder |
| 285 | hcClientBuilder := core.NewHcHttpClientBuilder(). |
| 286 | WithCredential(cred). |
| 287 | WithRegion(reg) |
| 288 | |
| 289 | hcClient := hcClientBuilder.Build() |
| 290 | |
| 291 | // Create KMS client |
| 292 | kmsClient := huaweikms.NewKmsClient(hcClient) |
| 293 | return kmsClient, nil |
| 294 | } |
no outgoing calls
no test coverage detected