From 4f42c601e1316877bd70b99ca4ff351b8aea72f2 Mon Sep 17 00:00:00 2001 From: Vadym Popov Date: Wed, 18 Sep 2024 11:20:01 -0400 Subject: [PATCH] Drop AutoUpdateServiceClient helper Rename comments for consistency --- api/client/client.go | 11 ++++------- api/types/autoupdate/config_test.go | 2 +- api/types/autoupdate/version_test.go | 2 +- lib/auth/authclient/api.go | 8 ++++---- lib/auth/authclient/clt.go | 4 ---- lib/cache/cache.go | 4 ++-- lib/services/autoupdates.go | 20 ++++++++++---------- lib/services/local/autoupdate.go | 22 +++++++++++----------- lib/services/local/autoupdate_test.go | 4 ++-- 9 files changed, 35 insertions(+), 42 deletions(-) diff --git a/api/client/client.go b/api/client/client.go index e221e3bcb9b57..e5eedbdd9d536 100644 --- a/api/client/client.go +++ b/api/client/client.go @@ -891,11 +891,6 @@ func (c *Client) GetVnetConfig(ctx context.Context) (*vnet.VnetConfig, error) { return c.VnetConfigServiceClient().GetVnetConfig(ctx, &vnet.GetVnetConfigRequest{}) } -// AutoUpdateServiceClient returns an unadorned client for the AutoUpdate service. -func (c *Client) AutoUpdateServiceClient() autoupdatev1pb.AutoUpdateServiceClient { - return autoupdatev1pb.NewAutoUpdateServiceClient(c.conn) -} - // Ping gets basic info about the auth server. func (c *Client) Ping(ctx context.Context) (proto.PingResponse, error) { rsp, err := c.grpc.Ping(ctx, &proto.PingRequest{}) @@ -2871,7 +2866,8 @@ func (c *Client) GetClusterAuditConfig(ctx context.Context) (types.ClusterAuditC // GetAutoUpdateConfig gets AutoUpdateConfig resource. func (c *Client) GetAutoUpdateConfig(ctx context.Context) (*autoupdatev1pb.AutoUpdateConfig, error) { - resp, err := c.AutoUpdateServiceClient().GetAutoUpdateConfig(ctx, &autoupdatev1pb.GetAutoUpdateConfigRequest{}) + client := autoupdatev1pb.NewAutoUpdateServiceClient(c.conn) + resp, err := client.GetAutoUpdateConfig(ctx, &autoupdatev1pb.GetAutoUpdateConfigRequest{}) if err != nil { return nil, trace.Wrap(err) } @@ -2880,7 +2876,8 @@ func (c *Client) GetAutoUpdateConfig(ctx context.Context) (*autoupdatev1pb.AutoU // GetAutoUpdateVersion gets AutoUpdateVersion resource. func (c *Client) GetAutoUpdateVersion(ctx context.Context) (*autoupdatev1pb.AutoUpdateVersion, error) { - resp, err := c.AutoUpdateServiceClient().GetAutoUpdateVersion(ctx, &autoupdatev1pb.GetAutoUpdateVersionRequest{}) + client := autoupdatev1pb.NewAutoUpdateServiceClient(c.conn) + resp, err := client.GetAutoUpdateVersion(ctx, &autoupdatev1pb.GetAutoUpdateVersionRequest{}) if err != nil { return nil, trace.Wrap(err) } diff --git a/api/types/autoupdate/config_test.go b/api/types/autoupdate/config_test.go index 4ebf29a536841..2ee33dc5bf2b3 100644 --- a/api/types/autoupdate/config_test.go +++ b/api/types/autoupdate/config_test.go @@ -30,7 +30,7 @@ import ( "github.com/gravitational/teleport/api/types" ) -// TestNewAutoUpdateConfig verifies validation for auto update config resource. +// TestNewAutoUpdateConfig verifies validation for AutoUpdateConfig resource. func TestNewAutoUpdateConfig(t *testing.T) { tests := []struct { name string diff --git a/api/types/autoupdate/version_test.go b/api/types/autoupdate/version_test.go index 5f6729ec42f5b..5fe4f167a037e 100644 --- a/api/types/autoupdate/version_test.go +++ b/api/types/autoupdate/version_test.go @@ -30,7 +30,7 @@ import ( "github.com/gravitational/teleport/api/types" ) -// TestNewAutoUpdateVersion verifies validation for auto update version resource. +// TestNewAutoUpdateVersion verifies validation for AutoUpdateVersion resource. func TestNewAutoUpdateVersion(t *testing.T) { tests := []struct { name string diff --git a/lib/auth/authclient/api.go b/lib/auth/authclient/api.go index cb1a5307a29d0..edce17d68ccea 100644 --- a/lib/auth/authclient/api.go +++ b/lib/auth/authclient/api.go @@ -308,10 +308,10 @@ type ReadProxyAccessPoint interface { // GetUserGroup returns the specified user group resources. GetUserGroup(ctx context.Context, name string) (types.UserGroup, error) - // GetAutoUpdateConfig gets the autoupdate config from the backend. + // GetAutoUpdateConfig gets the AutoUpdateConfig from the backend. GetAutoUpdateConfig(ctx context.Context) (*autoupdate.AutoUpdateConfig, error) - // GetAutoUpdateVersion gets the autoupdate version from the backend. + // GetAutoUpdateVersion gets the AutoUpdateVersion from the backend. GetAutoUpdateVersion(ctx context.Context) (*autoupdate.AutoUpdateVersion, error) } @@ -1183,10 +1183,10 @@ type Cache interface { // DatabaseObjectsGetter defines methods for fetching database objects. services.DatabaseObjectsGetter - // GetAutoUpdateConfig gets the autoupdate config from the backend. + // GetAutoUpdateConfig gets the AutoUpdateConfig from the backend. GetAutoUpdateConfig(ctx context.Context) (*autoupdate.AutoUpdateConfig, error) - // GetAutoUpdateVersion gets the autoupdate version from the backend. + // GetAutoUpdateVersion gets the AutoUpdateVersion from the backend. GetAutoUpdateVersion(ctx context.Context) (*autoupdate.AutoUpdateVersion, error) // GetAccessGraphSettings returns the access graph settings. diff --git a/lib/auth/authclient/clt.go b/lib/auth/authclient/clt.go index 554bf9aa4bc8d..ddae1daca76e0 100644 --- a/lib/auth/authclient/clt.go +++ b/lib/auth/authclient/clt.go @@ -38,7 +38,6 @@ import ( "github.com/gravitational/teleport/api/client/secreport" apidefaults "github.com/gravitational/teleport/api/defaults" accessgraphsecretsv1pb "github.com/gravitational/teleport/api/gen/proto/go/teleport/accessgraph/v1" - autoupdatev1pb "github.com/gravitational/teleport/api/gen/proto/go/teleport/autoupdate/v1" clusterconfigpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/clusterconfig/v1" dbobjectimportrulev1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/dbobjectimportrule/v1" devicepb "github.com/gravitational/teleport/api/gen/proto/go/teleport/devicetrust/v1" @@ -1824,9 +1823,6 @@ type ClientI interface { // will return "not implemented" errors (as per the default gRPC behavior). StaticHostUserClient() services.StaticHostUser - // AutoUpdateServiceClient returns a AutoUpdate service client. - AutoUpdateServiceClient() autoupdatev1pb.AutoUpdateServiceClient - // CloneHTTPClient creates a new HTTP client with the same configuration. CloneHTTPClient(params ...roundtrip.ClientParam) (*HTTPClient, error) diff --git a/lib/cache/cache.go b/lib/cache/cache.go index 4adebc8645618..3690d3e2fd762 100644 --- a/lib/cache/cache.go +++ b/lib/cache/cache.go @@ -1902,7 +1902,7 @@ type autoUpdateCacheKey struct { var _ map[autoUpdateCacheKey]struct{} // compile-time hashability check -// GetAutoUpdateConfig gets the autoupdate config from the backend. +// GetAutoUpdateConfig gets the AutoUpdateConfig from the backend. func (c *Cache) GetAutoUpdateConfig(ctx context.Context) (*autoupdate.AutoUpdateConfig, error) { ctx, span := c.Tracer.Start(ctx, "cache/GetAutoUpdateConfig") defer span.End() @@ -1925,7 +1925,7 @@ func (c *Cache) GetAutoUpdateConfig(ctx context.Context) (*autoupdate.AutoUpdate return rg.reader.GetAutoUpdateConfig(ctx) } -// GetAutoUpdateVersion gets the autoupdate version from the backend. +// GetAutoUpdateVersion gets the AutoUpdateVersion from the backend. func (c *Cache) GetAutoUpdateVersion(ctx context.Context) (*autoupdate.AutoUpdateVersion, error) { ctx, span := c.Tracer.Start(ctx, "cache/GetAutoUpdateVersion") defer span.End() diff --git a/lib/services/autoupdates.go b/lib/services/autoupdates.go index 3079f355d7ff8..5fa7a4eed4677 100644 --- a/lib/services/autoupdates.go +++ b/lib/services/autoupdates.go @@ -26,10 +26,10 @@ import ( // AutoUpdateServiceGetter defines only read-only service methods. type AutoUpdateServiceGetter interface { - // GetAutoUpdateConfig gets the autoupdate configuration from the backend. + // GetAutoUpdateConfig gets the AutoUpdateConfig singleton resource. GetAutoUpdateConfig(ctx context.Context) (*autoupdate.AutoUpdateConfig, error) - // GetAutoUpdateVersion gets the autoupdate version from the backend. + // GetAutoUpdateVersion gets the AutoUpdateVersion singleton resource. GetAutoUpdateVersion(ctx context.Context) (*autoupdate.AutoUpdateVersion, error) } @@ -37,27 +37,27 @@ type AutoUpdateServiceGetter interface { type AutoUpdateService interface { AutoUpdateServiceGetter - // CreateAutoUpdateConfig creates an auto update configuration. + // CreateAutoUpdateConfig creates the AutoUpdateConfig singleton resource. CreateAutoUpdateConfig(ctx context.Context, config *autoupdate.AutoUpdateConfig) (*autoupdate.AutoUpdateConfig, error) - // UpdateAutoUpdateConfig updates an auto update configuration. + // UpdateAutoUpdateConfig updates the AutoUpdateConfig singleton resource. UpdateAutoUpdateConfig(ctx context.Context, config *autoupdate.AutoUpdateConfig) (*autoupdate.AutoUpdateConfig, error) - // UpsertAutoUpdateConfig sets an auto update configuration. + // UpsertAutoUpdateConfig sets the AutoUpdateConfig singleton resource. UpsertAutoUpdateConfig(ctx context.Context, c *autoupdate.AutoUpdateConfig) (*autoupdate.AutoUpdateConfig, error) - // DeleteAutoUpdateConfig deletes the auto update configuration from the backend. + // DeleteAutoUpdateConfig deletes the AutoUpdateConfig singleton resource. DeleteAutoUpdateConfig(ctx context.Context) error - // CreateAutoUpdateVersion creates an auto update version. + // CreateAutoUpdateVersion creates the AutoUpdateVersion singleton resource. CreateAutoUpdateVersion(ctx context.Context, config *autoupdate.AutoUpdateVersion) (*autoupdate.AutoUpdateVersion, error) - // UpdateAutoUpdateVersion updates an auto update version. + // UpdateAutoUpdateVersion updates the AutoUpdateVersion singleton resource. UpdateAutoUpdateVersion(ctx context.Context, config *autoupdate.AutoUpdateVersion) (*autoupdate.AutoUpdateVersion, error) - // UpsertAutoUpdateVersion sets an auto update version. + // UpsertAutoUpdateVersion sets the AutoUpdateVersion singleton resource. UpsertAutoUpdateVersion(ctx context.Context, c *autoupdate.AutoUpdateVersion) (*autoupdate.AutoUpdateVersion, error) - // DeleteAutoUpdateVersion deletes the auto update version from the backend. + // DeleteAutoUpdateVersion deletes the AutoUpdateVersion singleton resource. DeleteAutoUpdateVersion(ctx context.Context) error } diff --git a/lib/services/local/autoupdate.go b/lib/services/local/autoupdate.go index a1a04a38ea654..f6e6a23abd2b1 100644 --- a/lib/services/local/autoupdate.go +++ b/lib/services/local/autoupdate.go @@ -36,7 +36,7 @@ const ( autoUpdateVersionPrefix = "auto_update_version" ) -// AutoUpdateService is responsible for managing auto update configuration and version. +// AutoUpdateService is responsible for managing AutoUpdateConfig and AutoUpdateVersion singleton resources. type AutoUpdateService struct { config *generic.ServiceWrapper[*autoupdate.AutoUpdateConfig] version *generic.ServiceWrapper[*autoupdate.AutoUpdateVersion] @@ -81,7 +81,7 @@ func NewAutoUpdateService(backend backend.Backend) (*AutoUpdateService, error) { }, nil } -// CreateAutoUpdateConfig creates an auto update configuration singleton. +// CreateAutoUpdateConfig creates the AutoUpdateConfig singleton resource. func (s *AutoUpdateService) CreateAutoUpdateConfig( ctx context.Context, c *autoupdate.AutoUpdateConfig, @@ -90,7 +90,7 @@ func (s *AutoUpdateService) CreateAutoUpdateConfig( return config, trace.Wrap(err) } -// UpdateAutoUpdateConfig updates an auto update configuration singleton. +// UpdateAutoUpdateConfig updates the AutoUpdateConfig singleton resource. func (s *AutoUpdateService) UpdateAutoUpdateConfig( ctx context.Context, c *autoupdate.AutoUpdateConfig, @@ -99,7 +99,7 @@ func (s *AutoUpdateService) UpdateAutoUpdateConfig( return config, trace.Wrap(err) } -// UpsertAutoUpdateConfig sets an auto update configuration. +// UpsertAutoUpdateConfig sets the AutoUpdateConfig singleton resource. func (s *AutoUpdateService) UpsertAutoUpdateConfig( ctx context.Context, c *autoupdate.AutoUpdateConfig, @@ -108,18 +108,18 @@ func (s *AutoUpdateService) UpsertAutoUpdateConfig( return config, trace.Wrap(err) } -// GetAutoUpdateConfig gets the auto update configuration from the backend. +// GetAutoUpdateConfig gets the AutoUpdateConfig singleton resource. func (s *AutoUpdateService) GetAutoUpdateConfig(ctx context.Context) (*autoupdate.AutoUpdateConfig, error) { config, err := s.config.GetResource(ctx, types.MetaNameAutoUpdateConfig) return config, trace.Wrap(err) } -// DeleteAutoUpdateConfig deletes the auto update configuration from the backend. +// DeleteAutoUpdateConfig deletes the AutoUpdateConfig singleton resource. func (s *AutoUpdateService) DeleteAutoUpdateConfig(ctx context.Context) error { return trace.Wrap(s.config.DeleteResource(ctx, types.MetaNameAutoUpdateConfig)) } -// CreateAutoUpdateVersion creates an autoupdate version resource. +// CreateAutoUpdateVersion creates the AutoUpdateVersion singleton resource. func (s *AutoUpdateService) CreateAutoUpdateVersion( ctx context.Context, v *autoupdate.AutoUpdateVersion, @@ -128,7 +128,7 @@ func (s *AutoUpdateService) CreateAutoUpdateVersion( return version, trace.Wrap(err) } -// UpdateAutoUpdateVersion updates an autoupdate version resource. +// UpdateAutoUpdateVersion updates the AutoUpdateVersion singleton resource. func (s *AutoUpdateService) UpdateAutoUpdateVersion( ctx context.Context, v *autoupdate.AutoUpdateVersion, @@ -137,7 +137,7 @@ func (s *AutoUpdateService) UpdateAutoUpdateVersion( return version, trace.Wrap(err) } -// UpsertAutoUpdateVersion sets autoupdate version resource. +// UpsertAutoUpdateVersion sets the AutoUpdateVersion singleton resource. func (s *AutoUpdateService) UpsertAutoUpdateVersion( ctx context.Context, v *autoupdate.AutoUpdateVersion, @@ -146,13 +146,13 @@ func (s *AutoUpdateService) UpsertAutoUpdateVersion( return version, trace.Wrap(err) } -// GetAutoUpdateVersion gets the auto update version from the backend. +// GetAutoUpdateVersion gets the AutoUpdateVersion singleton resource. func (s *AutoUpdateService) GetAutoUpdateVersion(ctx context.Context) (*autoupdate.AutoUpdateVersion, error) { version, err := s.version.GetResource(ctx, types.MetaNameAutoUpdateVersion) return version, trace.Wrap(err) } -// DeleteAutoUpdateVersion deletes the auto update version from the backend. +// DeleteAutoUpdateVersion deletes the AutoUpdateVersion singleton resource. func (s *AutoUpdateService) DeleteAutoUpdateVersion(ctx context.Context) error { return trace.Wrap(s.version.DeleteResource(ctx, types.MetaNameAutoUpdateVersion)) } diff --git a/lib/services/local/autoupdate_test.go b/lib/services/local/autoupdate_test.go index 7488aebb4372c..77e13937ac47a 100644 --- a/lib/services/local/autoupdate_test.go +++ b/lib/services/local/autoupdate_test.go @@ -36,7 +36,7 @@ import ( ) // TestAutoUpdateServiceConfigCRUD verifies get/create/update/upsert/delete methods of the backend service -// for auto update config resource. +// for AutoUpdateConfig resource. func TestAutoUpdateServiceConfigCRUD(t *testing.T) { t.Parallel() @@ -92,7 +92,7 @@ func TestAutoUpdateServiceConfigCRUD(t *testing.T) { } // TestAutoUpdateServiceVersionCRUD verifies get/create/update/upsert/delete methods of the backend service -// for auto update version resource. +// for AutoUpdateVersion resource. func TestAutoUpdateServiceVersionCRUD(t *testing.T) { t.Parallel()