Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 // At this point we trust what's in MachineTokenRequest, proceed with | 133 // At this point we trust what's in MachineTokenRequest, proceed with |
| 134 // generating the token. | 134 // generating the token. |
| 135 args := mintTokenArgs{ | 135 args := mintTokenArgs{ |
| 136 Config: ca.ParsedConfig, | 136 Config: ca.ParsedConfig, |
| 137 Cert: cert, | 137 Cert: cert, |
| 138 Request: &tokenReq, | 138 Request: &tokenReq, |
| 139 } | 139 } |
| 140 switch tokenReq.TokenType { | 140 switch tokenReq.TokenType { |
| 141 case tokenserver.MachineTokenType_LUCI_MACHINE_TOKEN: | 141 case tokenserver.MachineTokenType_LUCI_MACHINE_TOKEN: |
| 142 resp, body, err := r.mintLuciMachineToken(c, args) | 142 resp, body, err := r.mintLuciMachineToken(c, args) |
| 143 » » if err != nil { | 143 » » switch { |
| 144 » » case err != nil: // grpc-level error | |
| 144 return nil, err | 145 return nil, err |
| 146 case resp == nil: // should not happen | |
| 147 panic("both resp and err can't be nil") | |
| 148 case resp.ErrorCode != 0: // logic-level error | |
|
Vadim Sh.
2017/06/20 03:49:50
this is the actual fix: don't try to log the token
| |
| 149 if resp.TokenResponse != nil { | |
| 150 panic("TokenResponse must be nil if ErrorCode != 0") | |
| 151 } | |
| 152 return resp, nil | |
| 153 } | |
| 154 if resp.TokenResponse == nil { | |
| 155 panic("TokenResponse must not be nil if ErrorCode == 0") | |
| 145 } | 156 } |
| 146 if r.LogToken != nil { | 157 if r.LogToken != nil { |
| 147 // Errors during logging are considered not fatal. bqlog library has | 158 // Errors during logging are considered not fatal. bqlog library has |
| 148 // a monitoring counter that tracks number of errors, so they are not | 159 // a monitoring counter that tracks number of errors, so they are not |
| 149 // totally invisible. | 160 // totally invisible. |
| 150 tokInfo := MintedTokenInfo{ | 161 tokInfo := MintedTokenInfo{ |
| 151 Request: &tokenReq, | 162 Request: &tokenReq, |
| 152 Response: resp.TokenResponse, | 163 Response: resp.TokenResponse, |
| 153 TokenBody: body, | 164 TokenBody: body, |
| 154 CA: ca, | 165 CA: ca, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 serviceVer, err := utils.ServiceVersion(c, r.Signer) | 228 serviceVer, err := utils.ServiceVersion(c, r.Signer) |
| 218 if err != nil { | 229 if err != nil { |
| 219 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) |
| 220 } | 231 } |
| 221 return &minter.MintMachineTokenResponse{ | 232 return &minter.MintMachineTokenResponse{ |
| 222 ErrorCode: code, | 233 ErrorCode: code, |
| 223 ErrorMessage: fmt.Sprintf(msg, args...), | 234 ErrorMessage: fmt.Sprintf(msg, args...), |
| 224 ServiceVersion: serviceVer, | 235 ServiceVersion: serviceVer, |
| 225 }, nil | 236 }, nil |
| 226 } | 237 } |
| OLD | NEW |