Skip to content

Commit

Permalink
add description tags to thumbnails config
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas committed May 10, 2022
1 parent 9ef68fd commit 4b7a365
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 81 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/thumbnails-env-doc.md
Original file line number Diff line number Diff line change
@@ -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
21 changes: 8 additions & 13 deletions extensions/thumbnails/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."`
}
2 changes: 1 addition & 1 deletion extensions/thumbnails/pkg/config/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
8 changes: 4 additions & 4 deletions extensions/thumbnails/pkg/config/defaults/defaultconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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], ",")
}
}
2 changes: 1 addition & 1 deletion extensions/thumbnails/pkg/config/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"-"`
}
4 changes: 2 additions & 2 deletions extensions/thumbnails/pkg/config/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"-"`
}
8 changes: 4 additions & 4 deletions extensions/thumbnails/pkg/config/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."`
}
5 changes: 0 additions & 5 deletions extensions/thumbnails/pkg/config/parser/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
8 changes: 4 additions & 4 deletions extensions/thumbnails/pkg/config/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."`
}
34 changes: 0 additions & 34 deletions extensions/thumbnails/pkg/thumbnail/imgsource/filesystem.go

This file was deleted.

35 changes: 22 additions & 13 deletions ocis/pkg/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -253,6 +260,11 @@ func CreateConfig(insecure, forceOverwrite bool, configPath, adminPassword strin
},
},
},
Thumbnails: ThumbnailExtension{
Thumbnail: ThumbnailSettings{
TransferSecret: thumbnailsTransferSecret,
},
},
}

if insecure {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4b7a365

Please sign in to comment.