2 * ============LICENSE_START=======================================================
3 * oom-certservice-k8s-external-provider
4 * ================================================================================
5 * Copyright (C) 2021 Nokia. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
26 "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1"
27 "sigs.k8s.io/controller-runtime/pkg/client"
29 "onap.org/oom-certservice/k8s-external-provider/src/cmpv2controller/util"
30 "onap.org/oom-certservice/k8s-external-provider/src/cmpv2provisioner/csr"
31 "onap.org/oom-certservice/k8s-external-provider/src/leveledlogger"
34 func CreateSignCertificateModel(client client.Client, certificateRequest *v1.CertificateRequest, ctx context.Context, privateKeyBytes []byte) (SignCertificateModel, error) {
35 log := leveledlogger.GetLoggerWithName("certservice-certificate-model")
36 oldCertificateBytes, oldPrivateKeyBytes := util.RetrieveOldCertificateAndPkForCertificateUpdate(
37 client, certificateRequest, ctx)
39 csrBytes := certificateRequest.Spec.Request
40 log.Debug("Original CSR PEM: ", "bytes", csrBytes)
42 filteredCsrBytes, err := csr.FilterFieldsFromCSR(csrBytes, privateKeyBytes)
44 return SignCertificateModel{}, err
46 log.Debug("Filtered out CSR PEM: ", "bytes", filteredCsrBytes)
48 signCertificateModel := SignCertificateModel{
49 CertificateRequest: certificateRequest,
50 FilteredCsr: filteredCsrBytes,
51 PrivateKeyBytes: privateKeyBytes,
52 OldCertificateBytes: oldCertificateBytes,
53 OldPrivateKeyBytes: oldPrivateKeyBytes,
55 return signCertificateModel, nil