Skip to content

Commit

Permalink
Small fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
myidpt committed Jan 28, 2020
1 parent 594537c commit a292f44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 7 additions & 1 deletion security/pkg/nodeagent/cache/helper.go
Expand Up @@ -75,6 +75,12 @@ func isRetryableErr(c codes.Code, httpRespCode int, isGrpc bool) bool {

// cacheLogPrefix returns a unified log prefix.
func cacheLogPrefix(conID, resourceName string) string {
lPrefix := fmt.Sprintf("node:%s resource:%s", conID, resourceName)
lPrefix := fmt.Sprintf("[Node:%s Res:%s]", conID, resourceName)
return lPrefix
}

// cacheLogPrefix returns a unified log prefix.
func cacheLogPrefixWithReqID(conID, resourceName, reqID string) string {
lPrefix := fmt.Sprintf("[Node:%s Res:%s Req:%s]", conID, resourceName, reqID)
return lPrefix
}
11 changes: 6 additions & 5 deletions security/pkg/nodeagent/cache/secretcache.go
Expand Up @@ -825,16 +825,16 @@ func (sc *SecretCache) sendRetriableRequest(ctx context.Context, csrPEM []byte,
time.Sleep(time.Duration(randomizedInitialBackOffInMS) * time.Millisecond)
retryBackoffInMS := int64(firstRetryBackOffInMilliSec)

conIDresourceNamePrefix := cacheLogPrefix(connKey.ConnectionID, connKey.ResourceName)
// Assign a unique request ID for all the retries.
reqID := uuid.New().String()

conIDresourceNamePrefix := cacheLogPrefixWithReqID(connKey.ConnectionID, connKey.ResourceName, reqID)
startTime := time.Now()
var certChainPEM []string
exchangedToken := providedExchangedToken
var requestErrorString string
var err error

// Assign a unique request ID for all the retries.
reqID := uuid.New().String()

// Keep trying until no error or timeout.
for {
var httpRespCode int
Expand All @@ -843,10 +843,11 @@ func (sc *SecretCache) sendRetriableRequest(ctx context.Context, csrPEM []byte,
certChainPEM, err = sc.fetcher.CaClient.CSRSign(
ctx, reqID, csrPEM, exchangedToken, int64(sc.configOptions.SecretTTL.Seconds()))
} else {
requestErrorString = fmt.Sprintf("%s token exchange", conIDresourceNamePrefix)
requestErrorString = fmt.Sprintf("%s TokExch", conIDresourceNamePrefix)
p := sc.configOptions.Plugins[0]
exchangedToken, _, httpRespCode, err = p.ExchangeToken(ctx, sc.configOptions.TrustDomain, exchangedToken)
}
cacheLog.Debugf("%s", requestErrorString)

if err == nil {
break
Expand Down

0 comments on commit a292f44

Please sign in to comment.