42
42
import org .bouncycastle .pkcs .jcajce .JcaPKCS10CertificationRequestBuilder ;
43
43
import org .bouncycastle .util .io .pem .PemObject ;
44
44
import org .bouncycastle .util .io .pem .PemWriter ;
45
- import org .springframework .http .MediaType ;
46
45
import org .springframework .stereotype .Service ;
47
46
import reactor .core .publisher .Flux ;
48
47
import reactor .core .publisher .Mono ;
52
51
@ Slf4j
53
52
public class CertificateProcessingService {
54
53
55
- public static final MediaType PEM_CERT_CHAIN = MediaType .parseMediaType ("application/pem-certificate-chain" );
56
-
57
54
private final KubernetesClient k8s ;
58
55
private final AppProperties appProperties ;
59
56
private final AcmeDirectoryService directoryService ;
@@ -105,7 +102,7 @@ public Mono<Secret> initiateCertCreation(Ingress ingress, IngressTLS tls, String
105
102
*/
106
103
return Flux .fromIterable (orderResponse .authorizations ())
107
104
.flatMap (authzUri -> loadAuthorization (issuerId , authzUri )
108
- .flatMap (authz -> processAuthorization (issuerId , authzUri , authz , ingress , tls ))
105
+ .flatMap (authz -> processAuthorization (issuerId , authzUri , authz , ingress ))
109
106
)
110
107
.then (
111
108
submitCsr (issuerId , identifiers , orderResponse .finalizeUri ())
@@ -114,20 +111,23 @@ public Mono<Secret> initiateCertCreation(Ingress ingress, IngressTLS tls, String
114
111
.map (certChain -> buildCertAndKey (certChain , csrResult .privateKey ()))
115
112
)
116
113
.map (certAndKey -> storeSecret (issuerId , hosts , certAndKey .certChain (), certAndKey .privateKey (),
117
- secretName
114
+ secretName , ingressName
118
115
))
119
116
);
120
117
});
121
118
122
119
}
123
120
124
- private Secret storeSecret (String issuerId , List <String > hosts , String certChain , String privateKey , String secretName ) {
121
+ private Secret storeSecret (String issuerId , List <String > hosts , String certChain , String privateKey , String secretName ,
122
+ String ingressName
123
+ ) {
125
124
final Encoder b64Encoder = Base64 .getEncoder ();
126
125
final Secret secret = new SecretBuilder ()
127
126
.withMetadata (new ObjectMetaBuilder ()
128
127
.withName (secretName )
129
128
.withLabels (Map .of (
130
- Metadata .ISSUER_LABEL , issuerId
129
+ Metadata .ISSUER_LABEL , issuerId ,
130
+ Metadata .FOR_INGRESS_LABEL , ingressName
131
131
))
132
132
.withAnnotations (Map .of (
133
133
Metadata .HOST_ANNOTATION , String .join ("," , hosts )
@@ -244,8 +244,7 @@ private Extensions createExtensions(List<Identifier> identifiers) {
244
244
} catch (IOException e ) {
245
245
throw new RuntimeException ("Failed to create SAN extension" , e );
246
246
}
247
- final Extensions sanExtension = extensionsGenerator .generate ();
248
- return sanExtension ;
247
+ return extensionsGenerator .generate ();
249
248
}
250
249
251
250
private KeyPair generateCertKeyPair () {
@@ -263,8 +262,8 @@ private Mono<AuthzResponse> loadAuthorization(String issuerId, URI authzUri) {
263
262
return requestService .request (issuerId , authzUri , "" , AuthzResponse .class );
264
263
}
265
264
266
- private Mono <AuthzResponse > processAuthorization (String issuerId , URI authzUri , AuthzResponse auth , Ingress appIngress ,
267
- IngressTLS tls
265
+ private Mono <AuthzResponse > processAuthorization (String issuerId , URI authzUri , AuthzResponse auth ,
266
+ Ingress appIngress
268
267
) {
269
268
final Challenge httpChallenge = auth .challenges ().stream ()
270
269
.filter (challenge -> challenge .type ().equals (Challenge .TYPE_HTTP_01 ))
0 commit comments