func LabelsForNifiPKI(name string) map[string]string {
	return map[string]string{"app": "nifi", "nifi_issuer": fmt.Sprintf(NodeIssuerTemplate, name)}
}
LabelsForNifiPKI returns kubernetes labels for a PKI object
package pki
import (
	"context"
	"crypto/tls"
	"fmt"
	"github.com/Orange-OpenSource/nifikop/api/v1alpha1"
	"github.com/Orange-OpenSource/nifikop/pkg/resources/templates"
	certutil "github.com/Orange-OpenSource/nifikop/pkg/util/cert"
	"github.com/Orange-OpenSource/nifikop/pkg/util/nifi"
	"github.com/go-logr/logr"
	"k8s.io/apimachinery/pkg/runtime"
)
const (
	NodeSelfSignerTemplate = "%s-self-signer"
	NodeCACertTemplate = "%s-ca-certificate"
	NodeServerCertTemplate = "%s-%d-server-certificate"
	NodeIssuerTemplate = "%s-issuer"
	NodeControllerTemplate = "%s-controller"
	NodeControllerFQDNTemplate = "%s.%s.mgt.%s"
	SpiffeIdTemplate = "spiffe://%s/ns/%s/nifiuser/%s"
	CAIntermediateTemplate = "%s-intermediate.%s"
	CAFQDNTemplate = "%s-ca.%s.%s"
)
type Manager interface {
	ReconcilePKI(ctx context.Context, logger logr.Logger, scheme *runtime.Scheme, externalHostnames []string) error
	FinalizePKI(ctx context.Context, logger logr.Logger) error
	ReconcileUserCertificate(ctx context.Context, user *v1alpha1.NifiUser, scheme *runtime.Scheme) (*UserCertificate, error)
	FinalizeUserCertificate(ctx context.Context, user *v1alpha1.NifiUser) error
	GetControllerTLSConfig() (*tls.Config, error)
}
type UserCertificate struct {
	CA          []byte
	Certificate []byte
	Key         []byte
}
func (u *UserCertificate) DN() string {
	cert, _ := certutil.DecodeCertificate(u.Certificate)
	return cert.Subject.String()
}
func GetInternalDNSNames(cluster *v1alpha1.NifiCluster, nodeId int32) (dnsNames []string) {
	dnsNames = make([]string, 0)
	dnsNames = append(dnsNames, ClusterDNSNames(cluster, nodeId)...)
	return
}
func GetNodeUserName(cluster *v1alpha1.NifiCluster, nodeId int32) string {
	return nifi.ComputeRequestNiFiNodeHostname(nodeId, cluster.Name, cluster.Namespace,
		cluster.Spec.Service.HeadlessEnabled, cluster.Spec.ListenersConfig.GetClusterDomain(), cluster.Spec.ListenersConfig.UseExternalDNS)
}
func ClusterDNSNames(cluster *v1alpha1.NifiCluster, nodeId int32) (names []string) {
	names = make([]string, 0)
	names = append(names,
		nifi.ComputeRequestNiFiAllNodeHostname(cluster.Name, cluster.Namespace, cluster.Spec.Service.HeadlessEnabled,
			cluster.Spec.ListenersConfig.GetClusterDomain(), cluster.Spec.ListenersConfig.UseExternalDNS))
	names = append(names,
		nifi.ComputeRequestNiFiNodeHostname(nodeId, cluster.Name, cluster.Namespace, cluster.Spec.Service.HeadlessEnabled,
			cluster.Spec.ListenersConfig.GetClusterDomain(), cluster.Spec.ListenersConfig.UseExternalDNS))
	if !cluster.Spec.ListenersConfig.UseExternalDNS {
		names = append(names,
			nifi.ComputeRequestNiFiAllNodeNamespaceFull(cluster.Name, cluster.Namespace,
				cluster.Spec.Service.HeadlessEnabled, cluster.Spec.ListenersConfig.UseExternalDNS))
		names = append(names,
			nifi.ComputeRequestNiFiNodeNamespaceFull(nodeId, cluster.Name, cluster.Namespace,
				cluster.Spec.Service.HeadlessEnabled, cluster.Spec.ListenersConfig.UseExternalDNS))
		names = append(names,
			nifi.ComputeRequestNiFiAllNodeNamespace(cluster.Name, cluster.Namespace,
				cluster.Spec.Service.HeadlessEnabled, cluster.Spec.ListenersConfig.UseExternalDNS))
		names = append(names,
			nifi.ComputeRequestNiFiNodeNamespace(nodeId, cluster.Name, cluster.Namespace,
				cluster.Spec.Service.HeadlessEnabled, cluster.Spec.ListenersConfig.UseExternalDNS))
		names = append(names,
			nifi.ComputeRequestNiFiAllNodeService(cluster.Name, cluster.Spec.Service.HeadlessEnabled))
		names = append(names,
			nifi.ComputeRequestNiFiNodeService(nodeId, cluster.Name, cluster.Spec.Service.HeadlessEnabled))
		if cluster.Spec.Service.HeadlessEnabled {
			names = append(names,
				nifi.ComputeNodeName(nodeId, cluster.Name))
		} else {
			names = append(names, nifi.ComputeHostListenerNodeHostname(
				nodeId, cluster.Name, cluster.Namespace, cluster.Spec.Service.HeadlessEnabled,
				cluster.Spec.ListenersConfig.GetClusterDomain(), cluster.Spec.ListenersConfig.UseExternalDNS))
		}
	}
	return
}