@@ -91,8 +91,17 @@ func withDefaultASN1DN(def *config.ASN1DN) provisioner.CertificateModifierFunc {
91
91
}
92
92
}
93
93
94
- // Sign creates a signed certificate from a certificate signing request.
94
+ // Sign creates a signed certificate from a certificate signing request. It
95
+ // creates a new context.Context, and calls into SignWithContext.
96
+ //
97
+ // Deprecated: Use authority.SignWithContext with an actual context.Context.
95
98
func (a * Authority ) Sign (csr * x509.CertificateRequest , signOpts provisioner.SignOptions , extraOpts ... provisioner.SignOption ) ([]* x509.Certificate , error ) {
99
+ return a .SignWithContext (context .Background (), csr , signOpts , extraOpts ... )
100
+ }
101
+
102
+ // SignWithContext creates a signed certificate from a certificate signing request,
103
+ // taking the provided context.Context.
104
+ func (a * Authority ) SignWithContext (ctx context.Context , csr * x509.CertificateRequest , signOpts provisioner.SignOptions , extraOpts ... provisioner.SignOption ) ([]* x509.Certificate , error ) {
96
105
var (
97
106
certOptions []x509util.Option
98
107
certValidators []provisioner.CertificateValidator
@@ -163,7 +172,7 @@ func (a *Authority) Sign(csr *x509.CertificateRequest, signOpts provisioner.Sign
163
172
}
164
173
}
165
174
166
- if err := callEnrichingWebhooksX509 (webhookCtl , attData , csr ); err != nil {
175
+ if err := callEnrichingWebhooksX509 (ctx , webhookCtl , attData , csr ); err != nil {
167
176
return nil , errs .ApplyOptions (
168
177
errs .ForbiddenErr (err , err .Error ()),
169
178
errs .WithKeyVal ("csr" , csr ),
@@ -256,7 +265,7 @@ func (a *Authority) Sign(csr *x509.CertificateRequest, signOpts provisioner.Sign
256
265
}
257
266
258
267
// Send certificate to webhooks for authorization
259
- if err := callAuthorizingWebhooksX509 (webhookCtl , cert , leaf , attData ); err != nil {
268
+ if err := callAuthorizingWebhooksX509 (ctx , webhookCtl , cert , leaf , attData ); err != nil {
260
269
return nil , errs .ApplyOptions (
261
270
errs .ForbiddenErr (err , "error creating certificate" ),
262
271
opts ... ,
@@ -952,7 +961,7 @@ func templatingError(err error) error {
952
961
return errors .Wrap (cause , "error applying certificate template" )
953
962
}
954
963
955
- func callEnrichingWebhooksX509 (webhookCtl webhookController , attData * provisioner.AttestationData , csr * x509.CertificateRequest ) error {
964
+ func callEnrichingWebhooksX509 (ctx context. Context , webhookCtl webhookController , attData * provisioner.AttestationData , csr * x509.CertificateRequest ) error {
956
965
if webhookCtl == nil {
957
966
return nil
958
967
}
@@ -969,10 +978,10 @@ func callEnrichingWebhooksX509(webhookCtl webhookController, attData *provisione
969
978
if err != nil {
970
979
return err
971
980
}
972
- return webhookCtl .Enrich (whEnrichReq )
981
+ return webhookCtl .Enrich (ctx , whEnrichReq )
973
982
}
974
983
975
- func callAuthorizingWebhooksX509 (webhookCtl webhookController , cert * x509util.Certificate , leaf * x509.Certificate , attData * provisioner.AttestationData ) error {
984
+ func callAuthorizingWebhooksX509 (ctx context. Context , webhookCtl webhookController , cert * x509util.Certificate , leaf * x509.Certificate , attData * provisioner.AttestationData ) error {
976
985
if webhookCtl == nil {
977
986
return nil
978
987
}
@@ -989,5 +998,5 @@ func callAuthorizingWebhooksX509(webhookCtl webhookController, cert *x509util.Ce
989
998
if err != nil {
990
999
return err
991
1000
}
992
- return webhookCtl .Authorize (whAuthBody )
1001
+ return webhookCtl .Authorize (ctx , whAuthBody )
993
1002
}
0 commit comments