From 2eacbf6b4226481f0bdf89ff645f391bcbcabc98 Mon Sep 17 00:00:00 2001 From: Benedikt Kulmann Date: Mon, 7 Sep 2020 11:45:36 +0200 Subject: [PATCH 1/2] Get rid of cache in account_uuid middleware Accounts can be changed. In that case the cache entries would need to be invalidated. Since we are keeping accounts in an in-memory index within ocis-accounts anyway, we can get rid of this kind of optimization for now. --- pkg/middleware/account_uuid.go | 69 ++++++++++++---------------------- 1 file changed, 24 insertions(+), 45 deletions(-) diff --git a/pkg/middleware/account_uuid.go b/pkg/middleware/account_uuid.go index 881e30edf..1b98eed05 100644 --- a/pkg/middleware/account_uuid.go +++ b/pkg/middleware/account_uuid.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - settings "github.com/owncloud/ocis-settings/pkg/proto/v0" "net/http" "strconv" "strings" @@ -14,55 +13,35 @@ import ( "github.com/cs3org/reva/pkg/token/manager/jwt" acc "github.com/owncloud/ocis-accounts/pkg/proto/v0" "github.com/owncloud/ocis-pkg/v2/log" - oidc "github.com/owncloud/ocis-pkg/v2/oidc" + "github.com/owncloud/ocis-pkg/v2/oidc" + settings "github.com/owncloud/ocis-settings/pkg/proto/v0" ) func getAccount(l log.Logger, ac acc.AccountsService, query string) (account *acc.Account, status int) { - entry, err := svcCache.Get(AccountsKey, query) + resp, err := ac.ListAccounts(context.Background(), &acc.ListAccountsRequest{ + Query: query, + PageSize: 2, + }) + if err != nil { - l.Debug().Msgf("No cache entry for %s", query) - resp, err := ac.ListAccounts(context.Background(), &acc.ListAccountsRequest{ - Query: query, - PageSize: 2, - }) - - if err != nil { - l.Error().Err(err).Str("query", query).Msgf("Error fetching from accounts-service") - status = http.StatusInternalServerError - return - } - - if len(resp.Accounts) <= 0 { - l.Error().Str("query", query).Msgf("Account not found") - status = http.StatusNotFound - return - } - - // TODO provision account - - if len(resp.Accounts) > 1 { - l.Error().Str("query", query).Msgf("More than one account found. Not logging user in.") - status = http.StatusForbidden - return - } - - err = svcCache.Set(AccountsKey, query, *resp.Accounts[0]) - if err != nil { - l.Err(err).Str("query", query).Msgf("Could not cache user") - status = http.StatusInternalServerError - return - } - - account = resp.Accounts[0] - } else { - l.Debug().Msgf("using cache entry for %s", query) - a, ok := entry.V.(acc.Account) // TODO how can we directly point to the cached account? - if !ok { - status = http.StatusInternalServerError - return - } - account = &a + l.Error().Err(err).Str("query", query).Msgf("Error fetching from accounts-service") + status = http.StatusInternalServerError + return } + + if len(resp.Accounts) <= 0 { + l.Error().Str("query", query).Msgf("Account not found") + status = http.StatusNotFound + return + } + + if len(resp.Accounts) > 1 { + l.Error().Str("query", query).Msgf("More than one account found. Not logging user in.") + status = http.StatusForbidden + return + } + + account = resp.Accounts[0] return } From fb0ecd7e50dcac41275a6f77bd281b2fc9d1472c Mon Sep 17 00:00:00 2001 From: Benedikt Kulmann Date: Mon, 7 Sep 2020 11:50:05 +0200 Subject: [PATCH 2/2] Changelog --- changelog/unreleased/remove-account-caching.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/unreleased/remove-account-caching.md diff --git a/changelog/unreleased/remove-account-caching.md b/changelog/unreleased/remove-account-caching.md new file mode 100644 index 000000000..378117d62 --- /dev/null +++ b/changelog/unreleased/remove-account-caching.md @@ -0,0 +1,5 @@ +Change: Remove accounts caching + +We removed the accounts cache in order to avoid problems with accounts that have been updated in the accounts service. + +https://github.com/owncloud/ocis-proxy/pull/100