6bb420c393cec0a6b39a6e8367acf76ae7bfb446
[oom/platform/cert-service.git] / certServiceK8sExternalProvider / src / testdata / provider.go
1 /*
2  * ============LICENSE_START=======================================================
3  * oom-certservice-k8s-external-provider
4  * ================================================================================
5  * Copyright (C) 2020 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package testdata
22
23 import (
24         cmapi "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1"
25         "k8s.io/api/core/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"
31
32         "onap.org/oom-certservice/k8s-external-provider/src/cmpv2api"
33 )
34
35 const (
36         SecretName       = "issuer-cert-secret"
37         Url              = "https://oom-cert-service:8443/v1/certificate/"
38         HealthEndpoint   = "actuator/health"
39         CertEndpoint     = "v1/certificate"
40         CaName           = "RA"
41         KeySecretKey     = "cmpv2Issuer-key.pem"
42         CertSecretKey    = "cmpv2Issuer-cert.pem"
43         CacertSecretKey  = "cacert.pem"
44         Namespace        = "onap"
45         IssuerObjectName = "cmpv2-issuer"
46         Kind             = "CMPv2Issuer"
47         APIVersion       = "v1"
48         PrivateKeySecret = "privateKeySecretName"
49 )
50
51 func GetValidIssuerWithSecret() (cmpv2api.CMPv2Issuer, v1.Secret) {
52         issuer := cmpv2api.CMPv2Issuer{
53                 TypeMeta: metav1.TypeMeta{
54                         APIVersion: APIVersion,
55                         Kind:       Kind,
56                 },
57                 ObjectMeta: metav1.ObjectMeta{
58                         Name:      IssuerObjectName,
59                         Namespace: Namespace,
60                 },
61                 Spec: GetValidCMPv2IssuerSpec(),
62         }
63
64         secret := v1.Secret{
65                 Data: map[string][]byte{
66                         KeySecretKey:    KeyBytes,
67                         CertSecretKey:   CertBytes,
68                         CacertSecretKey: CacertBytes,
69                 },
70                 ObjectMeta: metav1.ObjectMeta{
71                         Name:      SecretName,
72                         Namespace: Namespace,
73                 },
74         }
75         secret.Name = SecretName
76         return issuer, secret
77 }
78
79 func GetValidCMPv2IssuerSpec() cmpv2api.CMPv2IssuerSpec {
80         issuerSpec := cmpv2api.CMPv2IssuerSpec{
81                 URL:            Url,
82                 HealthEndpoint: HealthEndpoint,
83                 CertEndpoint:   CertEndpoint,
84                 CaName:         CaName,
85                 CertSecretRef: cmpv2api.SecretKeySelector{
86                         Name:      SecretName,
87                         KeyRef:    KeySecretKey,
88                         CertRef:   CertSecretKey,
89                         CacertRef: CacertSecretKey,
90                 },
91         }
92         return issuerSpec
93 }
94
95 func GetScheme() *runtime.Scheme {
96         scheme := runtime.NewScheme()
97         _ = scheme2.AddToScheme(scheme)
98         _ = cmapi.AddToScheme(scheme)
99         _ = cmpv2api.AddToScheme(scheme)
100         return scheme
101 }
102
103 func GetFakeRequest(objectName string) reconcile.Request {
104         fakeRequest := reconcile.Request{
105                 NamespacedName: CreateIssuerNamespaceName(Namespace, objectName),
106         }
107         return fakeRequest
108 }
109
110 func GetIssuerStoreKey() types.NamespacedName {
111         return CreateIssuerNamespaceName(Namespace, IssuerObjectName)
112 }
113
114 func CreateIssuerNamespaceName(namespace string, name string) types.NamespacedName {
115         return types.NamespacedName{
116                 Namespace: namespace,
117                 Name:      name,
118         }
119 }