config: Avoid stale credentials in memory. (#4466)

This commit is contained in:
Harshavardhana
2017-08-08 12:14:32 -07:00
committed by GitHub
parent 6f7ace3d3e
commit f346ca44f0
4 changed files with 26 additions and 7 deletions

View File

@@ -181,8 +181,14 @@ func (adminAPI adminAPIHandlers) ServiceCredentialsHandler(w http.ResponseWriter
}
// Update local credentials in memory.
serverConfig.SetCredential(creds)
prevCred := serverConfig.SetCredential(creds)
// Save credentials to config file
if err = serverConfig.Save(); err != nil {
// Save the current creds when failed to update.
serverConfig.SetCredential(prevCred)
errorIf(err, "Unable to update the config with new credentials.")
writeErrorResponse(w, ErrInternalError, r.URL)
return
}