From 5a1ed8d128471cd0fecf2e257f0171eb641fa004 Mon Sep 17 00:00:00 2001 From: Leonardo Luz Almeida Date: Thu, 19 Sep 2024 15:37:13 -0400 Subject: [PATCH] add godocs Signed-off-by: Leonardo Luz Almeida --- internal/backend/k8s.go | 6 ++++++ internal/backend/service.go | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/internal/backend/k8s.go b/internal/backend/k8s.go index d00800c..7437445 100644 --- a/internal/backend/k8s.go +++ b/internal/backend/k8s.go @@ -22,16 +22,20 @@ type Persister interface { GetAccessRequest(ctx context.Context, name, namespace string) (*api.AccessRequest, error) } +// K8sPersister is a K8s implementation for the Persister interface. type K8sPersister struct { client dynamic.Interface } +// NewK8sPersister will return a new K8sPersister instance. func NewK8sPersister(c dynamic.Interface) *K8sPersister { return &K8sPersister{ client: c, } } +// GetAccessRequestResource return a GroupVersionResource schema for the +// AccessRequest CRD. func GetAccessRequestResource() schema.GroupVersionResource { return schema.GroupVersionResource{ Group: api.GroupVersion.Group, @@ -40,6 +44,8 @@ func GetAccessRequestResource() schema.GroupVersionResource { } } +// GetAccessRequest will retrieve an AccessRequest from k8s identified by the given +// name and namespace. func (c *K8sPersister) GetAccessRequest(ctx context.Context, name, namespace string) (*api.AccessRequest, error) { resp, err := c.client.Resource(GetAccessRequestResource()).Namespace(namespace).Get(ctx, name, metav1.GetOptions{}) if err != nil { diff --git a/internal/backend/service.go b/internal/backend/service.go index 1f422c4..abda866 100644 --- a/internal/backend/service.go +++ b/internal/backend/service.go @@ -9,15 +9,19 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" ) +// Service defines the operations provided by the backend. Backend business +// logic should be added in implementations of this interface type Service interface { GetAccessRequest(ctx context.Context, name, namespace string) (*api.AccessRequest, error) } +// DefaultService is the real Service implementation type DefaultService struct { k8s Persister logger log.Logger } +// NewDefaultService will return a new DefaultService instance. func NewDefaultService(c Persister, l log.Logger) *DefaultService { return &DefaultService{ k8s: c, @@ -25,6 +29,9 @@ func NewDefaultService(c Persister, l log.Logger) *DefaultService { } } +// GetAccessRequest will retrieve the access request from k8s identified by the +// given name and namespace. Will return a nil value without any error if the +// access request isn't found. func (s *DefaultService) GetAccessRequest(ctx context.Context, name, namespace string) (*api.AccessRequest, error) { ar, err := s.k8s.GetAccessRequest(ctx, name, namespace) if err != nil {