From c8d7225f9dabf0885499c7c90d86eecf189000b8 Mon Sep 17 00:00:00 2001 From: Francesco Torchia Date: Tue, 22 Aug 2023 14:48:36 +0200 Subject: [PATCH 1/2] Add serviceDetails to Service model Signed-off-by: Francesco Torchia --- dashboard/pkg/epinio/models/services.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/dashboard/pkg/epinio/models/services.js b/dashboard/pkg/epinio/models/services.js index e721a9a..bd803eb 100644 --- a/dashboard/pkg/epinio/models/services.js +++ b/dashboard/pkg/epinio/models/services.js @@ -3,6 +3,12 @@ import { EPINIO_TYPES } from '../types'; import EpinioNamespacedResource, { bulkRemove } from './epinio-namespaced-resource'; export default class EpinioServiceModel extends EpinioNamespacedResource { + constructor(...args) { + super(...args); + + this.serviceDetails = {}; + } + get links() { return { update: this.getUrl(), @@ -35,6 +41,14 @@ export default class EpinioServiceModel extends EpinioNamespacedResource { // ------------------------------------------------------------------ + get details() { + return this.serviceDetails; + } + + set details(v) { + this.serviceDetails = v; + } + get state() { return this.status; } From c07e9d8c315d13e7269d3ab3aee866bd1cb7d3f1 Mon Sep 17 00:00:00 2001 From: Richard Cox Date: Tue, 29 Aug 2023 15:35:16 +0100 Subject: [PATCH 2/2] Fixes to services and links --- .../epinio/rancherproxy/interfaces/types.go | 7 ++-- .../plugins/epinio/rancherproxy/norman/api.go | 4 +-- .../epinio/rancherproxy/steve/userprefs.go | 17 ++++++--- dashboard/pkg/epinio/models/services.js | 36 ++++++++++++++----- 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/backend/src/jetstream/plugins/epinio/rancherproxy/interfaces/types.go b/backend/src/jetstream/plugins/epinio/rancherproxy/interfaces/types.go index 2cadb0d..6dfa96d 100644 --- a/backend/src/jetstream/plugins/epinio/rancherproxy/interfaces/types.go +++ b/backend/src/jetstream/plugins/epinio/rancherproxy/interfaces/types.go @@ -38,14 +38,15 @@ func GetBaseURL(ec echo.Context) string { return host } -func GetSelfLink(ec echo.Context, paths ...string) string { +func GetSelfLink(ec echo.Context, additionalPaths ...string) string { host := GetBaseURL(ec) - path := strings.Join(paths, "/") + path := strings.Join(additionalPaths, "/") + if len(path) > 0 { path = fmt.Sprintf("/%s", path) } - return fmt.Sprintf("https://%s%s%s", host, ec.Request().URL.String(), path) + return fmt.Sprintf("https://%s%s%s%s", host, ec.Request().URL.Host, ec.Request().URL.Path, path) } type AuthProvider struct { diff --git a/backend/src/jetstream/plugins/epinio/rancherproxy/norman/api.go b/backend/src/jetstream/plugins/epinio/rancherproxy/norman/api.go index 3c2a2c1..1eb0cc8 100644 --- a/backend/src/jetstream/plugins/epinio/rancherproxy/norman/api.go +++ b/backend/src/jetstream/plugins/epinio/rancherproxy/norman/api.go @@ -23,7 +23,7 @@ func GetAuthProviders(ec echo.Context, p jInterfaces.PortalProxy) error { // /v3/users func GetUser(ec echo.Context) error { - user := NewUser(interfaces.GetBaseURL(ec), ec.Get("user_id").(string)) + user := NewUser(interfaces.GetSelfLink(ec), ec.Get("user_id").(string)) return api.SendResponse(ec, user) } @@ -36,7 +36,7 @@ func TokenLogout(ec echo.Context, p jInterfaces.PortalProxy) error { // /v3/principals func GetPrincipals(ec echo.Context) error { - principal := NewPrincipal(interfaces.GetBaseURL(ec), ec.Get("user_id").(string)) + principal := NewPrincipal(interfaces.GetSelfLink(ec), ec.Get("user_id").(string)) return api.SendResponse(ec, principal) } diff --git a/backend/src/jetstream/plugins/epinio/rancherproxy/steve/userprefs.go b/backend/src/jetstream/plugins/epinio/rancherproxy/steve/userprefs.go index dc0c4e2..4acb89e 100644 --- a/backend/src/jetstream/plugins/epinio/rancherproxy/steve/userprefs.go +++ b/backend/src/jetstream/plugins/epinio/rancherproxy/steve/userprefs.go @@ -38,11 +38,11 @@ func NewUserPref(userId string) *interfaces.UserPref { func GetUserPrefs(c echo.Context) error { col := NewUserPrefCollection() col.Data = make([]interface{}, 1) - pref := createPref(c) + pref := createPref(c, true) col.Data[0] = pref host := interfaces.GetBaseURL(c) - base := fmt.Sprintf("https://%s%s", host, c.Request().URL.String()) + base := fmt.Sprintf("https://%s%s%s", host, c.Request().URL.Host, c.Request().URL.Path) col.Links["self"] = base @@ -51,10 +51,10 @@ func GetUserPrefs(c echo.Context) error { // Get user profile func GetSpecificUserPrefs(c echo.Context) error { - return c.JSON(http.StatusOK, createPref(c)) + return c.JSON(http.StatusOK, createPref(c, false)) } -func createPref(c echo.Context) *interfaces.UserPref { +func createPref(c echo.Context, isList bool) *interfaces.UserPref { userID := c.Get("user_id").(string) data := json.RawMessage(DefaultUserPreferences) @@ -62,7 +62,14 @@ func createPref(c echo.Context) *interfaces.UserPref { pref.Data = data host := interfaces.GetBaseURL(c) - user := fmt.Sprintf("https://%s%s/%s", host, c.Request().URL.String(), userID) + + var user string + if isList { + user = fmt.Sprintf("https://%s%s%s/%s", host, c.Request().URL.Host, c.Request().URL.Path, userID) + } else { + // Already contains user id in url + user = fmt.Sprintf("https://%s%s%s", host, c.Request().URL.Host, c.Request().URL.Path) + } pref.Links["self"] = user pref.Links["remove"] = user diff --git a/dashboard/pkg/epinio/models/services.js b/dashboard/pkg/epinio/models/services.js index bd803eb..3498ee1 100644 --- a/dashboard/pkg/epinio/models/services.js +++ b/dashboard/pkg/epinio/models/services.js @@ -3,12 +3,6 @@ import { EPINIO_TYPES } from '../types'; import EpinioNamespacedResource, { bulkRemove } from './epinio-namespaced-resource'; export default class EpinioServiceModel extends EpinioNamespacedResource { - constructor(...args) { - super(...args); - - this.serviceDetails = {}; - } - get links() { return { update: this.getUrl(), @@ -39,16 +33,25 @@ export default class EpinioServiceModel extends EpinioNamespacedResource { .filter((a) => !!a); } - // ------------------------------------------------------------------ + get serviceDetails() { + return this._serviceDetails; + } + /** + * Return the dashboard reserved getter for `details` (shown in MastHead) + */ get details() { - return this.serviceDetails; + return super.details; } + /** + * When assigning Epinio details property ensure it goes to a temp value (instead of colliding with dashboard reserved `details` getter) + */ set details(v) { - this.serviceDetails = v; + this._serviceDetails = v; } + // ------------------------------------------------------------------ get state() { return this.status; } @@ -109,4 +112,19 @@ export default class EpinioServiceModel extends EpinioNamespacedResource { bulkRemove(items, opt) { return bulkRemove(items, opt); } + + // Ensure when we clone that we preserve the description + toJSON() { + const data = super.toJSON(); + + // Ensure the epinio detail gets persisted in the right property + data.details = this._serviceDetails; + delete data._serviceDetails; + + return data; + } + + toSave() { + return this.toJSON(); + } }