validation.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. package util
  13. import (
  14. "fmt"
  15. awssm "github.com/aws/aws-sdk-go/service/secretsmanager"
  16. )
  17. const (
  18. errInvalidDeleteSecretInput = "invalid DeleteSecretInput: %s"
  19. )
  20. // ValidateDeleteSecretInput validates the DeleteSecretInput.
  21. // The AWS sdk v2 does not validate the input before making the API call, leaving it to the API to return the error.
  22. // This function allows one to validate the input before any such call is made.
  23. // See: https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/secretsmanager#DeleteSecretInput
  24. func ValidateDeleteSecretInput(input awssm.DeleteSecretInput) error {
  25. // Validate range for RecoveryWindowInDays
  26. // See: https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/secretsmanager#DeleteSecretInput
  27. if input.RecoveryWindowInDays != nil && *input.RecoveryWindowInDays != 0 && (*input.RecoveryWindowInDays < 7 || *input.RecoveryWindowInDays > 30) {
  28. return fmt.Errorf(errInvalidDeleteSecretInput, "RecoveryWindowInDays must be between 7 and 30 days")
  29. }
  30. // Validate that ForceDeleteWithoutRecovery is not set when RecoveryWindowInDays is set
  31. if input.RecoveryWindowInDays != nil && *input.RecoveryWindowInDays != 0 && input.ForceDeleteWithoutRecovery != nil && *input.ForceDeleteWithoutRecovery {
  32. return fmt.Errorf(errInvalidDeleteSecretInput, "ForceDeleteWithoutRecovery conflicts with RecoveryWindowInDays")
  33. }
  34. return nil
  35. }