From 16bb92f89c2c00c28bd5918b60ee7a871c23b95b Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 9 Nov 2021 15:22:26 +0100 Subject: [PATCH] fix hello deployment --- .../config/ocis/entrypoint-override.sh | 5 - .../ocis/{proxy-config.json => proxy.json} | 0 .../examples/ocis_hello/docker-compose.yml | 7 +- ocis-pkg/config/helpers.go | 4 +- proxy/pkg/config/config.go | 165 +++++++++++++++++- proxy/pkg/config/mappings.go | 5 - proxy/pkg/proxy/proxy.go | 165 ------------------ proxy/pkg/proxy/proxy_integration_test.go | 1 - proxy/pkg/proxy/proxy_test.go | 2 +- 9 files changed, 167 insertions(+), 187 deletions(-) rename deployments/examples/ocis_hello/config/ocis/{proxy-config.json => proxy.json} (100%) diff --git a/deployments/examples/ocis_hello/config/ocis/entrypoint-override.sh b/deployments/examples/ocis_hello/config/ocis/entrypoint-override.sh index d90e287a94..6cd8f27182 100644 --- a/deployments/examples/ocis_hello/config/ocis/entrypoint-override.sh +++ b/deployments/examples/ocis_hello/config/ocis/entrypoint-override.sh @@ -3,7 +3,6 @@ set -e mkdir -p /var/tmp/ocis/.config/ -cp /config/proxy-config.json /var/tmp/ocis/.config/proxy-config.json cp /config/web-config.dist.json /var/tmp/ocis/.config/web-config.json sed -i 's/ocis.owncloud.test/'${OCIS_DOMAIN:-ocis.owncloud.test}'/g' /var/tmp/ocis/.config/web-config.json @@ -26,8 +25,4 @@ ocis accounts update --password $STORAGE_LDAP_BIND_PASSWORD $REVA_USER_UUID echo "default secrets changed" echo "##################################################" -ocis kill proxy -sleep 10 -ocis proxy server # workaround for loading proxy configuration - wait # wait for oCIS to exit diff --git a/deployments/examples/ocis_hello/config/ocis/proxy-config.json b/deployments/examples/ocis_hello/config/ocis/proxy.json similarity index 100% rename from deployments/examples/ocis_hello/config/ocis/proxy-config.json rename to deployments/examples/ocis_hello/config/ocis/proxy.json diff --git a/deployments/examples/ocis_hello/docker-compose.yml b/deployments/examples/ocis_hello/docker-compose.yml index bde3af9d84..635517e87d 100644 --- a/deployments/examples/ocis_hello/docker-compose.yml +++ b/deployments/examples/ocis_hello/docker-compose.yml @@ -52,7 +52,8 @@ services: environment: OCIS_URL: https://${OCIS_DOMAIN:-ocis.owncloud.test} OCIS_DOMAIN: ${OCIS_DOMAIN:-ocis.owncloud.test} - OCIS_LOG_LEVEL: ${OCIS_LOG_LEVEL:-error} # make oCIS less verbose + #OCIS_LOG_LEVEL: ${OCIS_LOG_LEVEL:-error} # make oCIS less verbose + PROXY_LOG_LEVEL: debug PROXY_OIDC_INSECURE: "${INSECURE:-false}" # needed if Traefik is using self generated certificates PROXY_TLS: "false" # do not use SSL between Traefik and oCIS # change default secrets @@ -63,14 +64,12 @@ services: OCIS_MACHINE_AUTH_API_KEY: ${OCIS_MACHINE_AUTH_API_KEY:-change-me-please} # web ui WEB_UI_CONFIG: "/var/tmp/ocis/.config/web-config.json" - # proxy - PROXY_CONFIG_FILE: "/var/tmp/ocis/.config/proxy-config.json" # make settings service available to oCIS Hello SETTINGS_GRPC_ADDR: 0.0.0.0:9191 volumes: - ./config/ocis/entrypoint-override.sh:/entrypoint-override.sh - ./config/ocis/web-config.dist.json:/config/web-config.dist.json - - ./config/ocis/proxy-config.json:/config/proxy-config.json + - ./config/ocis/proxy.json:/etc/ocis/proxy.json - ocis-data:/var/lib/ocis labels: - "traefik.enable=true" diff --git a/ocis-pkg/config/helpers.go b/ocis-pkg/config/helpers.go index 8cb6e00790..6acb6654f7 100644 --- a/ocis-pkg/config/helpers.go +++ b/ocis-pkg/config/helpers.go @@ -12,8 +12,8 @@ import ( var ( defaultLocations = []string{ - filepath.Join(os.Getenv("HOME"), "/.ocis/config"), - "/etc/ocis", + filepath.Join(os.Getenv("HOME"), "/.ocis/config/"), + "/etc/ocis/", ".config/", } diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index fec1e7449f..9e858a0eed 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -108,7 +108,6 @@ type Cache struct { type Config struct { OcisURL string - File string `mapstructure:"file"` Log shared.Log `mapstructure:"log"` Debug Debug `mapstructure:"debug"` HTTP HTTP `mapstructure:"http"` @@ -203,8 +202,7 @@ func New() *Config { // DefaultConfig are values stored in the flag set, but moved to a struct. func DefaultConfig() *Config { return &Config{ - File: "", - Log: shared.Log{}, // logging config is inherited. + Log: shared.Log{}, // logging config is inherited. Debug: Debug{ Addr: "0.0.0.0:9205", Token: "", @@ -253,6 +251,165 @@ func DefaultConfig() *Config { //AutoprovisionAccounts: false, //EnableBasicAuth: false, //InsecureBackends: false, - Context: nil, + Context: nil, + Policies: defaultPolicies(), + } +} + +func defaultPolicies() []Policy { + return []Policy{ + { + Name: "ocis", + Routes: []Route{ + { + Endpoint: "/", + Backend: "http://localhost:9100", + }, + { + Endpoint: "/.well-known/", + Backend: "http://localhost:9130", + }, + { + Endpoint: "/konnect/", + Backend: "http://localhost:9130", + }, + { + Endpoint: "/signin/", + Backend: "http://localhost:9130", + }, + { + Endpoint: "/archiver", + Backend: "http://localhost:9140", + }, + { + Type: RegexRoute, + Endpoint: "/ocs/v[12].php/cloud/(users?|groups)", // we have `user`, `users` and `groups` in ocis-ocs + Backend: "http://localhost:9110", + }, + { + Endpoint: "/ocs/", + Backend: "http://localhost:9140", + }, + { + Type: QueryRoute, + Endpoint: "/remote.php/?preview=1", + Backend: "http://localhost:9115", + }, + { + Endpoint: "/remote.php/", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/dav/", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/webdav/", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/status.php", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/index.php/", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/data", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/app/", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/graph/", + Backend: "http://localhost:9120", + }, + { + Endpoint: "/graph-explorer", + Backend: "http://localhost:9135", + }, + // if we were using the go micro api gateway we could look up the endpoint in the registry dynamically + { + Endpoint: "/api/v0/accounts", + Backend: "http://localhost:9181", + }, + // TODO the lookup needs a better mechanism + { + Endpoint: "/accounts.js", + Backend: "http://localhost:9181", + }, + { + Endpoint: "/api/v0/settings", + Backend: "http://localhost:9190", + }, + { + Endpoint: "/settings.js", + Backend: "http://localhost:9190", + }, + }, + }, + { + Name: "oc10", + Routes: []Route{ + { + Endpoint: "/", + Backend: "http://localhost:9100", + }, + { + Endpoint: "/.well-known/", + Backend: "http://localhost:9130", + }, + { + Endpoint: "/konnect/", + Backend: "http://localhost:9130", + }, + { + Endpoint: "/signin/", + Backend: "http://localhost:9130", + }, + { + Endpoint: "/archiver", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/ocs/", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + { + Endpoint: "/remote.php/", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + { + Endpoint: "/dav/", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + { + Endpoint: "/webdav/", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + { + Endpoint: "/status.php", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + { + Endpoint: "/index.php/", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + { + Endpoint: "/data", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + }, + }, } } diff --git a/proxy/pkg/config/mappings.go b/proxy/pkg/config/mappings.go index fc9433818f..f417ec2576 100644 --- a/proxy/pkg/config/mappings.go +++ b/proxy/pkg/config/mappings.go @@ -52,11 +52,6 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.Debug.Addr, }, - { - EnvVars: []string{"PROXY_CONFIG_FILE"}, - Destination: &cfg.File, - }, - // Tracing { EnvVars: []string{"PROXY_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, diff --git a/proxy/pkg/proxy/proxy.go b/proxy/pkg/proxy/proxy.go index 465c1563c8..7681defb80 100644 --- a/proxy/pkg/proxy/proxy.go +++ b/proxy/pkg/proxy/proxy.go @@ -62,13 +62,6 @@ func NewMultiHostReverseProxy(opts ...Option) *MultiHostReverseProxy { }, } - if options.Config.Policies == nil { - rp.logger.Info().Str("source", "runtime").Msg("Policies") - options.Config.Policies = defaultPolicies() - } else { - rp.logger.Info().Str("source", "file").Str("src", options.Config.File).Msg("policies") - } - if options.Config.PolicySelector == nil { firstPolicy := options.Config.Policies[0].Name rp.logger.Warn().Str("policy", firstPolicy).Msg("policy-selector not configured. Will always use first policy") @@ -263,161 +256,3 @@ func (p *MultiHostReverseProxy) regexRouteMatcher(pattern string, target url.URL func (p *MultiHostReverseProxy) prefixRouteMatcher(prefix string, target url.URL) bool { return strings.HasPrefix(target.Path, prefix) && prefix != "/" } - -func defaultPolicies() []config.Policy { - return []config.Policy{ - { - Name: "ocis", - Routes: []config.Route{ - { - Endpoint: "/", - Backend: "http://localhost:9100", - }, - { - Endpoint: "/.well-known/", - Backend: "http://localhost:9130", - }, - { - Endpoint: "/konnect/", - Backend: "http://localhost:9130", - }, - { - Endpoint: "/signin/", - Backend: "http://localhost:9130", - }, - { - Endpoint: "/archiver", - Backend: "http://localhost:9140", - }, - { - Type: config.RegexRoute, - Endpoint: "/ocs/v[12].php/cloud/(users?|groups)", // we have `user`, `users` and `groups` in ocis-ocs - Backend: "http://localhost:9110", - }, - { - Endpoint: "/ocs/", - Backend: "http://localhost:9140", - }, - { - Type: config.QueryRoute, - Endpoint: "/remote.php/?preview=1", - Backend: "http://localhost:9115", - }, - { - Endpoint: "/remote.php/", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/dav/", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/webdav/", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/status.php", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/index.php/", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/data", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/app/", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/graph/", - Backend: "http://localhost:9120", - }, - { - Endpoint: "/graph-explorer", - Backend: "http://localhost:9135", - }, - // if we were using the go micro api gateway we could look up the endpoint in the registry dynamically - { - Endpoint: "/api/v0/accounts", - Backend: "http://localhost:9181", - }, - // TODO the lookup needs a better mechanism - { - Endpoint: "/accounts.js", - Backend: "http://localhost:9181", - }, - { - Endpoint: "/api/v0/settings", - Backend: "http://localhost:9190", - }, - { - Endpoint: "/settings.js", - Backend: "http://localhost:9190", - }, - }, - }, - { - Name: "oc10", - Routes: []config.Route{ - { - Endpoint: "/", - Backend: "http://localhost:9100", - }, - { - Endpoint: "/.well-known/", - Backend: "http://localhost:9130", - }, - { - Endpoint: "/konnect/", - Backend: "http://localhost:9130", - }, - { - Endpoint: "/signin/", - Backend: "http://localhost:9130", - }, - { - Endpoint: "/archiver", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/ocs/", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - { - Endpoint: "/remote.php/", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - { - Endpoint: "/dav/", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - { - Endpoint: "/webdav/", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - { - Endpoint: "/status.php", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - { - Endpoint: "/index.php/", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - { - Endpoint: "/data", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - }, - }, - } -} diff --git a/proxy/pkg/proxy/proxy_integration_test.go b/proxy/pkg/proxy/proxy_integration_test.go index b9777ac666..3e7736e83b 100644 --- a/proxy/pkg/proxy/proxy_integration_test.go +++ b/proxy/pkg/proxy/proxy_integration_test.go @@ -215,7 +215,6 @@ func (tc *testCase) expectProxyTo(strURL string) testCase { func testConfig(policy []config.Policy) *config.Config { return &config.Config{ - File: "", Log: shared.Log{}, Debug: config.Debug{}, HTTP: config.HTTP{}, diff --git a/proxy/pkg/proxy/proxy_test.go b/proxy/pkg/proxy/proxy_test.go index 8eefe3143b..256a559dc4 100644 --- a/proxy/pkg/proxy/proxy_test.go +++ b/proxy/pkg/proxy/proxy_test.go @@ -13,7 +13,7 @@ type matchertest struct { } func TestPrefixRouteMatcher(t *testing.T) { - cfg := config.New() + cfg := config.DefaultConfig() p := NewMultiHostReverseProxy(Config(cfg)) table := []matchertest{