Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include the Log Out option when a custom menu is used #867

Merged
merged 2 commits into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it need to be a pointer? We probably want the default to be false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all new properties, we probably want a tri-state value: nil (not set), true, false. This way, the property doesn't get persisted as part of the CR, and we can have different defaults depending on the platform.

}

// 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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sign_in for log out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes :)

"anchorTarget": "_self",
}

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

func unknownStorage(typ string) bool {
Expand Down
Loading