@@ -23,8 +23,8 @@ type GoACM struct {
2323}
2424
2525// NewGoACM returns a new GoACM object.
26- func NewGoACM (region string ) (* GoACM , error ) {
27- cfg , err := config .LoadDefaultConfig (context . TODO () , config .WithRegion (region ))
26+ func NewGoACM (ctx context. Context , region string ) (* GoACM , error ) {
27+ cfg , err := config .LoadDefaultConfig (ctx , config .WithRegion (region ))
2828 if err != nil {
2929 return nil , err
3030 }
@@ -37,9 +37,9 @@ func NewGoACM(region string) (*GoACM, error) {
3737}
3838
3939// ListCertificateSummaries returns a list of certificate summary.
40- func ListCertificateSummaries (api ACMListCertificatesAPI ) ([]acmTypes.CertificateSummary , error ) {
40+ func ListCertificateSummaries (ctx context. Context , api ACMListCertificatesAPI ) ([]acmTypes.CertificateSummary , error ) {
4141 in := acm.ListCertificatesInput {}
42- out , err := api .ListCertificates (context . TODO () , & in )
42+ out , err := api .ListCertificates (ctx , & in )
4343 if err != nil {
4444 return nil , err
4545 }
@@ -48,11 +48,11 @@ func ListCertificateSummaries(api ACMListCertificatesAPI) ([]acmTypes.Certificat
4848}
4949
5050// GetCertificate returns the details of the certificate.
51- func GetCertificate (api ACMDescribeCertificateAPI , arn string ) (Certificate , error ) {
51+ func GetCertificate (ctx context. Context , api ACMDescribeCertificateAPI , arn string ) (Certificate , error ) {
5252 in := acm.DescribeCertificateInput {
5353 CertificateArn : aws .String (arn ),
5454 }
55- out , err := api .DescribeCertificate (context . TODO () , & in )
55+ out , err := api .DescribeCertificate (ctx , & in )
5656 if err != nil {
5757 return Certificate {}, err
5858 }
@@ -81,15 +81,15 @@ func GetCertificate(api ACMDescribeCertificateAPI, arn string) (Certificate, err
8181}
8282
8383// ListCertificates returns list of certificate.
84- func ListCertificates (api ACMAPI ) ([]Certificate , error ) {
85- summary , err := ListCertificateSummaries (api )
84+ func ListCertificates (ctx context. Context , api ACMAPI ) ([]Certificate , error ) {
85+ summary , err := ListCertificateSummaries (ctx , api )
8686 if err != nil {
8787 return nil , err
8888 }
8989
9090 var cList []Certificate
9191 for _ , s := range summary {
92- c , err := GetCertificate (api , aws .ToString (s .CertificateArn ))
92+ c , err := GetCertificate (ctx , api , aws .ToString (s .CertificateArn ))
9393 if err != nil {
9494 fmt .Println (err .Error ())
9595 continue
@@ -101,15 +101,15 @@ func ListCertificates(api ACMAPI) ([]Certificate, error) {
101101}
102102
103103// DeleteCertificate returns an error if deleting the certificate fails.
104- func DeleteCertificate (aAPI ACMAPI , rAPI Route53API , arn string ) error {
105- c , err := GetCertificate (aAPI , arn )
104+ func DeleteCertificate (ctx context. Context , aAPI ACMAPI , rAPI Route53API , arn string ) error {
105+ c , err := GetCertificate (ctx , aAPI , arn )
106106 if err != nil {
107107 return err
108108 }
109109
110110 // Delete Route 53 Record that validate domain.
111111 if c .ValidationMethod == string (types .ValidationMethodDns ) {
112- if err := DeleteRoute53RecordSet (aAPI , rAPI , c .ValidationRecordSet ); err != nil {
112+ if err := DeleteRoute53RecordSet (ctx , aAPI , rAPI , c .ValidationRecordSet ); err != nil {
113113 return err
114114 }
115115 }
@@ -118,15 +118,15 @@ func DeleteCertificate(aAPI ACMAPI, rAPI Route53API, arn string) error {
118118 CertificateArn : aws .String (arn ),
119119 }
120120
121- if _ , err := aAPI .DeleteCertificate (context . TODO () , & in ); err != nil {
121+ if _ , err := aAPI .DeleteCertificate (ctx , & in ); err != nil {
122122 return err
123123 }
124124
125125 return nil
126126}
127127
128128// IssueCertificate issues an SSL certificate for the specified domain.
129- func IssueCertificate (aAPI ACMAPI , rAPI Route53API , method , targetDomain , hostedDomain string ) (IssueCertificateResult , error ) {
129+ func IssueCertificate (ctx context. Context , aAPI ACMAPI , rAPI Route53API , method , targetDomain , hostedDomain string ) (IssueCertificateResult , error ) {
130130 var result IssueCertificateResult = IssueCertificateResult {
131131 DomainName : targetDomain ,
132132 HostedDomainName : hostedDomain ,
@@ -144,7 +144,7 @@ func IssueCertificate(aAPI ACMAPI, rAPI Route53API, method, targetDomain, hosted
144144 },
145145 },
146146 }
147- r , err := aAPI .RequestCertificate (context . TODO () , & reqIn )
147+ r , err := aAPI .RequestCertificate (ctx , & reqIn )
148148 if err != nil {
149149 return IssueCertificateResult {}, err
150150 }
@@ -160,13 +160,13 @@ func IssueCertificate(aAPI ACMAPI, rAPI Route53API, method, targetDomain, hosted
160160 dcIn := acm.DescribeCertificateInput {
161161 CertificateArn : r .CertificateArn ,
162162 }
163- c , err := aAPI .DescribeCertificate (context . TODO () , & dcIn )
163+ c , err := aAPI .DescribeCertificate (ctx , & dcIn )
164164 if err != nil {
165165 return IssueCertificateResult {}, err
166166 }
167167 if c .Certificate .DomainValidationOptions == nil {
168168 errMsg := "DomainValidationOptions dose not exists"
169- if err := RollbackIssueCertificate (aAPI , rAPI , * c .Certificate .CertificateArn ); err != nil {
169+ if err := RollbackIssueCertificate (ctx , aAPI , rAPI , * c .Certificate .CertificateArn ); err != nil {
170170 errMsg += fmt .Sprintf ("; Failed to rollback to issue certificate: %v" , err )
171171 } else {
172172 errMsg += "; rollbacked to issue certificate"
@@ -181,10 +181,10 @@ func IssueCertificate(aAPI ACMAPI, rAPI Route53API, method, targetDomain, hosted
181181 result .ValidationRecordValue = * vRecordValue
182182
183183 lhzIn := route53.ListHostedZonesInput {}
184- h , err := rAPI .ListHostedZones (context . TODO () , & lhzIn )
184+ h , err := rAPI .ListHostedZones (ctx , & lhzIn )
185185 if err != nil {
186186 errMsg := err .Error ()
187- if err := RollbackIssueCertificate (aAPI , rAPI , * c .Certificate .CertificateArn ); err != nil {
187+ if err := RollbackIssueCertificate (ctx , aAPI , rAPI , * c .Certificate .CertificateArn ); err != nil {
188188 errMsg += fmt .Sprintf ("; Failed to rollback to issue certificate: %v" , err )
189189 } else {
190190 errMsg += "; rollbacked to issue certificate"
@@ -200,7 +200,7 @@ func IssueCertificate(aAPI ACMAPI, rAPI Route53API, method, targetDomain, hosted
200200 }
201201 if hzID == "" {
202202 errMsg := "Cannot get hosted zone ID"
203- if err := RollbackIssueCertificate (aAPI , rAPI , * c .Certificate .CertificateArn ); err != nil {
203+ if err := RollbackIssueCertificate (ctx , aAPI , rAPI , * c .Certificate .CertificateArn ); err != nil {
204204 errMsg += fmt .Sprintf ("; Failed to rollback to issue certificate: %v" , err )
205205 } else {
206206 errMsg += "; rollbacked to issue certificate"
@@ -231,10 +231,10 @@ func IssueCertificate(aAPI ACMAPI, rAPI Route53API, method, targetDomain, hosted
231231 },
232232 }
233233
234- _ , err = rAPI .ChangeResourceRecordSets (context . TODO () , & crsIn )
234+ _ , err = rAPI .ChangeResourceRecordSets (ctx , & crsIn )
235235 if err != nil {
236236 errMsg := err .Error ()
237- if err := RollbackIssueCertificate (aAPI , rAPI , * c .Certificate .CertificateArn ); err != nil {
237+ if err := RollbackIssueCertificate (ctx , aAPI , rAPI , * c .Certificate .CertificateArn ); err != nil {
238238 errMsg += fmt .Sprintf ("; Failed to rollback to issue certificate: %v" , err )
239239 } else {
240240 errMsg += "; rollbacked to issue certificate"
@@ -246,14 +246,14 @@ func IssueCertificate(aAPI ACMAPI, rAPI Route53API, method, targetDomain, hosted
246246}
247247
248248// RollbackIssueCertificate rollbacks to issue an SSL certificate.
249- func RollbackIssueCertificate (aAPI ACMAPI , rAPI Route53API , arn string ) error {
250- return DeleteCertificate (aAPI , rAPI , arn )
249+ func RollbackIssueCertificate (ctx context. Context , aAPI ACMAPI , rAPI Route53API , arn string ) error {
250+ return DeleteCertificate (ctx , aAPI , rAPI , arn )
251251}
252252
253253// DeleteRoute53RecordSet deletes a Route 53 record set.
254- func DeleteRoute53RecordSet (aAPI ACMAPI , rAPI Route53API , rs RecordSet ) error {
254+ func DeleteRoute53RecordSet (ctx context. Context , aAPI ACMAPI , rAPI Route53API , rs RecordSet ) error {
255255 lhzIn := route53.ListHostedZonesInput {}
256- h , err := rAPI .ListHostedZones (context . TODO () , & lhzIn )
256+ h , err := rAPI .ListHostedZones (ctx , & lhzIn )
257257 if err != nil {
258258 return err
259259 }
@@ -273,7 +273,7 @@ func DeleteRoute53RecordSet(aAPI ACMAPI, rAPI Route53API, rs RecordSet) error {
273273 StartRecordName : aws .String (rs .Name ),
274274 MaxItems : aws .Int32 (1 ),
275275 }
276- r , err := rAPI .ListResourceRecordSets (context . TODO () , & lrrsIn )
276+ r , err := rAPI .ListResourceRecordSets (ctx , & lrrsIn )
277277 if err != nil {
278278 return err
279279 }
@@ -308,7 +308,7 @@ func DeleteRoute53RecordSet(aAPI ACMAPI, rAPI Route53API, rs RecordSet) error {
308308 },
309309 }
310310
311- _ , err = rAPI .ChangeResourceRecordSets (context . TODO () , & crsIn )
311+ _ , err = rAPI .ChangeResourceRecordSets (ctx , & crsIn )
312312
313313 if err != nil {
314314 return err
0 commit comments