Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(756)

Unified Diff: milo/common/middleware.go

Issue 2977863002: [milo] Refactor all html knowledge out of backends. (Closed)
Patch Set: now with case insensitivity Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « milo/common/funcs_test.go ('k') | milo/common/utils.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: milo/common/middleware.go
diff --git a/milo/common/middleware.go b/milo/common/middleware.go
deleted file mode 100644
index 9a80a43394e4afd7c3a064071a33b4e7649e7ffd..0000000000000000000000000000000000000000
--- a/milo/common/middleware.go
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright 2015 The LUCI Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package common
-
-import (
- "net/http"
- "strings"
-
- "golang.org/x/net/context"
-
- "github.com/luci/gae/impl/cloud"
- "github.com/luci/gae/service/info"
- "github.com/luci/luci-go/appengine/gaeauth/server"
- "github.com/luci/luci-go/appengine/gaemiddleware"
- "github.com/luci/luci-go/common/clock"
- "github.com/luci/luci-go/server/analytics"
- "github.com/luci/luci-go/server/auth"
- "github.com/luci/luci-go/server/auth/identity"
- "github.com/luci/luci-go/server/router"
- "github.com/luci/luci-go/server/templates"
-)
-
-var authconfig *auth.Config
-
-// GetTemplateBundles is used to render HTML templates. It provides base args
-// passed to all templates. It takes a path to the template folder, relative
-// to the path of the binary during runtime.
-func GetTemplateBundle(templatePath string) *templates.Bundle {
- return &templates.Bundle{
- Loader: templates.FileSystemLoader(templatePath),
- DebugMode: info.IsDevAppServer,
- DefaultTemplate: "base",
- DefaultArgs: func(c context.Context) (templates.Args, error) {
- r := getRequest(c)
- path := r.URL.Path
- loginURL, err := auth.LoginURL(c, path)
- if err != nil {
- return nil, err
- }
- logoutURL, err := auth.LogoutURL(c, path)
- if err != nil {
- return nil, err
- }
- return templates.Args{
- "AppVersion": strings.Split(info.VersionID(c), ".")[0],
- "IsAnonymous": auth.CurrentIdentity(c) == identity.AnonymousIdentity,
- "User": auth.CurrentUser(c),
- "LoginURL": loginURL,
- "LogoutURL": logoutURL,
- "CurrentTime": clock.Now(c),
- "Analytics": analytics.Snippet(c),
- "RequestID": info.RequestID(c),
- "Request": r,
- }, nil
- },
- FuncMap: funcMap,
- }
-}
-
-// Base returns the basic LUCI appengine middlewares.
-func Base(templatePath string) router.MiddlewareChain {
- return gaemiddleware.BaseProd().Extend(
- auth.Authenticate(server.CookieAuth),
- withRequestMiddleware,
- templates.WithTemplates(GetTemplateBundle(templatePath)),
- )
-}
-
-// FlexBase returns the basic middleware for use on appengine flex. Flex does not
-// allow the use of appengine APIs.
-func FlexBase() router.MiddlewareChain {
- // Installs the Info and Datastore services.
- return router.NewMiddlewareChain(func(c *router.Context, next router.Handler) {
- c.Context = cloud.UseFlex(c.Context)
- next(c)
- })
-}
-
-// The context key, so that we can embed the http.Request object into
-// the context.
-var requestKey = "http.request"
-
-// WithRequest returns a context with the http.Request object
-// in it.
-func WithRequest(c context.Context, r *http.Request) context.Context {
- return context.WithValue(c, &requestKey, r)
-}
-
-// withRequestMiddleware is a middleware that installs a request into the context.
-// This is used for various things in the default template.
-func withRequestMiddleware(c *router.Context, next router.Handler) {
- c.Context = WithRequest(c.Context, c.Request)
- next(c)
-}
-
-func getRequest(c context.Context) *http.Request {
- if req, ok := c.Value(&requestKey).(*http.Request); ok {
- return req
- }
- panic("No http.request found in context")
-}
« no previous file with comments | « milo/common/funcs_test.go ('k') | milo/common/utils.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698