Skip to content

Commit

Permalink
Check that specified certificate ARN exists before creating stack (#90)
Browse files Browse the repository at this point in the history
Fix #86
  • Loading branch information
mikkeloscar authored Oct 4, 2017
1 parent 88b158d commit 1a6295d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ func buildManagedModel(certsProvider certs.CertificatesProvider, ingresses []*ku
log.Printf("failed to find a certificate for %v: %v", ingress.CertHostname(), err)
continue
}
} else { // validate that certificateARN exists
err := checkCertificate(certsProvider, certificateARN)
if err != nil {
log.Printf("Failed to find certificate with ARN %s: %v", certificateARN, err)
continue
}
}
if item, ok := model[certificateARN]; ok {
item.ingresses = append(item.ingresses, ingress)
Expand All @@ -181,6 +187,23 @@ func discoverCertificateAndUpdateIngress(certsProvider certs.CertificatesProvide
return certificateSummary.ID(), nil
}

// checkCertificate checks that a certificate with the specified ARN exists in
// the account. Returns error if no certificate is found.
func checkCertificate(certsProvider certs.CertificatesProvider, arn string) error {
certs, err := certsProvider.GetCertificates()
if err != nil {
return err
}

for _, cert := range certs {
if arn == cert.ID() {
return nil
}
}

return fmt.Errorf("certificate not found")
}

func createStack(awsAdapter *aws.Adapter, item *managedItem) {
certificateARN := item.ingresses[0].CertificateARN()
log.Printf("creating stack for certificate %q / ingress %q", certificateARN, item.ingresses)
Expand Down

0 comments on commit 1a6295d

Please sign in to comment.