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

Side by Side Diff: grpc/prpc/server.go

Issue 2951393002: [errors] de-specialize Transient in favor of Tags. (Closed)
Patch Set: copyright 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 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 prpc 5 package prpc
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "net/http" 9 "net/http"
10 "sort" 10 "sort"
11 "strings" 11 "strings"
12 "sync" 12 "sync"
13 13
14 "golang.org/x/net/context" 14 "golang.org/x/net/context"
15 "google.golang.org/grpc" 15 "google.golang.org/grpc"
16 "google.golang.org/grpc/codes" 16 "google.golang.org/grpc/codes"
17 17
18 "github.com/luci/luci-go/common/errors"
19 "github.com/luci/luci-go/common/logging" 18 "github.com/luci/luci-go/common/logging"
19 "github.com/luci/luci-go/common/retry"
20 "github.com/luci/luci-go/server/router" 20 "github.com/luci/luci-go/server/router"
21 ) 21 )
22 22
23 var ( 23 var (
24 // Describe the permitted Access Control requests. 24 // Describe the permitted Access Control requests.
25 allowHeaders = strings.Join([]string{"Origin", "Content-Type", "Accept", "Authorization"}, ", ") 25 allowHeaders = strings.Join([]string{"Origin", "Content-Type", "Accept", "Authorization"}, ", ")
26 allowMethods = strings.Join([]string{"OPTIONS", "POST"}, ", ") 26 allowMethods = strings.Join([]string{"OPTIONS", "POST"}, ", ")
27 27
28 // allowPreflightCacheAgeSecs is the amount of time to enable the browse r to 28 // allowPreflightCacheAgeSecs is the amount of time to enable the browse r to
29 // cache the preflight access control response, in seconds. 29 // cache the preflight access control response, in seconds.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 if a == nil { 112 if a == nil {
113 a = GetDefaultAuth() 113 a = GetDefaultAuth()
114 if a == nil { 114 if a == nil {
115 panic("prpc: no custom Authenticator was provided and de fault authenticator was not registered.\n" + 115 panic("prpc: no custom Authenticator was provided and de fault authenticator was not registered.\n" +
116 "Either explicitly set `Server.Authenticator = N oAuthentication`, or use RegisterDefaultAuth()") 116 "Either explicitly set `Server.Authenticator = N oAuthentication`, or use RegisterDefaultAuth()")
117 } 117 }
118 } 118 }
119 119
120 return func(c *router.Context, next router.Handler) { 120 return func(c *router.Context, next router.Handler) {
121 switch ctx, err := a.Authenticate(c.Context, c.Request); { 121 switch ctx, err := a.Authenticate(c.Context, c.Request); {
122 » » case errors.IsTransient(err): 122 » » case retry.Tag.In(err):
123 res := errResponse(codes.Internal, http.StatusInternalSe rverError, escapeFmt(err.Error())) 123 res := errResponse(codes.Internal, http.StatusInternalSe rverError, escapeFmt(err.Error()))
124 res.write(c.Context, c.Writer) 124 res.write(c.Context, c.Writer)
125 case err != nil: 125 case err != nil:
126 res := errResponse(codes.Unauthenticated, http.StatusUna uthorized, escapeFmt(err.Error())) 126 res := errResponse(codes.Unauthenticated, http.StatusUna uthorized, escapeFmt(err.Error()))
127 res.write(c.Context, c.Writer) 127 res.write(c.Context, c.Writer)
128 default: 128 default:
129 c.Context = ctx 129 c.Context = ctx
130 next(c) 130 next(c)
131 } 131 }
132 } 132 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 s.mu.Lock() 220 s.mu.Lock()
221 defer s.mu.Unlock() 221 defer s.mu.Unlock()
222 222
223 names := make([]string, 0, len(s.services)) 223 names := make([]string, 0, len(s.services))
224 for name := range s.services { 224 for name := range s.services {
225 names = append(names, name) 225 names = append(names, name)
226 } 226 }
227 sort.Strings(names) 227 sort.Strings(names)
228 return names 228 return names
229 } 229 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698