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

Side by Side Diff: logdog/appengine/coordinator/context.go

Issue 2626433004: Move "common/config" common types into cfgtypes. (Closed)
Patch Set: Created 3 years, 11 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 LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package coordinator 5 package coordinator
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 9
10 "github.com/luci/gae/service/info" 10 "github.com/luci/gae/service/info"
11 luciConfig "github.com/luci/luci-go/common/config" 11 luciConfig "github.com/luci/luci-go/common/config"
12 log "github.com/luci/luci-go/common/logging" 12 log "github.com/luci/luci-go/common/logging"
13 "github.com/luci/luci-go/grpc/grpcutil" 13 "github.com/luci/luci-go/grpc/grpcutil"
14 "github.com/luci/luci-go/logdog/api/config/svcconfig" 14 "github.com/luci/luci-go/logdog/api/config/svcconfig"
15 "github.com/luci/luci-go/logdog/appengine/coordinator/config" 15 "github.com/luci/luci-go/logdog/appengine/coordinator/config"
16 "github.com/luci/luci-go/luci_config/common/cfgtypes"
16 "github.com/luci/luci-go/server/auth" 17 "github.com/luci/luci-go/server/auth"
17 "github.com/luci/luci-go/server/auth/identity" 18 "github.com/luci/luci-go/server/auth/identity"
18 19
19 "golang.org/x/net/context" 20 "golang.org/x/net/context"
20 "google.golang.org/grpc/codes" 21 "google.golang.org/grpc/codes"
21 ) 22 )
22 23
23 // NamespaceAccessType specifies the type of namespace access that is being 24 // NamespaceAccessType specifies the type of namespace access that is being
24 // requested for WithProjectNamespace. 25 // requested for WithProjectNamespace.
25 type NamespaceAccessType int 26 type NamespaceAccessType int
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // It will return a user-facing wrapped gRPC error on failure: 69 // It will return a user-facing wrapped gRPC error on failure:
69 // - InvalidArgument if the project name is invalid. 70 // - InvalidArgument if the project name is invalid.
70 // - If the project exists, then 71 // - If the project exists, then
71 // - nil, if the user has the requested access. 72 // - nil, if the user has the requested access.
72 // - Unauthenticated if the user does not have the requested access, but is 73 // - Unauthenticated if the user does not have the requested access, but is
73 // also not authenticated. This lets them know they should try again af ter 74 // also not authenticated. This lets them know they should try again af ter
74 // authenticating. 75 // authenticating.
75 // - PermissionDenied if the user does not have the requested access. 76 // - PermissionDenied if the user does not have the requested access.
76 // - PermissionDenied if the project doesn't exist. 77 // - PermissionDenied if the project doesn't exist.
77 // - Internal if an internal error occurred. 78 // - Internal if an internal error occurred.
78 func WithProjectNamespace(c *context.Context, project luciConfig.ProjectName, at NamespaceAccessType) error { 79 func WithProjectNamespace(c *context.Context, project cfgtypes.ProjectName, at N amespaceAccessType) error {
79 ctx := *c 80 ctx := *c
80 81
81 if err := project.Validate(); err != nil { 82 if err := project.Validate(); err != nil {
82 log.WithError(err).Errorf(ctx, "Project name is invalid.") 83 log.WithError(err).Errorf(ctx, "Project name is invalid.")
83 return grpcutil.Errf(codes.InvalidArgument, "Project name is inv alid: %s", err) 84 return grpcutil.Errf(codes.InvalidArgument, "Project name is inv alid: %s", err)
84 } 85 }
85 86
86 // Return gRPC error for when the user is denied access and does not hav e READ 87 // Return gRPC error for when the user is denied access and does not hav e READ
87 // access. Returns either Unauthenticated if the user is not authenticat ed 88 // access. Returns either Unauthenticated if the user is not authenticat ed
88 // or PermissionDenied if the user is authenticated. 89 // or PermissionDenied if the user is authenticated.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 *c = nc 182 *c = nc
182 return nil 183 return nil
183 } 184 }
184 185
185 // Project returns the current project installed in the supplied Context's 186 // Project returns the current project installed in the supplied Context's
186 // namespace. 187 // namespace.
187 // 188 //
188 // This function is called with the expectation that the Context is in a 189 // This function is called with the expectation that the Context is in a
189 // namespace conforming to ProjectNamespace. If this is not the case, this 190 // namespace conforming to ProjectNamespace. If this is not the case, this
190 // method will panic. 191 // method will panic.
191 func Project(c context.Context) luciConfig.ProjectName { 192 func Project(c context.Context) cfgtypes.ProjectName {
192 ns := info.GetNamespace(c) 193 ns := info.GetNamespace(c)
193 project := ProjectFromNamespace(ns) 194 project := ProjectFromNamespace(ns)
194 if project != "" { 195 if project != "" {
195 return project 196 return project
196 } 197 }
197 panic(fmt.Errorf("current namespace %q does not begin with project names pace prefix (%q)", ns, projectNamespacePrefix)) 198 panic(fmt.Errorf("current namespace %q does not begin with project names pace prefix (%q)", ns, projectNamespacePrefix))
198 } 199 }
OLDNEW
« no previous file with comments | « logdog/appengine/coordinator/config/projects.go ('k') | logdog/appengine/coordinator/context_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698