Skip to content

Commit

Permalink
Add godoc
Browse files Browse the repository at this point in the history
  • Loading branch information
atburke committed Jul 29, 2024
1 parent 80faa1e commit 5033f87
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
11 changes: 11 additions & 0 deletions lib/services/local/statichostuser.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ const (
staticHostUserPrefix = "static_host_user"
)

// StaticHostUserService manages host users that should be created on SSH nodes.
type StaticHostUserService struct {
svc *generic.ServiceWrapper[*userprovisioningpb.StaticHostUser]
}

// NewStaticHostUserService creates a new static host user service.
func NewStaticHostUserService(bk backend.Backend) (*StaticHostUserService, error) {
svc, err := generic.NewServiceWrapper(
bk,
Expand All @@ -53,6 +55,7 @@ func NewStaticHostUserService(bk backend.Backend) (*StaticHostUserService, error
}, nil
}

// ListStaticHostUsers lists static host users.
func (s *StaticHostUserService) ListStaticHostUsers(ctx context.Context, pageSize int, pageToken string) ([]*userprovisioningpb.StaticHostUser, string, error) {
out, nextToken, err := s.svc.ListResources(ctx, pageSize, pageToken)
if err != nil {
Expand All @@ -61,30 +64,38 @@ func (s *StaticHostUserService) ListStaticHostUsers(ctx context.Context, pageSiz
return out, nextToken, nil
}

// GetStaticHostUser returns a static host user by name.
func (s *StaticHostUserService) GetStaticHostUser(ctx context.Context, name string) (*userprovisioningpb.StaticHostUser, error) {
out, err := s.svc.GetResource(ctx, name)
return out, trace.Wrap(err)
}

// CreateStaticHostUser creates a static host user.
func (s *StaticHostUserService) CreateStaticHostUser(ctx context.Context, in *userprovisioningpb.StaticHostUser) (*userprovisioningpb.StaticHostUser, error) {
out, err := s.svc.CreateResource(ctx, in)
return out, trace.Wrap(err)
}

// UpdateStaticHostUser updates a static host user.
func (s *StaticHostUserService) UpdateStaticHostUser(ctx context.Context, in *userprovisioningpb.StaticHostUser) (*userprovisioningpb.StaticHostUser, error) {
out, err := s.svc.UpdateResource(ctx, in)
return out, trace.Wrap(err)
}

// UpsertStaticHostUser upserts a static host user.
func (s *StaticHostUserService) UpsertStaticHostUser(ctx context.Context, in *userprovisioningpb.StaticHostUser) (*userprovisioningpb.StaticHostUser, error) {
out, err := s.svc.UpsertResource(ctx, in)
return out, trace.Wrap(err)
}

// DeleteStaticHostUser deletes a static host user. Note that this does not
// remove any host users created on nodes from the resource.
func (s *StaticHostUserService) DeleteStaticHostUser(ctx context.Context, name string) error {
return trace.Wrap(s.svc.DeleteResource(ctx, name))
}

// DeleteStaticHostUser deletes a static host user. Note that this does not
// remove any host users created on nodes from the resources.
func (s *StaticHostUserService) DeleteAllStaticHostUsers(ctx context.Context) error {
return trace.Wrap(s.svc.DeleteAllResources(ctx))
}
14 changes: 12 additions & 2 deletions lib/services/statichostuser.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,32 @@ import (
"github.com/gravitational/trace"
)

type StaticHostUsers interface {
// StaticHostUserService manages host users that should be created on SSH nodes.
type StaticHostUser interface {
// ListStaticHostUsers lists static host users.
ListStaticHostUsers(ctx context.Context, pageSize int, pageToken string) ([]*userprovisioningpb.StaticHostUser, string, error)
// GetStaticHostUser returns a static host user by name.
GetStaticHostUser(ctx context.Context, name string) (*userprovisioningpb.StaticHostUser, error)
// CreateStaticHostUser creates a static host user.
CreateStaticHostUser(ctx context.Context, in *userprovisioningpb.StaticHostUser) (*userprovisioningpb.StaticHostUser, error)
// UpdateStaticHostUser updates a static host user.
UpdateStaticHostUser(ctx context.Context, in *userprovisioningpb.StaticHostUser) (*userprovisioningpb.StaticHostUser, error)
// UpsertStaticHostUser upserts a static host user.
UpsertStaticHostUser(ctx context.Context, in *userprovisioningpb.StaticHostUser) (*userprovisioningpb.StaticHostUser, error)
// DeleteStaticHostUser deletes a static host user. Note that this does not
// remove any host users created on nodes from the resource.
DeleteStaticHostUser(ctx context.Context, name string) error
}

// MarshalStaticHostUser marshals a StaticHostUser resource to JSON.
func MarshalStaticHostUser(in *userprovisioningpb.StaticHostUser, opts ...MarshalOption) ([]byte, error) {
if err := ValidateStaticHostUser(in); err != nil {
return nil, trace.Wrap(err)
}
return MarshalProtoResource(in, opts...)
}

// UnmarshalStaticHostUser unmarshals a StaticHostUser resource from JSON.
func UnmarshalStaticHostUser(data []byte, opts ...MarshalOption) (*userprovisioningpb.StaticHostUser, error) {
out, err := UnmarshalProtoResource[*userprovisioningpb.StaticHostUser](data, opts...)
if err != nil {
Expand All @@ -55,7 +65,7 @@ func UnmarshalStaticHostUser(data []byte, opts ...MarshalOption) (*userprovision
}

func isValidUidOrGid(s string) bool {
// No uid/gid is OK
// No uid/gid is OK.
if s == "" {
return true
}
Expand Down

0 comments on commit 5033f87

Please sign in to comment.