func (s *Service) User() string {
	return s.Username
}
User returns the service's username
package services
import (
	"context"
	"errors"
	"fmt"
	"github.com/epinio/epinio/helpers/kubernetes"
	corev1 "k8s.io/api/core/v1"
	apierrors "k8s.io/apimachinery/pkg/api/errors"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type ServiceList []*Service
type Service struct {
	SecretName string
	OrgName    string
	Service    string
	Username   string
	kubeClient *kubernetes.Cluster
}
func Lookup(ctx context.Context, kubeClient *kubernetes.Cluster, org, service string) (*Service, error) {
	secretName := serviceResourceName(org, service)
	s, err := kubeClient.GetSecret(ctx, org, secretName)
	if err != nil {
		if apierrors.IsNotFound(err) {
			return nil, errors.New("service not found")
		}
		return nil, err
	}
	username := s.ObjectMeta.Labels["app.kubernetes.io/created-by"]
	return &Service{
		SecretName: secretName,
		OrgName:    org,
		Service:    service,
		kubeClient: kubeClient,
		Username:   username,
	}, nil
}
func List(ctx context.Context, kubeClient *kubernetes.Cluster, org string) (ServiceList, error) {
	labelSelector := fmt.Sprintf("app.kubernetes.io/name=epinio, epinio.suse.org/namespace=%s", org)
	secrets, err := kubeClient.Kubectl.CoreV1().
		Secrets(org).List(ctx,
		metav1.ListOptions{
			LabelSelector: labelSelector,
		})
	if err != nil {
		return nil, err
	}
	result := ServiceList{}
	for _, s := range secrets.Items {
		service := s.ObjectMeta.Labels["epinio.suse.org/service"]
		org := s.ObjectMeta.Labels["epinio.suse.org/namespace"]
		username := s.ObjectMeta.Labels["app.kubernetes.io/created-by"]
		secretName := s.ObjectMeta.Name
		result = append(result, &Service{
			SecretName: secretName,
			OrgName:    org,
			Service:    service,
			kubeClient: kubeClient,
			Username:   username,
		})
	}
	return result, nil
}
func CreateService(ctx context.Context, kubeClient *kubernetes.Cluster, name, org, username string,
	data map[string]string) (*Service, error) {
	secretName := serviceResourceName(org, name)
	_, err := kubeClient.GetSecret(ctx, org, secretName)
	if err == nil {
		return nil, errors.New("Service of this name already exists.")
	}
	sdata := make(map[string][]byte)
	for k, v := range data {
		sdata[k] = []byte(v)
	}
	err = kubeClient.CreateLabeledSecret(ctx, org, secretName, sdata,
		map[string]string{
			"epinio.suse.org/service":      name,
			"epinio.suse.org/namespace":    org,
			"app.kubernetes.io/name":       "epinio",
			"app.kubernetes.io/created-by": username,
		},
	)
	if err != nil {
		return nil, err
	}
	return &Service{
		SecretName: secretName,
		OrgName:    org,
		Service:    name,
		kubeClient: kubeClient,
	}, nil
}
func (s *Service) Name() string {
	return s.Service
}