Skip to content

Commit

Permalink
add godocs
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Luz Almeida <[email protected]>
  • Loading branch information
leoluz committed Sep 19, 2024
1 parent c273d42 commit 5a1ed8d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/backend/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions internal/backend/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,29 @@ 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,
logger: l,
}
}

// 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 {
Expand Down

0 comments on commit 5a1ed8d

Please sign in to comment.