Skip to content

Commit

Permalink
adding dynamic route53 action setting, returning error if a bad actio…
Browse files Browse the repository at this point in the history
…n is passed, and checking for raised error
  • Loading branch information
c-e-brumm committed Oct 22, 2019
1 parent fec7f00 commit 29fb90f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
17 changes: 13 additions & 4 deletions pkg/awsclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,18 @@ func BuildR53Input(hostedZone string) *route53.ChangeResourceRecordSetsInput {

// CreateR53TXTRecordChange creates an route53 Change object for a TXT record with a given name
// and a given action to take.
func CreateR53TXTRecordChange(name *string, action string, value *string) route53.Change {
change := route53.Change{
Action: aws.String(route53.ChangeActionDelete),
func CreateR53TXTRecordChange(name *string, action string, value *string) (change route53.Change, err error) {
if strings.EqualFold("DELETE", action) {
action = route53.ChangeActionDelete
} else if strings.EqualFold("CREATE", action) {
action = route53.ChangeActionCreate
} else if strings.EqualFold("UPSERT", action) {
action = route53.ChangeActionUpsert
} else {
return change, fmt.Errorf("Invaild record action passed %v. Must be DELETE, CREATE, or UPSERT", action)
}
change = route53.Change{
Action: aws.String(action),
ResourceRecordSet: &route53.ResourceRecordSet{
Name: aws.String(*name),
ResourceRecords: []*route53.ResourceRecord{
Expand All @@ -122,7 +131,7 @@ func CreateR53TXTRecordChange(name *string, action string, value *string) route5
Type: aws.String(route53.RRTypeTxt),
},
}
return change
return change, nil
}

// NewClient returns an awsclient.Client object to the caller. If NewClient is passed a non-null
Expand Down
5 changes: 4 additions & 1 deletion pkg/controller/certificaterequest/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,10 @@ func (r *ReconcileCertificateRequest) DeleteAllAcmeChallengeResourceRecords(reqL
input := awsclient.BuildR53Input(*hostedzone.Id)
for _, record := range listRecordSets.ResourceRecordSets {
if strings.Contains(*record.Name, acmeChallengeSubDomain) {
change := awsclient.CreateR53TXTRecordChange(record.Name, route53.ChangeActionDelete, record.ResourceRecords[0].Value)
change, err := awsclient.CreateR53TXTRecordChange(record.Name, route53.ChangeActionDelete, record.ResourceRecords[0].Value)
if err != nil {
reqLogger.Error(err, "Error creating record change object")
}
input.ChangeBatch.Changes = append(input.ChangeBatch.Changes, &change)
}
}
Expand Down

0 comments on commit 29fb90f

Please sign in to comment.