Added Color customization to embedded object browser (#2246)
Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>
This commit is contained in:
@@ -95,6 +95,7 @@ func configureAPI(api *operations.ConsoleAPI) http.Handler {
|
||||
AccountAccessKey: claims.AccountAccessKey,
|
||||
Hm: claims.HideMenu,
|
||||
Ob: claims.ObjectBrowser,
|
||||
CustomStyleOb: claims.CustomStyleOB,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -355,6 +356,8 @@ func handleSPA(w http.ResponseWriter, r *http.Request) {
|
||||
sts := r.URL.Query().Get("sts")
|
||||
stsAccessKey := r.URL.Query().Get("sts_a")
|
||||
stsSecretKey := r.URL.Query().Get("sts_s")
|
||||
overridenStyles := r.URL.Query().Get("ov_st")
|
||||
|
||||
// if these three parameters are present we are being asked to issue a session with these values
|
||||
if sts != "" && stsAccessKey != "" && stsSecretKey != "" {
|
||||
creds := credentials.NewStaticV4(stsAccessKey, stsSecretKey, sts)
|
||||
@@ -366,6 +369,14 @@ func handleSPA(w http.ResponseWriter, r *http.Request) {
|
||||
sf.HideMenu = true
|
||||
sf.ObjectBrowser = true
|
||||
|
||||
err := ValidateEncodedStyles(overridenStyles)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
} else {
|
||||
sf.CustomStyleOB = overridenStyles
|
||||
}
|
||||
|
||||
sessionID, err := login(consoleCreds, sf)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
||||
@@ -51,7 +51,6 @@ const (
|
||||
PrometheusExtraLabels = "CONSOLE_PROMETHEUS_EXTRA_LABELS"
|
||||
ConsoleLogQueryURL = "CONSOLE_LOG_QUERY_URL"
|
||||
ConsoleLogQueryAuthToken = "CONSOLE_LOG_QUERY_AUTH_TOKEN"
|
||||
ConsoleObjectBrowserOnly = "CONSOLE_OBJECT_BROWSER_ONLY"
|
||||
LogSearchQueryAuthToken = "LOGSEARCH_QUERY_AUTH_TOKEN"
|
||||
SlashSeparator = "/"
|
||||
)
|
||||
|
||||
@@ -6006,6 +6006,9 @@ func init() {
|
||||
"accountAccessKey": {
|
||||
"type": "string"
|
||||
},
|
||||
"customStyleOb": {
|
||||
"type": "string"
|
||||
},
|
||||
"hm": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -6318,6 +6321,9 @@ func init() {
|
||||
"$ref": "#/definitions/permissionResource"
|
||||
}
|
||||
},
|
||||
"customStyles": {
|
||||
"type": "string"
|
||||
},
|
||||
"distributedMode": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -13266,6 +13272,9 @@ func init() {
|
||||
"accountAccessKey": {
|
||||
"type": "string"
|
||||
},
|
||||
"customStyleOb": {
|
||||
"type": "string"
|
||||
},
|
||||
"hm": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -13578,6 +13587,9 @@ func init() {
|
||||
"$ref": "#/definitions/permissionResource"
|
||||
}
|
||||
},
|
||||
"customStyles": {
|
||||
"type": "string"
|
||||
},
|
||||
"distributedMode": {
|
||||
"type": "boolean"
|
||||
},
|
||||
|
||||
@@ -103,6 +103,7 @@ func getSessionResponse(ctx context.Context, session *models.Principal) (*models
|
||||
}
|
||||
currTime := time.Now().UTC()
|
||||
|
||||
customStyles := session.CustomStyleOb
|
||||
// This actions will be global, meaning has to be attached to all resources
|
||||
conditionValues := map[string][]string{
|
||||
condition.AWSUsername.Name(): {session.AccountAccessKey},
|
||||
@@ -244,6 +245,7 @@ func getSessionResponse(ctx context.Context, session *models.Principal) (*models
|
||||
DistributedMode: erasure,
|
||||
Permissions: resourcePermissions,
|
||||
AllowResources: allowResources,
|
||||
CustomStyles: customStyles,
|
||||
}
|
||||
return sessionResp, nil
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ package restapi
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -40,6 +43,21 @@ import (
|
||||
// more likely then others.
|
||||
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"
|
||||
|
||||
type CustomButtonStyle struct {
|
||||
BackgroundColor *string `json:"backgroundColor"`
|
||||
TextColor *string `json:"textColor"`
|
||||
HoverColor *string `json:"hoverColor"`
|
||||
HoverText *string `json:"hoverText"`
|
||||
ActiveColor *string `json:"activeColor"`
|
||||
ActiveText *string `json:"activeText"`
|
||||
}
|
||||
|
||||
type CustomStyles struct {
|
||||
BackgroundColor *string `json:"backgroundColor"`
|
||||
FontColor *string `json:"fontColor"`
|
||||
ButtonStyles *CustomButtonStyle `json:"buttonStyles"`
|
||||
}
|
||||
|
||||
func RandomCharStringWithAlphabet(n int, alphabet string) string {
|
||||
random := make([]byte, n)
|
||||
if _, err := io.ReadFull(rand.Reader, random); err != nil {
|
||||
@@ -130,6 +148,28 @@ func ExpireSessionCookie() http.Cookie {
|
||||
}
|
||||
}
|
||||
|
||||
func ValidateEncodedStyles(encodedStyles string) error {
|
||||
// encodedStyle JSON validation
|
||||
str, err := base64.StdEncoding.DecodeString(encodedStyles)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var styleElements *CustomStyles
|
||||
|
||||
err = json.Unmarshal(str, &styleElements)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if styleElements.BackgroundColor == nil || styleElements.FontColor == nil || styleElements.ButtonStyles == nil {
|
||||
return errors.New("specified style is not in the correct format")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SanitizeEncodedPrefix replaces spaces for + since those are lost when you do GET parameters
|
||||
func SanitizeEncodedPrefix(rawPrefix string) string {
|
||||
return strings.ReplaceAll(rawPrefix, " ", "+")
|
||||
|
||||
Reference in New Issue
Block a user