validation.go 1.9 KB

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