/
hooks.go
64 lines (56 loc) · 1.98 KB
/
hooks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
package certificate
import (
"errors"
"fmt"
"github.com/aws-controllers-k8s/acm-controller/pkg/tags"
)
const (
// DNS validation only works for up to 5 chained CNAME records
limitDomainValidationOptionsPublic = 5
)
var (
errTooManyDomainValidationOptions = errors.New(
"Too many domain validation errors",
)
domainValidationOptionsExceededMsg = fmt.Sprintf(
"Certificate cannot have more than %d domain validation options "+
"when requesting a public certificate",
limitDomainValidationOptionsPublic,
)
)
// validatePublicValidationOptions checks that when requesting a public
// certificate, we do not exceed the number of additional CNAME records that
// DNS verification can handle.
func validatePublicValidationOptions(
r *resource,
) error {
// If the certificateAuthorityARN field is empty, that means this is a
// request for a public certificate. If so, because we require DNS
// verification for public certificates (due to email verification not be
// automateable), we need to limit the number of chained CNAME records in
// the DomainValidationOptions field to 5, since DNS verification only
// works on up to 5 subdomains.
if r.ko.Spec.CertificateAuthorityARN != nil {
numDVOptions := len(r.ko.Spec.DomainValidationOptions)
if numDVOptions > limitDomainValidationOptionsPublic {
return errTooManyDomainValidationOptions
}
}
return nil
}
var (
syncTags = tags.SyncTags
listTags = tags.ListTags
)