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

Side by Side Diff: tokenserver/appengine/impl/machinetoken/rpc_mint_machine_token.go

Issue 2951393002: [errors] de-specialize Transient in favor of Tags. (Closed)
Patch Set: more refactor 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 machinetoken 5 package machinetoken
6 6
7 import ( 7 import (
8 "crypto/x509" 8 "crypto/x509"
9 "fmt" 9 "fmt"
10 "strings" 10 "strings"
11 "time" 11 "time"
12 12
13 "github.com/golang/protobuf/proto" 13 "github.com/golang/protobuf/proto"
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/gae/service/info" 18 "github.com/luci/gae/service/info"
19 "github.com/luci/luci-go/common/clock" 19 "github.com/luci/luci-go/common/clock"
20 "github.com/luci/luci-go/common/errors"
21 "github.com/luci/luci-go/common/logging" 20 "github.com/luci/luci-go/common/logging"
22 "github.com/luci/luci-go/common/proto/google" 21 "github.com/luci/luci-go/common/proto/google"
22 "github.com/luci/luci-go/common/retry/transient"
23 "github.com/luci/luci-go/server/auth" 23 "github.com/luci/luci-go/server/auth"
24 "github.com/luci/luci-go/server/auth/signing" 24 "github.com/luci/luci-go/server/auth/signing"
25 25
26 tokenserver "github.com/luci/luci-go/tokenserver/api" 26 tokenserver "github.com/luci/luci-go/tokenserver/api"
27 "github.com/luci/luci-go/tokenserver/api/admin/v1" 27 "github.com/luci/luci-go/tokenserver/api/admin/v1"
28 "github.com/luci/luci-go/tokenserver/api/minter/v1" 28 "github.com/luci/luci-go/tokenserver/api/minter/v1"
29 29
30 "github.com/luci/luci-go/tokenserver/appengine/impl/certchecker" 30 "github.com/luci/luci-go/tokenserver/appengine/impl/certchecker"
31 "github.com/luci/luci-go/tokenserver/appengine/impl/certconfig" 31 "github.com/luci/luci-go/tokenserver/appengine/impl/certconfig"
32 "github.com/luci/luci-go/tokenserver/appengine/impl/utils" 32 "github.com/luci/luci-go/tokenserver/appengine/impl/utils"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 TokenResponse: &minter.MachineTokenResponse{ 209 TokenResponse: &minter.MachineTokenResponse{
210 ServiceVersion: serviceVer, 210 ServiceVersion: serviceVer,
211 TokenType: &minter.MachineTokenResponse_LuciMach ineToken{ 211 TokenType: &minter.MachineTokenResponse_LuciMach ineToken{
212 LuciMachineToken: &minter.LuciMachineTok en{ 212 LuciMachineToken: &minter.LuciMachineTok en{
213 MachineToken: signedToken, 213 MachineToken: signedToken,
214 Expiry: google.NewTimestam p(expiry), 214 Expiry: google.NewTimestam p(expiry),
215 }, 215 },
216 }, 216 },
217 }, 217 },
218 }, body, nil 218 }, body, nil
219 » case errors.IsTransient(err): 219 » case transient.Tag.In(err):
220 return nil, nil, grpc.Errorf(codes.Internal, "failed to generate machine token - %s", err) 220 return nil, nil, grpc.Errorf(codes.Internal, "failed to generate machine token - %s", err)
221 default: 221 default:
222 resp, err := r.mintingErrorResponse(c, minter.ErrorCode_MACHINE_ TOKEN_MINTING_ERROR, "%s", err) 222 resp, err := r.mintingErrorResponse(c, minter.ErrorCode_MACHINE_ TOKEN_MINTING_ERROR, "%s", err)
223 return resp, nil, err 223 return resp, nil, err
224 } 224 }
225 } 225 }
226 226
227 func (r *MintMachineTokenRPC) mintingErrorResponse(c context.Context, code minte r.ErrorCode, msg string, args ...interface{}) (*minter.MintMachineTokenResponse, error) { 227 func (r *MintMachineTokenRPC) mintingErrorResponse(c context.Context, code minte r.ErrorCode, msg string, args ...interface{}) (*minter.MintMachineTokenResponse, error) {
228 serviceVer, err := utils.ServiceVersion(c, r.Signer) 228 serviceVer, err := utils.ServiceVersion(c, r.Signer)
229 if err != nil { 229 if err != nil {
230 return nil, grpc.Errorf(codes.Internal, "can't grab service vers ion - %s", err) 230 return nil, grpc.Errorf(codes.Internal, "can't grab service vers ion - %s", err)
231 } 231 }
232 return &minter.MintMachineTokenResponse{ 232 return &minter.MintMachineTokenResponse{
233 ErrorCode: code, 233 ErrorCode: code,
234 ErrorMessage: fmt.Sprintf(msg, args...), 234 ErrorMessage: fmt.Sprintf(msg, args...),
235 ServiceVersion: serviceVer, 235 ServiceVersion: serviceVer,
236 }, nil 236 }, nil
237 } 237 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698