From 5033f8797bc9ab7de52fa9c81729a5427d087035 Mon Sep 17 00:00:00 2001 From: Andrew Burke Date: Mon, 29 Jul 2024 14:46:23 -0700 Subject: [PATCH] Add godoc --- lib/services/local/statichostuser.go | 11 +++++++++++ lib/services/statichostuser.go | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/services/local/statichostuser.go b/lib/services/local/statichostuser.go index efe80f339e562..5913bc51897e1 100644 --- a/lib/services/local/statichostuser.go +++ b/lib/services/local/statichostuser.go @@ -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, @@ -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 { @@ -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)) } diff --git a/lib/services/statichostuser.go b/lib/services/statichostuser.go index 4653701e78eb8..b02555c3d4057 100644 --- a/lib/services/statichostuser.go +++ b/lib/services/statichostuser.go @@ -27,15 +27,24 @@ 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) @@ -43,6 +52,7 @@ func MarshalStaticHostUser(in *userprovisioningpb.StaticHostUser, opts ...Marsha 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 { @@ -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 }