Merge remote-tracking branch 'origin/master' into ocis-init

Signed-off-by: Christian Richter <crichter@owncloud.com>
This commit is contained in:
Christian Richter
2022-04-26 16:28:12 +02:00
110 changed files with 4895 additions and 1955 deletions
+44 -18
View File
@@ -4,20 +4,33 @@ import (
"github.com/owncloud/ocis/ocis-pkg/shared"
accounts "github.com/owncloud/ocis/extensions/accounts/pkg/config"
appprovider "github.com/owncloud/ocis/extensions/appprovider/pkg/config"
audit "github.com/owncloud/ocis/extensions/audit/pkg/config"
authbasic "github.com/owncloud/ocis/extensions/auth-basic/pkg/config"
authbearer "github.com/owncloud/ocis/extensions/auth-bearer/pkg/config"
authmachine "github.com/owncloud/ocis/extensions/auth-machine/pkg/config"
frontend "github.com/owncloud/ocis/extensions/frontend/pkg/config"
gateway "github.com/owncloud/ocis/extensions/gateway/pkg/config"
glauth "github.com/owncloud/ocis/extensions/glauth/pkg/config"
graphExplorer "github.com/owncloud/ocis/extensions/graph-explorer/pkg/config"
graph "github.com/owncloud/ocis/extensions/graph/pkg/config"
group "github.com/owncloud/ocis/extensions/group/pkg/config"
idm "github.com/owncloud/ocis/extensions/idm/pkg/config"
idp "github.com/owncloud/ocis/extensions/idp/pkg/config"
nats "github.com/owncloud/ocis/extensions/nats/pkg/config"
notifications "github.com/owncloud/ocis/extensions/notifications/pkg/config"
ocdav "github.com/owncloud/ocis/extensions/ocdav/pkg/config"
ocs "github.com/owncloud/ocis/extensions/ocs/pkg/config"
proxy "github.com/owncloud/ocis/extensions/proxy/pkg/config"
settings "github.com/owncloud/ocis/extensions/settings/pkg/config"
storage "github.com/owncloud/ocis/extensions/storage/pkg/config"
sharing "github.com/owncloud/ocis/extensions/sharing/pkg/config"
storagemetadata "github.com/owncloud/ocis/extensions/storage-metadata/pkg/config"
storagepublic "github.com/owncloud/ocis/extensions/storage-publiclink/pkg/config"
storageshares "github.com/owncloud/ocis/extensions/storage-shares/pkg/config"
storageusers "github.com/owncloud/ocis/extensions/storage-users/pkg/config"
store "github.com/owncloud/ocis/extensions/store/pkg/config"
thumbnails "github.com/owncloud/ocis/extensions/thumbnails/pkg/config"
user "github.com/owncloud/ocis/extensions/user/pkg/config"
web "github.com/owncloud/ocis/extensions/web/pkg/config"
webdav "github.com/owncloud/ocis/extensions/webdav/pkg/config"
)
@@ -61,21 +74,34 @@ type Config struct {
TransferSecret string `yaml:"transfer_secret,omitempty"`
Runtime Runtime `yaml:"runtime,omitempty"`
Audit *audit.Config `yaml:"audit,omitempty"`
Accounts *accounts.Config `yaml:"accounts,omitempty"`
GLAuth *glauth.Config `yaml:"glauth,omitempty"`
Graph *graph.Config `yaml:"graph,omitempty"`
GraphExplorer *graphExplorer.Config `yaml:"graph_explorer,omitempty"`
IDP *idp.Config `yaml:"idp,omitempty"`
IDM *idm.Config `yaml:"idm,omitempty"`
Nats *nats.Config `yaml:"nats,omitempty"`
Notifications *notifications.Config `yaml:"notifications,omitempty"`
OCS *ocs.Config `yaml:"ocs,omitempty"`
Web *web.Config `yaml:"web,omitempty"`
Proxy *proxy.Config `yaml:"proxy,omitempty"`
Settings *settings.Config `yaml:"settings,omitempty"`
Storage *storage.Config `yaml:"storage,omitempty"`
Store *store.Config `yaml:"store,omitempty"`
Thumbnails *thumbnails.Config `yaml:"thumbnails,omitempty"`
WebDAV *webdav.Config `yaml:"webdav,omitempty"`
Audit *audit.Config `yaml:"audit,omitempty"`
Accounts *accounts.Config `yaml:"accounts,omitempty"`
GLAuth *glauth.Config `yaml:"glauth,omitempty"`
Graph *graph.Config `yaml:"graph,omitempty"`
GraphExplorer *graphExplorer.Config `yaml:"graph_explorer,omitempty"`
IDP *idp.Config `yaml:"idp,omitempty"`
IDM *idm.Config `yaml:"idm,omitempty"`
Nats *nats.Config `yaml:"nats,omitempty"`
Notifications *notifications.Config `yaml:"notifications,omitempty"`
OCS *ocs.Config `yaml:"ocs,omitempty"`
Web *web.Config `yaml:"web,omitempty"`
Proxy *proxy.Config `yaml:"proxy,omitempty"`
Settings *settings.Config `yaml:"settings,omitempty"`
Gateway *gateway.Config `yaml:"gateway,omitempty"`
Frontend *frontend.Config `yaml:"frontend,omitempty"`
AuthBasic *authbasic.Config `yaml:"auth_basic,omitempty"`
AuthBearer *authbearer.Config `yaml:"auth_bearer,omitempty"`
AuthMachine *authmachine.Config `yaml:"auth_machine,omitempty"`
User *user.Config `yaml:"user,omitempty"`
Group *group.Config `yaml:"group,omitempty"`
AppProvider *appprovider.Config `yaml:"app_provider,omitempty"`
Sharing *sharing.Config `yaml:"sharing,omitempty"`
StorageMetadata *storagemetadata.Config `yaml:"storage_metadata,omitempty"`
StoragePublicLink *storagepublic.Config `yaml:"storage_public,omitempty"`
StorageUsers *storageusers.Config `yaml:"storage_users,omitempty"`
StorageShares *storageshares.Config `yaml:"storage_shares,omitempty"`
OCDav *ocdav.Config `yaml:"ocdav,omitempty"`
Store *store.Config `yaml:"store,omitempty"`
Thumbnails *thumbnails.Config `yaml:"thumbnails,omitempty"`
WebDAV *webdav.Config `yaml:"webdav,omitempty"`
}
+44 -18
View File
@@ -2,20 +2,33 @@ package config
import (
accounts "github.com/owncloud/ocis/extensions/accounts/pkg/config/defaults"
appprovider "github.com/owncloud/ocis/extensions/appprovider/pkg/config/defaults"
audit "github.com/owncloud/ocis/extensions/audit/pkg/config/defaults"
authbasic "github.com/owncloud/ocis/extensions/auth-basic/pkg/config/defaults"
authbearer "github.com/owncloud/ocis/extensions/auth-bearer/pkg/config/defaults"
authmachine "github.com/owncloud/ocis/extensions/auth-machine/pkg/config/defaults"
frontend "github.com/owncloud/ocis/extensions/frontend/pkg/config/defaults"
gateway "github.com/owncloud/ocis/extensions/gateway/pkg/config/defaults"
glauth "github.com/owncloud/ocis/extensions/glauth/pkg/config/defaults"
graphExplorer "github.com/owncloud/ocis/extensions/graph-explorer/pkg/config/defaults"
graph "github.com/owncloud/ocis/extensions/graph/pkg/config/defaults"
group "github.com/owncloud/ocis/extensions/group/pkg/config/defaults"
idm "github.com/owncloud/ocis/extensions/idm/pkg/config/defaults"
idp "github.com/owncloud/ocis/extensions/idp/pkg/config/defaults"
nats "github.com/owncloud/ocis/extensions/nats/pkg/config/defaults"
notifications "github.com/owncloud/ocis/extensions/notifications/pkg/config/defaults"
ocdav "github.com/owncloud/ocis/extensions/ocdav/pkg/config/defaults"
ocs "github.com/owncloud/ocis/extensions/ocs/pkg/config/defaults"
proxy "github.com/owncloud/ocis/extensions/proxy/pkg/config/defaults"
settings "github.com/owncloud/ocis/extensions/settings/pkg/config/defaults"
storage "github.com/owncloud/ocis/extensions/storage/pkg/config/defaults"
sharing "github.com/owncloud/ocis/extensions/sharing/pkg/config/defaults"
storagemetadata "github.com/owncloud/ocis/extensions/storage-metadata/pkg/config/defaults"
storagepublic "github.com/owncloud/ocis/extensions/storage-publiclink/pkg/config/defaults"
storageshares "github.com/owncloud/ocis/extensions/storage-shares/pkg/config/defaults"
storageusers "github.com/owncloud/ocis/extensions/storage-users/pkg/config/defaults"
store "github.com/owncloud/ocis/extensions/store/pkg/config/defaults"
thumbnails "github.com/owncloud/ocis/extensions/thumbnails/pkg/config/defaults"
user "github.com/owncloud/ocis/extensions/user/pkg/config/defaults"
web "github.com/owncloud/ocis/extensions/web/pkg/config/defaults"
webdav "github.com/owncloud/ocis/extensions/webdav/pkg/config/defaults"
"github.com/owncloud/ocis/ocis-pkg/shared"
@@ -30,22 +43,35 @@ func DefaultConfig() *Config {
Port: "9250",
Host: "localhost",
},
Audit: audit.DefaultConfig(),
Accounts: accounts.DefaultConfig(),
GLAuth: glauth.DefaultConfig(),
Graph: graph.DefaultConfig(),
IDP: idp.DefaultConfig(),
IDM: idm.DefaultConfig(),
Nats: nats.DefaultConfig(),
Notifications: notifications.DefaultConfig(),
Proxy: proxy.DefaultConfig(),
GraphExplorer: graphExplorer.DefaultConfig(),
OCS: ocs.DefaultConfig(),
Settings: settings.DefaultConfig(),
Web: web.DefaultConfig(),
Store: store.DefaultConfig(),
Thumbnails: thumbnails.DefaultConfig(),
WebDAV: webdav.DefaultConfig(),
Storage: storage.DefaultConfig(),
Audit: audit.DefaultConfig(),
Accounts: accounts.DefaultConfig(),
GLAuth: glauth.DefaultConfig(),
Graph: graph.DefaultConfig(),
IDP: idp.DefaultConfig(),
IDM: idm.DefaultConfig(),
Nats: nats.DefaultConfig(),
Notifications: notifications.DefaultConfig(),
Proxy: proxy.DefaultConfig(),
GraphExplorer: graphExplorer.DefaultConfig(),
OCS: ocs.DefaultConfig(),
Settings: settings.DefaultConfig(),
Web: web.DefaultConfig(),
Store: store.DefaultConfig(),
Thumbnails: thumbnails.DefaultConfig(),
WebDAV: webdav.DefaultConfig(),
Gateway: gateway.FullDefaultConfig(),
AuthBasic: authbasic.FullDefaultConfig(),
AuthBearer: authbearer.FullDefaultConfig(),
AuthMachine: authmachine.FullDefaultConfig(),
User: user.FullDefaultConfig(),
Group: group.FullDefaultConfig(),
Sharing: sharing.FullDefaultConfig(),
StorageMetadata: storagemetadata.FullDefaultConfig(),
StoragePublicLink: storagepublic.FullDefaultConfig(),
StorageUsers: storageusers.FullDefaultConfig(),
StorageShares: storageshares.FullDefaultConfig(),
AppProvider: appprovider.FullDefaultConfig(),
Frontend: frontend.FullDefaultConfig(),
OCDav: ocdav.FullDefaultConfig(),
}
}
+37 -4
View File
@@ -10,16 +10,16 @@ const ()
var (
// switch between modes
BaseDataPathType = "homedir"
// don't read from this, only write
BaseDataPathType = "homedir" // or "path"
// default data path
BaseDataPathValue = "/var/lib/ocis"
)
func BaseDataPath() string {
// It is not nice to have hidden / secrete configuration options
// But how can we update the base path for every occurence with a flageset option?
// This is currenlty not possible and needs a new configuration concept
// But how can we update the base path for every occurrence with a flagset option?
// This is currently not possible and needs a new configuration concept
p := os.Getenv("OCIS_BASE_DATA_PATH")
if p != "" {
return p
@@ -40,3 +40,36 @@ func BaseDataPath() string {
return ""
}
}
var (
// switch between modes
BaseConfigPathType = "homedir" // or "path"
// default config path
BaseConfigPathValue = "/etc/ocis"
)
func BaseConfigPath() string {
// It is not nice to have hidden / secrete configuration options
// But how can we update the base path for every occurrence with a flagset option?
// This is currently not possible and needs a new configuration concept
p := os.Getenv("OCIS_CONFIG_DIR")
if p != "" {
return p
}
switch BaseConfigPathType {
case "homedir":
dir, err := os.UserHomeDir()
if err != nil {
// fallback to BaseConfigPathValue for users without home
return BaseConfigPathValue
}
return path.Join(dir, ".ocis", "config")
case "path":
return BaseConfigPathValue
default:
log.Fatalf("BaseConfigPathType %s not found", BaseConfigPathType)
return ""
}
}
+10 -66
View File
@@ -1,87 +1,31 @@
package config
import (
"io/fs"
"os"
"path/filepath"
"strings"
"path"
gofig "github.com/gookit/config/v2"
gooyaml "github.com/gookit/config/v2/yaml"
"github.com/owncloud/ocis/ocis-pkg/config/defaults"
)
var (
defaultLocations = []string{
filepath.Join(os.Getenv("HOME"), "/.ocis/config/"),
"/etc/ocis/",
".config/",
}
// supportedExtensions is determined by gookit/config.
supportedExtensions = []string{
"yaml",
"yml",
}
// decoderConfigTagname sets the tag name to be used from the config structs
// currently we only support "yaml" because we only support config loading
// from yaml files and the yaml parser has no simple way to set a custom tag name to use
decoderConfigTagName = "yaml"
)
// DefaultConfigSources returns a slice with matched expected config files. It sugars coat several aspects of config file
// management by assuming there are 3 default locations a config file could be.
// It uses globbing to match a config file by name, and retrieve any supported extension supported by our drivers.
// It sanitizes the output depending on the list of drivers provided.
func DefaultConfigSources(filename string, drivers []string) []string {
var sources []string
locations := []string{}
if v := os.Getenv("OCIS_CONFIG_DIR"); v != "" {
locations = append(locations, v)
// only use the configured config dir
locations = append(locations, os.Getenv("OCIS_CONFIG_DIR"))
} else {
// merge config from all default locations
locations = append(locations, defaultLocations...)
}
for i := range locations {
dirFS := os.DirFS(locations[i])
pattern := filename + ".*"
matched, _ := fs.Glob(dirFS, pattern)
if len(matched) > 0 {
// prepend path to results
for j := 0; j < len(matched); j++ {
matched[j] = filepath.Join(locations[i], matched[j])
}
}
sources = append(sources, matched...)
}
return sanitizeExtensions(sources, drivers, func(a, b string) bool {
return strings.HasSuffix(filepath.Base(a), b)
})
}
// sanitizeExtensions removes elements from "set" which extensions are not in "ext".
func sanitizeExtensions(set []string, ext []string, f func(a, b string) bool) []string {
var r []string
for i := 0; i < len(set); i++ {
for j := 0; j < len(ext); j++ {
if f(filepath.Base(set[i]), ext[j]) {
r = append(r, set[i])
}
}
}
return r
}
// BindSourcesToStructs assigns any config value from a config file / env variable to struct `dst`. Its only purpose
// is to solely modify `dst`, not dealing with the config structs; and do so in a thread safe manner.
func BindSourcesToStructs(extension string, dst interface{}) (*gofig.Config, error) {
sources := DefaultConfigSources(extension, supportedExtensions)
cnf := gofig.NewWithOptions(extension)
cnf.WithOptions(func(options *gofig.Options) {
options.DecoderConfig.TagName = "yaml"
options.DecoderConfig.TagName = decoderConfigTagName
})
cnf.AddDriver(gooyaml.Driver)
_ = cnf.LoadFiles(sources...)
cfgFile := path.Join(defaults.BaseConfigPath(), extension+".yaml")
_ = cnf.LoadFiles([]string{cfgFile}...)
err := cnf.BindStruct("", &dst)
if err != nil {
+25
View File
@@ -0,0 +1,25 @@
package ldap
import (
"errors"
"os"
"time"
"github.com/owncloud/ocis/ocis-pkg/log"
)
const _caTimeout = 5
func WaitForCA(log log.Logger, insecure bool, caCert string) error {
if !insecure && caCert != "" {
if _, err := os.Stat(caCert); errors.Is(err, os.ErrNotExist) {
log.Warn().Str("LDAP CACert", caCert).Msgf("File does not exist. Waiting %d seconds for it to appear.", _caTimeout)
time.Sleep(_caTimeout * time.Second)
if _, err := os.Stat(caCert); errors.Is(err, os.ErrNotExist) {
log.Warn().Str("LDAP CACert", caCert).Msgf("File still does not exist after Timeout")
return err
}
}
}
return nil
}
+33
View File
@@ -5,6 +5,7 @@ import (
"net/url"
"strings"
"github.com/owncloud/ocis/ocis-pkg/log"
"go.opentelemetry.io/otel/exporters/jaeger"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/resource"
@@ -93,3 +94,35 @@ func parseAgentConfig(ae string) (string, string, error) {
}
return p[0], p[1], nil
}
// Configure for Reva serves only as informational / instructive log messages. Tracing config will be delegated directly
// to Reva services.
func Configure(enabled bool, tracingType string, logger log.Logger) {
if enabled {
switch tracingType {
case "agent":
logger.Error().
Str("type", tracingType).
Msg("Reva only supports the jaeger tracing backend")
case "jaeger":
logger.Info().
Str("type", tracingType).
Msg("configuring storage to use the jaeger tracing backend")
case "zipkin":
logger.Error().
Str("type", tracingType).
Msg("Reva only supports the jaeger tracing backend")
default:
logger.Warn().
Str("type", tracingType).
Msg("Unknown tracing backend")
}
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
}