Skip to content

Commit

Permalink
Accept custom logo image as a file
Browse files Browse the repository at this point in the history
  • Loading branch information
spadgett authored and rhamilto committed Apr 15, 2019
1 parent 6e5740a commit 74e2446
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
10 changes: 10 additions & 0 deletions cmd/bridge/config.go
Expand Up @@ -55,6 +55,8 @@ type Auth struct {
type Customization struct {
Branding string `yaml:"branding"`
DocumentationBaseURL string `yaml:"documentationBaseURL"`
CustomProductName string `yaml:"customProductName"`
CustomLogoFile string `yaml:"customLogoFile"`
}

// SetFlagsFromConfig sets flag values based on a YAML config file.
Expand Down Expand Up @@ -175,4 +177,12 @@ func addCustomization(fs *flag.FlagSet, customization *Customization) {
if customization.DocumentationBaseURL != "" {
fs.Set("documentation-base-url", customization.DocumentationBaseURL)
}

if customization.CustomProductName != "" {
fs.Set("custom-product-name", customization.CustomProductName)
}

if customization.CustomLogoFile != "" {
fs.Set("custom-logo-file", customization.CustomLogoFile)
}
}
13 changes: 8 additions & 5 deletions cmd/bridge/main.go
Expand Up @@ -85,7 +85,7 @@ func main() {
fDexAPIHost := fs.String("dex-api-host", "", "Target host and port of the Dex API service.")
fBranding := fs.String("branding", "okd", "Console branding for the masthead logo and title. One of okd, openshift, ocp, online, dedicated, or azure. Defaults to okd.")
fCustomProductName := fs.String("custom-product-name", "", "Custom product name for console branding.")
fCustomLogoImage := fs.String("custom-logo-image", "", "Custom product image for console branding.")
fCustomLogoFile := fs.String("custom-logo-file", "", "Custom product image for console branding.")
fDocumentationBaseURL := fs.String("documentation-base-url", "", "The base URL for documentation links.")
fGoogleTagManagerID := fs.String("google-tag-manager-id", "", "Google Tag Manager ID. External analytics are disabled if this is not set.")

Expand Down Expand Up @@ -154,8 +154,11 @@ func main() {
flagFatalf("branding", "value must be one of okd, openshift, ocp, online, dedicated, or azure")
}

customProductName := *fCustomProductName
customLogoImage := *fCustomLogoImage
if *fCustomLogoFile != "" {
if _, err := os.Stat(*fCustomLogoFile); err != nil {
log.Fatalf("could not read logo file: %v", err)
}
}

srv := &server.Server{
PublicDir: *fPublicDir,
Expand All @@ -164,8 +167,8 @@ func main() {
LogoutRedirect: logoutRedirect,
TectonicCACertFile: caCertFilePath,
Branding: branding,
CustomProductName: customProductName,
CustomLogoImage: customLogoImage,
CustomProductName: *fCustomProductName,
CustomLogoFile: *fCustomLogoFile,
DocumentationBaseURL: documentationBaseURL,
GoogleTagManagerID: *fGoogleTagManagerID,
LoadTestFactor: *fLoadTestFactor,
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/components/about-modal.jsx
Expand Up @@ -29,7 +29,7 @@ class AboutModal_ extends React.Component {
const {isOpen, closeAboutModal} = this.props;
const {kubernetesVersion} = this.state;
const details = getBrandingDetails();
const customBranding = window.SERVER_FLAGS.customLogoImage || window.SERVER_FLAGS.customProductName;
const customBranding = window.SERVER_FLAGS.customLogoURL || window.SERVER_FLAGS.customProductName;

return (
<PfAboutModal
Expand Down
4 changes: 2 additions & 2 deletions frontend/public/components/masthead.jsx
Expand Up @@ -39,8 +39,8 @@ export const getBrandingDetails = () => {
logoImg = okdLogoImg;
productName = 'OKD';
}
if (window.SERVER_FLAGS.customLogoImage) {
logoImg = window.SERVER_FLAGS.customLogoImage;
if (window.SERVER_FLAGS.customLogoURL) {
logoImg = window.SERVER_FLAGS.customLogoURL;
}
if (window.SERVER_FLAGS.customProductName) {
productName = window.SERVER_FLAGS.customProductName;
Expand Down
34 changes: 21 additions & 13 deletions server/server.go
Expand Up @@ -32,6 +32,7 @@ const (
prometheusProxyEndpoint = "/api/prometheus"
prometheusTenancyProxyEndpoint = "/api/prometheus-tenancy"
alertManagerProxyEndpoint = "/api/alertmanager"
customLogoEndpoint = "/custom-logo"
)

var (
Expand All @@ -55,7 +56,7 @@ type jsGlobals struct {
AlertManagerBaseURL string `json:"alertManagerBaseURL"`
Branding string `json:"branding"`
CustomProductName string `json:"customProductName"`
CustomLogoImage string `json:"customLogoImage"`
CustomLogoURL string `json:"customLogoURL"`
DocumentationBaseURL string `json:"documentationBaseURL"`
GoogleTagManagerID string `json:"googleTagManagerID"`
LoadTestFactor int `json:"loadTestFactor"`
Expand All @@ -75,7 +76,7 @@ type Server struct {
DocumentationBaseURL *url.URL
Branding string
CustomProductName string
CustomLogoImage string
CustomLogoFile string
GoogleTagManagerID string
LoadTestFactor int
DexClient api.DexClient
Expand Down Expand Up @@ -112,17 +113,15 @@ func (s *Server) HTTPHandler() http.Handler {

fn := func(loginInfo auth.LoginJSON, successURL string, w http.ResponseWriter) {
jsg := struct {
auth.LoginJSON `json:",inline"`
LoginSuccessURL string `json:"loginSuccessURL"`
Branding string `json:"branding"`
CustomProductName string `json:"customProductName"`
CustomLogoImage string `json:"customLogoImage"`
auth.LoginJSON `json:",inline"`
LoginSuccessURL string `json:"loginSuccessURL"`
Branding string `json:"branding"`
CustomProductName string `json:"customProductName"`
}{
LoginJSON: loginInfo,
LoginSuccessURL: successURL,
Branding: s.Branding,
CustomProductName: s.CustomProductName,
CustomLogoImage: s.CustomLogoImage,
LoginJSON: loginInfo,
LoginSuccessURL: successURL,
Branding: s.Branding,
CustomProductName: s.CustomProductName,
}

tpl := template.New(tokenizerPageTemplateName)
Expand Down Expand Up @@ -170,6 +169,12 @@ func (s *Server) HTTPHandler() http.Handler {
staticHandler := http.StripPrefix(proxy.SingleJoiningSlash(s.BaseURL.Path, "/static/"), http.FileServer(http.Dir(s.PublicDir)))
handle("/static/", gzipHandler(securityHeadersMiddleware(staticHandler)))

if s.CustomLogoFile != "" {
handleFunc(customLogoEndpoint, func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, s.CustomLogoFile)
})
}

// Scope of Service Worker needs to be higher than the requests it is intercepting (https://stackoverflow.com/a/35780776/6909941)
handleFunc("/load-test.sw.js", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, path.Join(s.PublicDir, "load-test.sw.js"))
Expand Down Expand Up @@ -263,7 +268,6 @@ func (s *Server) indexHandler(w http.ResponseWriter, r *http.Request) {
KubeAPIServerURL: s.KubeAPIServerURL,
Branding: s.Branding,
CustomProductName: s.CustomProductName,
CustomLogoImage: s.CustomLogoImage,
DocumentationBaseURL: s.DocumentationBaseURL.String(),
GoogleTagManagerID: s.GoogleTagManagerID,
LoadTestFactor: s.LoadTestFactor,
Expand All @@ -286,6 +290,10 @@ func (s *Server) indexHandler(w http.ResponseWriter, r *http.Request) {
s.Auther.SetCSRFCookie(s.BaseURL.Path, &w)
}

if s.CustomLogoFile != "" {
jsg.CustomLogoURL = proxy.SingleJoiningSlash(s.BaseURL.Path, customLogoEndpoint)
}

tpl := template.New(indexPageTemplateName)
tpl.Delims("[[", "]]")
tpls, err := tpl.ParseFiles(path.Join(s.PublicDir, indexPageTemplateName))
Expand Down

0 comments on commit 74e2446

Please sign in to comment.