2 * ============LICENSE_START=======================================================
3 * oom-certservice-k8s-external-provider
4 * ================================================================================
5 * Copyright (C) 2020-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=========================================================
24 cmapi "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1"
26 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27 "k8s.io/apimachinery/pkg/runtime"
28 "k8s.io/apimachinery/pkg/types"
29 scheme2 "k8s.io/client-go/kubernetes/scheme"
30 "sigs.k8s.io/controller-runtime/pkg/reconcile"
32 "onap.org/oom-certservice/k8s-external-provider/src/cmpv2api"
36 SecretName = "issuer-cert-secret"
37 Url = "https://oom-cert-service:8443/v1/certificate/"
38 HealthEndpoint = "actuator/health"
39 CertEndpoint = "v1/certificate"
41 KeySecretKey = "cmpv2Issuer-key.pem"
42 CertSecretKey = "cmpv2Issuer-cert.pem"
43 CacertSecretKey = "cacert.pem"
45 IssuerObjectName = "cmpv2-issuer"
48 PrivateKeySecret = "privateKeySecretName"
49 OldCertificateConfig = "{\"apiVersion\":\"cert-manager.io/v1\",\"kind\":\"Certificate\",\"metadata\":{\"annotations\":{},\"name\":\"cert-test\",\"namespace\":\"onap\"},\"spec\":{\"commonName\":\"certissuer.onap.org\",\"dnsNames\":[\"localhost\",\"certissuer.onap.org\"],\"emailAddresses\":[\"onap@onap.org\"],\"ipAddresses\":[\"127.0.0.1\"],\"issuerRef\":{\"group\":\"certmanager.onap.org\",\"kind\":\"CMPv2Issuer\",\"name\":\"cmpv2-issuer-onap\"},\"secretName\":\"cert-test-secret-name\",\"subject\":{\"countries\":[\"US\"],\"localities\":[\"San-Francisco\"],\"organizationalUnits\":[\"ONAP\"],\"organizations\":[\"Linux-Foundation\"],\"provinces\":[\"California\"]},\"uris\":[\"onap://cluster.local/\"]}}\n"
52 func GetValidIssuerWithSecret() (cmpv2api.CMPv2Issuer, v1.Secret) {
53 issuer := cmpv2api.CMPv2Issuer{
54 TypeMeta: metav1.TypeMeta{
55 APIVersion: APIVersion,
58 ObjectMeta: metav1.ObjectMeta{
59 Name: IssuerObjectName,
62 Spec: GetValidCMPv2IssuerSpec(),
66 Data: map[string][]byte{
67 KeySecretKey: KeyBytes,
68 CertSecretKey: CertBytes,
69 CacertSecretKey: CacertBytes,
71 ObjectMeta: metav1.ObjectMeta{
76 secret.Name = SecretName
80 func GetValidCMPv2IssuerSpec() cmpv2api.CMPv2IssuerSpec {
81 issuerSpec := cmpv2api.CMPv2IssuerSpec{
83 HealthEndpoint: HealthEndpoint,
84 CertEndpoint: CertEndpoint,
86 CertSecretRef: cmpv2api.SecretKeySelector{
89 CertRef: CertSecretKey,
90 CacertRef: CacertSecretKey,
96 func GetScheme() *runtime.Scheme {
97 scheme := runtime.NewScheme()
98 _ = scheme2.AddToScheme(scheme)
99 _ = cmapi.AddToScheme(scheme)
100 _ = cmpv2api.AddToScheme(scheme)
104 func GetFakeRequest(objectName string) reconcile.Request {
105 fakeRequest := reconcile.Request{
106 NamespacedName: CreateIssuerNamespaceName(Namespace, objectName),
111 func GetIssuerStoreKey() types.NamespacedName {
112 return CreateIssuerNamespaceName(Namespace, IssuerObjectName)
115 func CreateIssuerNamespaceName(namespace string, name string) types.NamespacedName {
116 return types.NamespacedName{
117 Namespace: namespace,
122 func GetValidCertificateSecret() *v1.Secret {
123 const privateKeySecretKey = "tls.key"
124 const certificateSecretKey = "tls.crt"
127 Data: map[string][]byte{
128 privateKeySecretKey: []byte("test-private-key"),
129 certificateSecretKey: []byte("test-certificate"),
131 ObjectMeta: metav1.ObjectMeta{
132 Name: "cert-test-secret-name",