auth.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. Copyright © 2025 ESO Maintainer Team
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. https://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. // Package dvls implements the external-secrets provider for Devolutions Server (DVLS).
  14. package dvls
  15. import (
  16. "context"
  17. "fmt"
  18. "github.com/Devolutions/go-dvls"
  19. kclient "sigs.k8s.io/controller-runtime/pkg/client"
  20. esv1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
  21. "github.com/external-secrets/external-secrets/runtime/esutils/resolvers"
  22. )
  23. // NewDVLSClient creates a new authenticated DVLS client.
  24. func NewDVLSClient(ctx context.Context, kube kclient.Client, storeKind, namespace string, provider *esv1.DVLSProvider) (credentialClient, error) {
  25. if provider == nil {
  26. return nil, fmt.Errorf("missing provider configuration")
  27. }
  28. appID, err := resolvers.SecretKeyRef(ctx, kube, storeKind, namespace, &provider.Auth.SecretRef.AppID)
  29. if err != nil {
  30. return nil, fmt.Errorf("failed to get appId: %w", err)
  31. }
  32. appSecret, err := resolvers.SecretKeyRef(ctx, kube, storeKind, namespace, &provider.Auth.SecretRef.AppSecret)
  33. if err != nil {
  34. return nil, fmt.Errorf("failed to get appSecret: %w", err)
  35. }
  36. client, err := dvls.NewClient(appID, appSecret, provider.ServerURL)
  37. if err != nil {
  38. return nil, fmt.Errorf("failed to create DVLS client: %w", err)
  39. }
  40. return &realCredentialClient{cred: client.Entries.Credential}, nil
  41. }