Improve code doc

This commit is contained in:
Benedikt Kulmann
2020-05-22 09:19:06 +02:00
parent ea49cedac4
commit 88b0ecc643
7 changed files with 26 additions and 14 deletions
+6
View File
@@ -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 {
+3 -2
View File
@@ -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)
+4 -2
View File
@@ -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")
+2 -2
View File
@@ -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")
}
+4 -4
View File
@@ -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)
+6 -3
View File
@@ -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")
+1 -1
View File
@@ -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'