/
certs.go
34 lines (29 loc) · 1021 Bytes
/
certs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (c) 2021, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
package pkg
import (
"context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
)
// GetCertificate returns the a cert in a given namespace for the cluster specified in the environment
func GetCertificate(namespace string, name string) (*unstructured.Unstructured, error) {
client, err := GetDynamicClient()
if err != nil {
return nil, err
}
cert, err := client.Resource(getScheme()).Namespace(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return nil, err
}
return cert, nil
}
// getScheme returns the certificate scheme needed to get unstructured data
func getScheme() schema.GroupVersionResource {
return schema.GroupVersionResource{
Group: "cert-manager.io",
Version: "v1alpha2",
Resource: "certificate",
}
}