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

Side by Side Diff: appengine/logdog/coordinator/endpoints/admin/setConfig.go

Issue 1863973002: LogDog: Update to archival V2. (Closed) Base URL: https://github.com/luci/luci-go@grpcutil-errors
Patch Set: Code review comments, use Pub/Sub, archival staging, quality of life. Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package admin 5 package admin
6 6
7 import ( 7 import (
8 "github.com/luci/gae/service/info"
9 "github.com/luci/luci-go/appengine/logdog/coordinator/config" 8 "github.com/luci/luci-go/appengine/logdog/coordinator/config"
10 "github.com/luci/luci-go/common/api/logdog_coordinator/admin/v1" 9 "github.com/luci/luci-go/common/api/logdog_coordinator/admin/v1"
11 "github.com/luci/luci-go/common/grpcutil" 10 "github.com/luci/luci-go/common/grpcutil"
12 log "github.com/luci/luci-go/common/logging" 11 log "github.com/luci/luci-go/common/logging"
13 "github.com/luci/luci-go/common/proto/google" 12 "github.com/luci/luci-go/common/proto/google"
14 "github.com/luci/luci-go/server/auth"
15 "golang.org/x/net/context" 13 "golang.org/x/net/context"
16 "google.golang.org/grpc/codes" 14 "google.golang.org/grpc/codes"
17 ) 15 )
18 16
19 // SetConfig loads the supplied configuration into a config.GlobalConfig 17 // SetConfig loads the supplied configuration into a config.GlobalConfig
20 // instance. 18 // instance.
21 func (s *Server) SetConfig(c context.Context, req *logdog.SetConfigRequest) (*go ogle.Empty, error) { 19 func (s *Server) SetConfig(c context.Context, req *logdog.SetConfigRequest) (*go ogle.Empty, error) {
22 » // The user must be an administrator. 20 » svc := s.GetServices()
23 » if err := config.IsAdminUser(c); err != nil { 21 » if err := s.Auth(c, svc); err != nil {
24 » » log.Fields{ 22 » » return nil, err
25 » » » log.ErrorKey: err,
26 » » }.Warningf(c, "User is not an administrator.")
27
28 » » // If we're on development server, any user can set the initial config.
29 » » if !info.Get(c).IsDevAppServer() {
30 » » » u := auth.CurrentUser(c)
31 » » » if !(u != nil && u.Superuser) {
32 » » » » return nil, grpcutil.PermissionDenied
33 » » » }
34
35 » » » log.Fields{
36 » » » » "email": u.Email,
37 » » » » "clientID": u.ClientID,
38 » » » » "name": u.Name,
39 » » » }.Infof(c, "User is an AppEngine superuser. Granting acc ess.")
40 » » }
41 } 23 }
42 24
43 gcfg := config.GlobalConfig{ 25 gcfg := config.GlobalConfig{
44 ConfigServiceURL: req.ConfigServiceUrl, 26 ConfigServiceURL: req.ConfigServiceUrl,
45 ConfigSet: req.ConfigSet, 27 ConfigSet: req.ConfigSet,
46 ConfigPath: req.ConfigPath, 28 ConfigPath: req.ConfigPath,
47 BigTableServiceAccountJSON: req.StorageServiceAccountJson, 29 BigTableServiceAccountJSON: req.StorageServiceAccountJson,
48 } 30 }
49 if err := gcfg.Validate(); err != nil { 31 if err := gcfg.Validate(); err != nil {
50 log.Fields{ 32 log.Fields{
51 log.ErrorKey: err, 33 log.ErrorKey: err,
52 }.Errorf(c, "New configuration did not validate.") 34 }.Errorf(c, "New configuration did not validate.")
53 return nil, grpcutil.Errf(codes.InvalidArgument, "config did not validate: %v", err) 35 return nil, grpcutil.Errf(codes.InvalidArgument, "config did not validate: %v", err)
54 } 36 }
55 37
56 if err := gcfg.Store(c, "setConfig endpoint"); err != nil { 38 if err := gcfg.Store(c, "setConfig endpoint"); err != nil {
57 log.Fields{ 39 log.Fields{
58 log.ErrorKey: err, 40 log.ErrorKey: err,
59 }.Errorf(c, "Failed to store new configuration.") 41 }.Errorf(c, "Failed to store new configuration.")
60 return nil, grpcutil.Internal 42 return nil, grpcutil.Internal
61 } 43 }
62 return &google.Empty{}, nil 44 return &google.Empty{}, nil
63 } 45 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698