| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The LUCI Authors. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 | |
| 15 package frontend | |
| 16 | |
| 17 import ( | |
| 18 "net/http" | |
| 19 | |
| 20 "cloud.google.com/go/datastore" | |
| 21 "google.golang.org/appengine" | |
| 22 | |
| 23 "github.com/luci/luci-go/common/logging" | |
| 24 "github.com/luci/luci-go/milo/common" | |
| 25 "github.com/luci/luci-go/server/router" | |
| 26 "github.com/luci/luci-go/server/templates" | |
| 27 ) | |
| 28 | |
| 29 // ConfigsHandler renders the page showing the currently loaded set of luci-conf
igs. | |
| 30 func ConfigsHandler(c *router.Context) { | |
| 31 projects, err := common.GetAllProjects(c.Context) | |
| 32 if err != nil { | |
| 33 common.ErrorPage( | |
| 34 c, http.StatusInternalServerError, | |
| 35 "Error while getting projects: "+err.Error()) | |
| 36 return | |
| 37 } | |
| 38 sc, err := common.GetCurrentServiceConfig(c.Context) | |
| 39 if err != nil && err != datastore.ErrNoSuchEntity { | |
| 40 common.ErrorPage( | |
| 41 c, http.StatusInternalServerError, | |
| 42 "Error while getting service config: "+err.Error()) | |
| 43 return | |
| 44 } | |
| 45 | |
| 46 templates.MustRender(c.Context, c.Writer, "pages/configs.html", template
s.Args{ | |
| 47 "Projects": projects, | |
| 48 "ServiceConfig": sc, | |
| 49 }) | |
| 50 } | |
| 51 | |
| 52 // UpdateHandler is an HTTP handler that handles configuration update requests. | |
| 53 func UpdateConfigHandler(ctx *router.Context) { | |
| 54 c, h := ctx.Context, ctx.Writer | |
| 55 // Needed to access the PubSub API | |
| 56 c = appengine.WithContext(c, ctx.Request) | |
| 57 projErr := common.UpdateProjectConfigs(c) | |
| 58 if projErr != nil { | |
| 59 logging.WithError(projErr).Errorf(c, "project update handler enc
ountered error") | |
| 60 } | |
| 61 settings, servErr := common.UpdateServiceConfig(c) | |
| 62 if servErr != nil { | |
| 63 logging.WithError(servErr).Errorf(c, "service update handler enc
ountered error") | |
| 64 } else { | |
| 65 servErr = common.EnsurePubSubSubscribed(c, settings) | |
| 66 if servErr != nil { | |
| 67 logging.WithError(servErr).Errorf( | |
| 68 c, "pubsub subscriber handler encountered error"
) | |
| 69 } | |
| 70 } | |
| 71 if projErr != nil || servErr != nil { | |
| 72 h.WriteHeader(http.StatusInternalServerError) | |
| 73 return | |
| 74 } | |
| 75 h.WriteHeader(http.StatusOK) | |
| 76 } | |
| OLD | NEW |