validation.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 awsutil provides utility functions for AWS provider integration
  14. package awsutil
  15. import (
  16. "fmt"
  17. awssm "github.com/aws/aws-sdk-go-v2/service/secretsmanager"
  18. )
  19. const (
  20. errInvalidDeleteSecretInput = "invalid DeleteSecretInput: %s"
  21. )
  22. // ValidateDeleteSecretInput validates the DeleteSecretInput.
  23. // The AWS sdk v2 does not validate the input before making the API call, leaving it to the API to return the error.
  24. // This function allows one to validate the input before any such call is made.
  25. // See: https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/secretsmanager#DeleteSecretInput
  26. func ValidateDeleteSecretInput(input awssm.DeleteSecretInput) error {
  27. // Validate range for RecoveryWindowInDays
  28. // See: https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/secretsmanager#DeleteSecretInput
  29. if input.RecoveryWindowInDays != nil && *input.RecoveryWindowInDays != 0 && (*input.RecoveryWindowInDays < 7 || *input.RecoveryWindowInDays > 30) {
  30. return fmt.Errorf(errInvalidDeleteSecretInput, "RecoveryWindowInDays must be between 7 and 30 days")
  31. }
  32. // Validate that ForceDeleteWithoutRecovery is not set when RecoveryWindowInDays is set
  33. if input.RecoveryWindowInDays != nil && *input.RecoveryWindowInDays != 0 && input.ForceDeleteWithoutRecovery != nil && *input.ForceDeleteWithoutRecovery {
  34. return fmt.Errorf(errInvalidDeleteSecretInput, "ForceDeleteWithoutRecovery conflicts with RecoveryWindowInDays")
  35. }
  36. return nil
  37. }