From 4b7a365781ebdd019966d1a29d16993764ac5f97 Mon Sep 17 00:00:00 2001 From: David Christofas Date: Tue, 10 May 2022 09:24:29 +0200 Subject: [PATCH] add description tags to thumbnails config --- changelog/unreleased/thumbnails-env-doc.md | 5 +++ extensions/thumbnails/pkg/config/config.go | 21 +++++------ extensions/thumbnails/pkg/config/debug.go | 2 +- .../pkg/config/defaults/defaultconfig.go | 8 ++--- extensions/thumbnails/pkg/config/grpc.go | 2 +- extensions/thumbnails/pkg/config/http.go | 4 +-- extensions/thumbnails/pkg/config/log.go | 8 ++--- .../thumbnails/pkg/config/parser/parse.go | 5 --- extensions/thumbnails/pkg/config/tracing.go | 8 ++--- .../pkg/thumbnail/imgsource/filesystem.go | 34 ------------------ ocis/pkg/init/init.go | 35 ++++++++++++------- 11 files changed, 51 insertions(+), 81 deletions(-) create mode 100644 changelog/unreleased/thumbnails-env-doc.md delete mode 100644 extensions/thumbnails/pkg/thumbnail/imgsource/filesystem.go diff --git a/changelog/unreleased/thumbnails-env-doc.md b/changelog/unreleased/thumbnails-env-doc.md new file mode 100644 index 00000000000..e7651cd4937 --- /dev/null +++ b/changelog/unreleased/thumbnails-env-doc.md @@ -0,0 +1,5 @@ +Enhancement: Add description tags to the thumbnails config structs + +Added description tags to the config structs in the thumbnails service so they will be included in the config documentation. + +https://github.com/owncloud/ocis/pull/3752 diff --git a/extensions/thumbnails/pkg/config/config.go b/extensions/thumbnails/pkg/config/config.go index 5592422174a..a26f20c806d 100644 --- a/extensions/thumbnails/pkg/config/config.go +++ b/extensions/thumbnails/pkg/config/config.go @@ -26,22 +26,17 @@ type Config struct { // FileSystemStorage defines the available filesystem storage configuration. type FileSystemStorage struct { - RootDirectory string `yaml:"root_directory" env:"THUMBNAILS_FILESYSTEMSTORAGE_ROOT"` -} - -// FileSystemSource defines the available filesystem source configuration. -type FileSystemSource struct { - BasePath string `yaml:"base_path"` + RootDirectory string `yaml:"root_directory" env:"THUMBNAILS_FILESYSTEMSTORAGE_ROOT" desc:"The directory where the filesystem storage will store the thumbnails."` } // Thumbnail defines the available thumbnail related configuration. type Thumbnail struct { - Resolutions []string `yaml:"resolutions"` + Resolutions []string `yaml:"resolutions" env:"THUMBNAILS_RESOLUTIONS" desc:"The supported target resolutions in the format WidthxHeight e.g. 32x32. You can provide multiple resolutions seperated by a comma."` FileSystemStorage FileSystemStorage `yaml:"filesystem_storage"` - WebdavAllowInsecure bool `yaml:"webdav_allow_insecure" env:"OCIS_INSECURE;THUMBNAILS_WEBDAVSOURCE_INSECURE"` - CS3AllowInsecure bool `yaml:"cs3_allow_insecure" env:"OCIS_INSECURE;THUMBNAILS_CS3SOURCE_INSECURE"` - RevaGateway string `yaml:"reva_gateway" env:"REVA_GATEWAY"` //TODO: use REVA config - FontMapFile string `yaml:"font_map_file" env:"THUMBNAILS_TXT_FONTMAP_FILE"` - TransferSecret string `yaml:"transfer_secret" env:"STORAGE_TRANSFER_TOKEN;THUMBNAILS_TRANSFER_TOKEN"` - DataEndpoint string `yaml:"data_endpoint" env:"THUMBNAILS_DATA_ENDPOINT"` + WebdavAllowInsecure bool `yaml:"webdav_allow_insecure" env:"OCIS_INSECURE;THUMBNAILS_WEBDAVSOURCE_INSECURE" desc:"Ignore untrusted SSL certificates when connecting to the webdav source."` + CS3AllowInsecure bool `yaml:"cs3_allow_insecure" env:"OCIS_INSECURE;THUMBNAILS_CS3SOURCE_INSECURE" desc:"Ignore untrusted SSL certificates when connecting to the CS3 source."` + RevaGateway string `yaml:"reva_gateway" env:"REVA_GATEWAY" desc:"The CS3 gateway endpoint"` //TODO: use REVA config + FontMapFile string `yaml:"font_map_file" env:"THUMBNAILS_TXT_FONTMAP_FILE" desc:"The path to a font file for txt thumbnails."` + TransferSecret string `yaml:"transfer_secret" env:"THUMBNAILS_TRANSFER_TOKEN" desc:"The secret to sign JWT to download the actual thumbnail file."` + DataEndpoint string `yaml:"data_endpoint" env:"THUMBNAILS_DATA_ENDPOINT" desc:"The HTTP endpoint where the actual thumbnail file can be downloaded."` } diff --git a/extensions/thumbnails/pkg/config/debug.go b/extensions/thumbnails/pkg/config/debug.go index 65148e1069c..ee9d8f48333 100644 --- a/extensions/thumbnails/pkg/config/debug.go +++ b/extensions/thumbnails/pkg/config/debug.go @@ -2,7 +2,7 @@ package config // Debug defines the available debug configuration. type Debug struct { - Addr string `yaml:"addr" env:"THUMBNAILS_DEBUG_ADDR"` + Addr string `yaml:"addr" env:"THUMBNAILS_DEBUG_ADDR" desc:"The debug address"` Token string `yaml:"token" env:"THUMBNAILS_DEBUG_TOKEN"` Pprof bool `yaml:"pprof" env:"THUMBNAILS_DEBUG_PPROF"` Zpages bool `yaml:"zpages" env:"THUMBNAILS_DEBUG_ZPAGES"` diff --git a/extensions/thumbnails/pkg/config/defaults/defaultconfig.go b/extensions/thumbnails/pkg/config/defaults/defaultconfig.go index b3d2203c9b3..3a179e0f5e6 100644 --- a/extensions/thumbnails/pkg/config/defaults/defaultconfig.go +++ b/extensions/thumbnails/pkg/config/defaults/defaultconfig.go @@ -2,6 +2,7 @@ package defaults import ( "path" + "strings" "github.com/owncloud/ocis/v2/extensions/thumbnails/pkg/config" "github.com/owncloud/ocis/v2/ocis-pkg/config/defaults" @@ -70,12 +71,11 @@ func EnsureDefaults(cfg *config.Config) { } else if cfg.Tracing == nil { cfg.Tracing = &config.Tracing{} } - - if cfg.Thumbnail.TransferSecret == "" && cfg.Commons != nil && cfg.Commons.TransferSecret != "" { - cfg.Thumbnail.TransferSecret = cfg.Commons.TransferSecret - } } func Sanitize(cfg *config.Config) { // nothing to sanitize here atm + if len(cfg.Thumbnail.Resolutions) == 1 && strings.Contains(cfg.Thumbnail.Resolutions[0], ",") { + cfg.Thumbnail.Resolutions = strings.Split(cfg.Thumbnail.Resolutions[0], ",") + } } diff --git a/extensions/thumbnails/pkg/config/grpc.go b/extensions/thumbnails/pkg/config/grpc.go index 4f742360916..6852c0eb8c7 100644 --- a/extensions/thumbnails/pkg/config/grpc.go +++ b/extensions/thumbnails/pkg/config/grpc.go @@ -2,6 +2,6 @@ package config // GRPC defines the available grpc configuration. type GRPC struct { - Addr string `yaml:"addr" env:"THUMBNAILS_GRPC_ADDR"` + Addr string `yaml:"addr" env:"THUMBNAILS_GRPC_ADDR" desc:"The address off the grpc service."` Namespace string `yaml:"-"` } diff --git a/extensions/thumbnails/pkg/config/http.go b/extensions/thumbnails/pkg/config/http.go index db3272e8b70..05e76c9df44 100644 --- a/extensions/thumbnails/pkg/config/http.go +++ b/extensions/thumbnails/pkg/config/http.go @@ -2,7 +2,7 @@ package config // HTTP defines the available http configuration. type HTTP struct { - Addr string `yaml:"addr" env:"THUMBNAILS_HTTP_ADDR"` - Root string `yaml:"root" env:"THUMBNAILS_HTTP_ROOT"` + Addr string `yaml:"addr" env:"THUMBNAILS_HTTP_ADDR" desc:"The address of the HTTP service."` + Root string `yaml:"root" env:"THUMBNAILS_HTTP_ROOT" desc:"The root path of the HTTP service."` Namespace string `yaml:"-"` } diff --git a/extensions/thumbnails/pkg/config/log.go b/extensions/thumbnails/pkg/config/log.go index a9b19f07077..584b7262d56 100644 --- a/extensions/thumbnails/pkg/config/log.go +++ b/extensions/thumbnails/pkg/config/log.go @@ -2,8 +2,8 @@ package config // Log defines the available log configuration. type Log struct { - Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;THUMBNAILS_LOG_LEVEL"` - Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;THUMBNAILS_LOG_PRETTY"` - Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;THUMBNAILS_LOG_COLOR"` - File string `mapstructure:"file" env:"OCIS_LOG_FILE;THUMBNAILS_LOG_FILE"` + Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;THUMBNAILS_LOG_LEVEL" desc:"The log level."` + Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;THUMBNAILS_LOG_PRETTY" desc:"Enable pretty logs."` + Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;THUMBNAILS_LOG_COLOR" desc:"Enable colored logs."` + File string `mapstructure:"file" env:"OCIS_LOG_FILE;THUMBNAILS_LOG_FILE" desc:"The path to the log file when logging to file."` } diff --git a/extensions/thumbnails/pkg/config/parser/parse.go b/extensions/thumbnails/pkg/config/parser/parse.go index 936ce8c6c8d..0a36b2a32bd 100644 --- a/extensions/thumbnails/pkg/config/parser/parse.go +++ b/extensions/thumbnails/pkg/config/parser/parse.go @@ -6,7 +6,6 @@ import ( "github.com/owncloud/ocis/v2/extensions/thumbnails/pkg/config" "github.com/owncloud/ocis/v2/extensions/thumbnails/pkg/config/defaults" ociscfg "github.com/owncloud/ocis/v2/ocis-pkg/config" - "github.com/owncloud/ocis/v2/ocis-pkg/shared" "github.com/owncloud/ocis/v2/ocis-pkg/config/envdecode" ) @@ -35,9 +34,5 @@ func ParseConfig(cfg *config.Config) error { } func Validate(cfg *config.Config) error { - if cfg.Thumbnail.TransferSecret == "" { - return shared.MissingRevaTransferSecretError(cfg.Service.Name) - } - return nil } diff --git a/extensions/thumbnails/pkg/config/tracing.go b/extensions/thumbnails/pkg/config/tracing.go index 1446c2d462e..accc1c80fdf 100644 --- a/extensions/thumbnails/pkg/config/tracing.go +++ b/extensions/thumbnails/pkg/config/tracing.go @@ -2,8 +2,8 @@ package config // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `yaml:"enabled" env:"OCIS_TRACING_ENABLED;THUMBNAILS_TRACING_ENABLED"` - Type string `yaml:"type" env:"OCIS_TRACING_TYPE;THUMBNAILS_TRACING_TYPE"` - Endpoint string `yaml:"endpoint" env:"OCIS_TRACING_ENDPOINT;THUMBNAILS_TRACING_ENDPOINT"` - Collector string `yaml:"collector" env:"OCIS_TRACING_COLLECTOR;THUMBNAILS_TRACING_COLLECTOR"` + Enabled bool `yaml:"enabled" env:"OCIS_TRACING_ENABLED;THUMBNAILS_TRACING_ENABLED" desc:"Enable tracing."` + Type string `yaml:"type" env:"OCIS_TRACING_TYPE;THUMBNAILS_TRACING_TYPE" desc:"The tracing type."` + Endpoint string `yaml:"endpoint" env:"OCIS_TRACING_ENDPOINT;THUMBNAILS_TRACING_ENDPOINT" desc:"The endpoint of the tracing service."` + Collector string `yaml:"collector" env:"OCIS_TRACING_COLLECTOR;THUMBNAILS_TRACING_COLLECTOR" desc:"The tracing collector."` } diff --git a/extensions/thumbnails/pkg/thumbnail/imgsource/filesystem.go b/extensions/thumbnails/pkg/thumbnail/imgsource/filesystem.go deleted file mode 100644 index c3924140ac8..00000000000 --- a/extensions/thumbnails/pkg/thumbnail/imgsource/filesystem.go +++ /dev/null @@ -1,34 +0,0 @@ -package imgsource - -import ( - "context" - "io" - "os" - "path/filepath" - - "github.com/owncloud/ocis/v2/extensions/thumbnails/pkg/config" - "github.com/pkg/errors" -) - -// NewFileSystemSource return a new FileSystem instance -func NewFileSystemSource(cfg config.FileSystemSource) FileSystem { - return FileSystem{ - basePath: cfg.BasePath, - } -} - -// FileSystem is an image source using the local file system -type FileSystem struct { - basePath string -} - -// Get retrieves an image from the filesystem. -func (s FileSystem) Get(ctx context.Context, file string) (io.ReadCloser, error) { - imgPath := filepath.Join(s.basePath, file) - f, err := os.Open(filepath.Clean(imgPath)) - if err != nil { - return nil, errors.Wrapf(err, "failed to load the file %s from %s", file, imgPath) - } - - return f, nil -} diff --git a/ocis/pkg/init/init.go b/ocis/pkg/init/init.go index 3ccd8768bfb..a4411ac2db5 100644 --- a/ocis/pkg/init/init.go +++ b/ocis/pkg/init/init.go @@ -14,8 +14,10 @@ import ( "gopkg.in/yaml.v2" ) -const configFilename string = "ocis.yaml" // TODO: use also a constant for reading this file -const passwordLength int = 32 +const ( + configFilename = "ocis.yaml" // TODO: use also a constant for reading this file + passwordLength = 32 +) type TokenManager struct { JWTSecret string `yaml:"jwt_secret"` @@ -75,11 +77,12 @@ type UsersAndGroupsExtension struct { } type ThumbnailSettings struct { - WebdavAllowInsecure bool `yaml:"webdav_allow_insecure"` - Cs3AllowInsecure bool `yaml:"cs3_allow_insecure"` + TransferSecret string `yaml:"transfer_secret"` + WebdavAllowInsecure bool `yaml:"webdav_allow_insecure"` + Cs3AllowInsecure bool `yaml:"cs3_allow_insecure"` } -type ThumbNailExtension struct { +type ThumbnailExtension struct { Thumbnail ThumbnailSettings } @@ -114,7 +117,7 @@ type OcisConfig struct { StorageSystem DataProviderInsecureSettings `yaml:"storage_system"` StorageUsers DataProviderInsecureSettings `yaml:"storage_users"` Ocdav InsecureExtension - Thumbnails ThumbNailExtension + Thumbnails ThumbnailExtension } func checkConfigPath(configPath string) error { @@ -200,7 +203,11 @@ func CreateConfig(insecure, forceOverwrite bool, configPath, adminPassword strin } revaTransferSecret, err := generators.GenerateRandomPassword(passwordLength) if err != nil { - return fmt.Errorf("could not generate random password for machineauthsecret: %s", err) + return fmt.Errorf("could not generate random password for revaTransferSecret: %s", err) + } + thumbnailsTransferSecret, err := generators.GenerateRandomPassword(passwordLength) + if err != nil { + return fmt.Errorf("could not generate random password for thumbnailsTransferSecret: %s", err) } cfg := OcisConfig{ @@ -253,6 +260,11 @@ func CreateConfig(insecure, forceOverwrite bool, configPath, adminPassword strin }, }, }, + Thumbnails: ThumbnailExtension{ + Thumbnail: ThumbnailSettings{ + TransferSecret: thumbnailsTransferSecret, + }, + }, } if insecure { @@ -283,12 +295,9 @@ func CreateConfig(insecure, forceOverwrite bool, configPath, adminPassword strin cfg.StorageUsers = DataProviderInsecureSettings{ Data_provider_insecure: true, } - cfg.Thumbnails = ThumbNailExtension{ - Thumbnail: ThumbnailSettings{ - WebdavAllowInsecure: true, - Cs3AllowInsecure: true, - }, - } + + cfg.Thumbnails.Thumbnail.WebdavAllowInsecure = true + cfg.Thumbnails.Thumbnail.Cs3AllowInsecure = true } yamlOutput, err := yaml.Marshal(cfg)