Skip to content

Commit

Permalink
improvements suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
helderjs committed Jan 15, 2024
1 parent fae5c8c commit 025ef96
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 5 additions & 1 deletion pkg/api/v1/atlasdatabaseuser_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,13 @@ func (p AtlasDatabaseUser) ToAtlasSDK(ctx context.Context, kubeClient client.Cli

result := admin.NewCloudDatabaseUserWithDefaults()
err = compat.JSONCopy(result, p.Spec)
if err != nil {
return nil, err
}

result.Password = &password

return result, err
return result, nil
}

func (p AtlasDatabaseUser) GetScopes(scopeType ScopeType) []string {
Expand Down
13 changes: 8 additions & 5 deletions pkg/controller/atlas/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,21 @@ func (p *ProductionProvider) SdkClient(ctx context.Context, secretRef *client.Ob
//}

c, err := NewClient(p.domain, secretData.PublicKey, secretData.PrivateKey)
if err != nil {
return nil, "", err
}

return c, secretData.OrgID, err
return c, secretData.OrgID, nil
}

func getSecrets(ctx context.Context, k8sClient client.Client, secretRef, fallbackRef *client.ObjectKey) (credentialsSecret, error) {
func getSecrets(ctx context.Context, k8sClient client.Client, secretRef, fallbackRef *client.ObjectKey) (*credentialsSecret, error) {
if secretRef == nil {
secretRef = fallbackRef
}

secret := &corev1.Secret{}
if err := k8sClient.Get(ctx, *secretRef, secret); err != nil {
return credentialsSecret{}, fmt.Errorf("failed to read Atlas API credentials from the secret %s: %w", secretRef.String(), err)
return nil, fmt.Errorf("failed to read Atlas API credentials from the secret %s: %w", secretRef.String(), err)
}

secretData := credentialsSecret{
Expand All @@ -141,10 +144,10 @@ func getSecrets(ctx context.Context, k8sClient client.Client, secretRef, fallbac
}

if missingFields, valid := validateSecretData(&secretData); !valid {
return credentialsSecret{}, fmt.Errorf("the following fields are missing in the secret %v: %v", secretRef, missingFields)
return nil, fmt.Errorf("the following fields are missing in the secret %v: %v", secretRef, missingFields)
}

return secretData, nil
return &secretData, nil
}

func validateSecretData(secretData *credentialsSecret) ([]string, bool) {
Expand Down
2 changes: 1 addition & 1 deletion test/int/integration_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ var _ = SynchronizedBeforeSuite(func() []byte {
err = e.Encode(*cfg)
Expect(err).ToNot(HaveOccurred())

fmt.Printf("Api Server is listening on %s\n", cfg.Host)
GinkgoWriter.Printf("Api Server is listening on %s\n", cfg.Host)
})

return b.Bytes()
Expand Down

0 comments on commit 025ef96

Please sign in to comment.