Merge pull request #3752 from owncloud/thumbnails-env-doc

add description tags to thumbnails config
This commit is contained in:
David Christofas
2022-05-10 11:39:35 +02:00
committed by GitHub
11 changed files with 63 additions and 81 deletions

View File

@@ -0,0 +1,17 @@
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.
**Important**
If you ran `ocis init` with the `v2.0.0-alpha*` version then you have to manually add the `transfer_secret` to the ocis.yaml.
Just open the `ocis.yaml` config file and look for the thumbnails section.
Then add a random `transfer_secret` so that it looks like this:
```yaml
thumbnails:
thumbnail:
transfer_secret: <put random value here>
```
https://github.com/owncloud/ocis/pull/3752

View File

@@ -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."`
}

View File

@@ -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"`

View File

@@ -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], ",")
}
}

View File

@@ -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:"-"`
}

View File

@@ -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:"-"`
}

View File

@@ -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."`
}

View File

@@ -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
}

View File

@@ -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."`
}

View File

@@ -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
}

View File

@@ -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)