From 88b0ecc643ee7e397c967df843a8c4265fbdae8d Mon Sep 17 00:00:00 2001 From: Benedikt Kulmann Date: Fri, 22 May 2020 09:19:06 +0200 Subject: [PATCH] Improve code doc --- pkg/service/v0/service.go | 6 ++++++ pkg/settings/settings.go | 5 +++-- pkg/store/filesystem/bundles.go | 6 ++++-- pkg/store/filesystem/paths.go | 4 ++-- pkg/store/filesystem/store.go | 8 ++++---- pkg/store/filesystem/values.go | 9 ++++++--- rollup.config.js | 2 +- 7 files changed, 26 insertions(+), 14 deletions(-) diff --git a/pkg/service/v0/service.go b/pkg/service/v0/service.go index aaad3aabe..4e7d3621f 100644 --- a/pkg/service/v0/service.go +++ b/pkg/service/v0/service.go @@ -22,6 +22,7 @@ func NewService(cfg *config.Config) Service { } } +// SaveSettingsBundle implements the BundleServiceHandler interface func (g Service) SaveSettingsBundle(c context.Context, req *proto.SaveSettingsBundleRequest, res *proto.SaveSettingsBundleResponse) error { req.SettingsBundle.Identifier = getFailsafeIdentifier(req.SettingsBundle.Identifier) r, err := g.manager.WriteBundle(req.SettingsBundle) @@ -32,6 +33,7 @@ func (g Service) SaveSettingsBundle(c context.Context, req *proto.SaveSettingsBu return nil } +// GetSettingsBundle implements the BundleServiceHandler interface func (g Service) GetSettingsBundle(c context.Context, req *proto.GetSettingsBundleRequest, res *proto.GetSettingsBundleResponse) error { r, err := g.manager.ReadBundle(getFailsafeIdentifier(req.Identifier)) if err != nil { @@ -41,6 +43,7 @@ func (g Service) GetSettingsBundle(c context.Context, req *proto.GetSettingsBund return nil } +// ListSettingsBundles implements the BundleServiceHandler interface func (g Service) ListSettingsBundles(c context.Context, req *proto.ListSettingsBundlesRequest, res *proto.ListSettingsBundlesResponse) error { r, err := g.manager.ListBundles(getFailsafeIdentifier(req.Identifier)) if err != nil { @@ -50,6 +53,7 @@ func (g Service) ListSettingsBundles(c context.Context, req *proto.ListSettingsB return nil } +// SaveSettingsValue implements the ValueServiceHandler interface func (g Service) SaveSettingsValue(c context.Context, req *proto.SaveSettingsValueRequest, res *proto.SaveSettingsValueResponse) error { req.SettingsValue.Identifier = getFailsafeIdentifier(req.SettingsValue.Identifier) r, err := g.manager.WriteValue(req.SettingsValue) @@ -60,6 +64,7 @@ func (g Service) SaveSettingsValue(c context.Context, req *proto.SaveSettingsVal return nil } +// GetSettingsValue implements the ValueServiceHandler interface func (g Service) GetSettingsValue(c context.Context, req *proto.GetSettingsValueRequest, res *proto.GetSettingsValueResponse) error { r, err := g.manager.ReadValue(getFailsafeIdentifier(req.Identifier)) if err != nil { @@ -69,6 +74,7 @@ func (g Service) GetSettingsValue(c context.Context, req *proto.GetSettingsValue return nil } +// ListSettingsValues implements the ValueServiceHandler interface func (g Service) ListSettingsValues(c context.Context, req *proto.ListSettingsValuesRequest, res *proto.ListSettingsValuesResponse) error { r, err := g.manager.ListValues(getFailsafeIdentifier(req.Identifier)) if err != nil { diff --git a/pkg/settings/settings.go b/pkg/settings/settings.go index 70d2905e9..0d26bfbb4 100644 --- a/pkg/settings/settings.go +++ b/pkg/settings/settings.go @@ -13,19 +13,20 @@ var ( // RegisterFunc stores store constructors type RegisterFunc func(*config.Config) Manager +// Manager combines service interfaces for abstraction of storage implementations type Manager interface { BundleManager ValueManager } -// BundleManager +// BundleManager is a bundle service interface for abstraction of storage implementations type BundleManager interface { ReadBundle(identifier *proto.Identifier) (*proto.SettingsBundle, error) WriteBundle(bundle *proto.SettingsBundle) (*proto.SettingsBundle, error) ListBundles(identifier *proto.Identifier) ([]*proto.SettingsBundle, error) } -// ValueManager +// ValueManager is a value service interface for abstraction of storage implementations type ValueManager interface { ReadValue(identifier *proto.Identifier) (*proto.SettingsValue, error) WriteValue(value *proto.SettingsValue) (*proto.SettingsValue, error) diff --git a/pkg/store/filesystem/bundles.go b/pkg/store/filesystem/bundles.go index 48710758f..fba9e04aa 100644 --- a/pkg/store/filesystem/bundles.go +++ b/pkg/store/filesystem/bundles.go @@ -48,7 +48,8 @@ func (s Store) ListBundles(identifier *proto.Identifier) ([]*proto.SettingsBundl return records, nil } -// Read tries to find a bundle by the given extension and key within the mountPath +// ReadBundle tries to find a bundle by the given identifier within the mountPath. +// Extension and BundleKey within the identifier are required. func (s Store) ReadBundle(identifier *proto.Identifier) (*proto.SettingsBundle, error) { if len(identifier.Extension) < 1 || len(identifier.BundleKey) < 1 { s.Logger.Error().Msg("extension and bundleKey cannot be empty") @@ -65,7 +66,8 @@ func (s Store) ReadBundle(identifier *proto.Identifier) (*proto.SettingsBundle, return &record, nil } -// Write writes the given record into a file within the mountPath +// WriteBundle writes the given record into a file within the mountPath +// Extension and BundleKey within the record identifier are required. func (s Store) WriteBundle(record *proto.SettingsBundle) (*proto.SettingsBundle, error) { if len(record.Identifier.Extension) < 1 || len(record.Identifier.BundleKey) < 1 { s.Logger.Error().Msg("extension and bundleKey cannot be empty") diff --git a/pkg/store/filesystem/paths.go b/pkg/store/filesystem/paths.go index 5b99762ea..0ea208f95 100644 --- a/pkg/store/filesystem/paths.go +++ b/pkg/store/filesystem/paths.go @@ -41,8 +41,8 @@ func (s Store) buildFilePathFromValue(value *proto.SettingsValue) string { } // Builds a unique file name from the given params -func (s Store) buildFilePathFromValueArgs(accountUuid string, extension string, bundleKey string) string { - extensionFolder := path.Join(s.mountPath, folderNameValues, accountUuid, extension) +func (s Store) buildFilePathFromValueArgs(accountUUID string, extension string, bundleKey string) string { + extensionFolder := path.Join(s.mountPath, folderNameValues, accountUUID, extension) s.ensureFolderExists(extensionFolder) return path.Join(extensionFolder, bundleKey+".json") } diff --git a/pkg/store/filesystem/store.go b/pkg/store/filesystem/store.go index f52a27bfb..c41e3ae09 100644 --- a/pkg/store/filesystem/store.go +++ b/pkg/store/filesystem/store.go @@ -11,9 +11,9 @@ import ( ) var ( - // StoreName is the default name for the settings store - StoreName = "ocis-settings-store" - managerName = "filesystem" + // Name is the default name for the settings store + Name = "ocis-settings-store" + managerName = "filesystem" ) // Store interacts with the filesystem to manage settings information @@ -26,7 +26,7 @@ type Store struct { func New(cfg *config.Config) settings.Manager { s := Store{} - dest := path.Join(cfg.Storage.RootMountPath, StoreName) + dest := path.Join(cfg.Storage.RootMountPath, Name) if _, err := os.Stat(dest); err != nil { s.Logger.Info().Msgf("creating container on %v", dest) err := os.MkdirAll(dest, 0700) diff --git a/pkg/store/filesystem/values.go b/pkg/store/filesystem/values.go index 7f4fa3c28..3204fe96a 100644 --- a/pkg/store/filesystem/values.go +++ b/pkg/store/filesystem/values.go @@ -10,7 +10,8 @@ import ( "path/filepath" ) -// Tries to find a value by the given identifier attributes within the mountPath +// ReadValue tries to find a value by the given identifier attributes within the mountPath +// All identifier fields are required. func (s Store) ReadValue(identifier *proto.Identifier) (*proto.SettingsValue, error) { if len(identifier.AccountUuid) < 1 || len(identifier.Extension) < 1 || len(identifier.BundleKey) < 1 || len(identifier.SettingKey) < 1 { s.Logger.Error().Msg("account-uuid, extension, bundle and setting are required") @@ -29,7 +30,8 @@ func (s Store) ReadValue(identifier *proto.Identifier) (*proto.SettingsValue, er return nil, gstatus.Error(codes.NotFound, "SettingsValue not set") } -// Writes the given SettingsValue into a file within the mountPath +// WriteValue writes the given SettingsValue into a file within the mountPath +// All identifier fields within the value are required. func (s Store) WriteValue(value *proto.SettingsValue) (*proto.SettingsValue, error) { if len(value.Identifier.AccountUuid) < 1 || len(value.Identifier.Extension) < 1 || len(value.Identifier.BundleKey) < 1 || len(value.Identifier.SettingKey) < 1 { s.Logger.Error().Msg("all identifier keys are required") @@ -48,7 +50,8 @@ func (s Store) WriteValue(value *proto.SettingsValue) (*proto.SettingsValue, err return value, nil } -// Reads all values within the scope of the given identifier +// ListValues reads all values within the scope of the given identifier +// AccountUuid is required. func (s Store) ListValues(identifier *proto.Identifier) ([]*proto.SettingsValue, error) { if len(identifier.AccountUuid) < 1 { s.Logger.Error().Msg("account-uuid is required") diff --git a/rollup.config.js b/rollup.config.js index cadac1e91..a5101262b 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,5 +1,5 @@ import vue from 'rollup-plugin-vue' -import { terser } from 'rollup-plugin-terser' +import terser from 'rollup-plugin-terser' import replace from '@rollup/plugin-replace' import filesize from 'rollup-plugin-filesize' import resolve from 'rollup-plugin-node-resolve'