Skip to content

Commit

Permalink
Include the Log Out option when a custom menu is used (#867)
Browse files Browse the repository at this point in the history
Signed-off-by: Juraci Paixão Kröhling <[email protected]>
  • Loading branch information
jpkrohling authored Jan 21, 2020
1 parent bcff7a4 commit 643cb75
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 61 deletions.
4 changes: 4 additions & 0 deletions deploy/crds/jaegertracing.io_jaegers_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9439,6 +9439,10 @@ spec:
type: string
sar:
type: string
skipLogout:
description: SkipLogout tells the operator to not automatically
add a "Log Out" menu option to the custom Jaeger configuration
type: boolean
type: object
resources:
description: ResourceRequirements describes the compute resource
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/jaegertracing/v1/jaeger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ type JaegerIngressOpenShiftSpec struct {

// +optional
HtpasswdFile string `json:"htpasswdFile,omitempty"`

// SkipLogout tells the operator to not automatically add a "Log Out" menu option to the custom Jaeger configuration
// +optional
SkipLogout *bool `json:"skipLogout,omitempty"`
}

// JaegerAllInOneSpec defines the options to be used when deploying the query
Expand Down
7 changes: 6 additions & 1 deletion pkg/apis/jaegertracing/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/apis/jaegertracing/v1/zz_generated.openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,13 @@ func schema_pkg_apis_jaegertracing_v1_JaegerIngressOpenShiftSpec(ref common.Refe
Format: "",
},
},
"skipLogout": {
SchemaProps: spec.SchemaProps{
Description: "SkipLogout tells the operator to not automatically add a \"Log Out\" menu option to the custom Jaeger configuration",
Type: []string{"boolean"},
Format: "",
},
},
},
},
},
Expand Down
68 changes: 46 additions & 22 deletions pkg/strategy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package strategy

import (
"context"
"encoding/json"
"fmt"
"strings"

Expand Down Expand Up @@ -195,6 +194,7 @@ func normalizeUI(spec *v1.JaegerSpec) {
}
enableArchiveButton(uiOpts, spec.Storage.Options.Map())
disableDependenciesTab(uiOpts, spec.Storage.Type, spec.Storage.Dependencies.Enabled)
enableDocumentationLink(uiOpts, spec)
enableLogOut(uiOpts, spec)
if len(uiOpts) > 0 {
spec.UI.Options = v1.NewFreeForm(uiOpts)
Expand Down Expand Up @@ -233,40 +233,64 @@ func disableDependenciesTab(uiOpts map[string]interface{}, storage string, depsE
}
}

func enableDocumentationLink(uiOpts map[string]interface{}, spec *v1.JaegerSpec) {
if !viper.IsSet("documentation-url") {
return
}

// if a custom menu has been specified, do not add the link to the documentation
if _, ok := uiOpts["menu"]; ok {
return
}

e := map[string]interface{}{
"label": "About",
"items": []interface{}{map[string]interface{}{
"label": "Documentation",
"url": viper.GetString("documentation-url"),
}},
}
uiOpts["menu"] = []interface{}{e}
}

func enableLogOut(uiOpts map[string]interface{}, spec *v1.JaegerSpec) {
if (spec.Ingress.Enabled != nil && *spec.Ingress.Enabled == false) ||
spec.Ingress.Security != v1.IngressSecurityOAuthProxy {
return
}

if _, ok := uiOpts["menu"]; ok {
if spec.Ingress.Openshift.SkipLogout != nil && *spec.Ingress.Openshift.SkipLogout == true {
return
}

docURL := viper.GetString("documentation-url")

menuStr := fmt.Sprintf(`[
{
"label": "About",
"items": [
{
"label": "Documentation",
"url": "%s"
}
]
},
{
"label": "Log Out",
"url": "/oauth/sign_in",
"anchorTarget": "_self"
var menuArray []interface{}
if m, ok := uiOpts["menu"]; ok {
menuArray = m.([]interface{})
}

for _, v := range menuArray {
converted, ok := v.(map[string]interface{})
if !ok {
// not a map, skip
return
}
]`, docURL)

menuArray := make([]interface{}, 2)
// if it has a URL entry, and if the entry contains "/oauth/sign_in", skip
url := fmt.Sprintf("%v", converted["url"])
// this is very naive, but will work for most cases, as that's how the OpenShift OAuth Proxy
// build the URL. If needed, this can be a list of patterns in the future
if strings.Contains(url, "/oauth/sign_in") {
return
}
}

json.Unmarshal([]byte(menuStr), &menuArray)
logout := map[string]interface{}{
"label": "Log Out",
"url": "/oauth/sign_in",
"anchorTarget": "_self",
}

uiOpts["menu"] = menuArray
uiOpts["menu"] = append(menuArray, logout)
}

func unknownStorage(typ string) bool {
Expand Down
Loading

0 comments on commit 643cb75

Please sign in to comment.