Use the update access token for renew_lease calls instead of user access token (#3348)

* Change RenewUpdateLease to use the update access token as the Bearer token.

* Deprecate the Token property in RenewUpdateLeaseRequest.
This commit is contained in:
Praneet Loke 2019-11-05 13:32:31 -08:00 committed by GitHub
parent 7353b18a30
commit 1fe3f0f46e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 4 deletions

View file

@ -1,6 +1,11 @@
CHANGELOG
=========
## HEAD (Unreleased)
- Use the update token for renew_lease calls and update the API version to 5.
[#3348](https://github.com/pulumi/pulumi/pull/3348)
## 1.4.1 (2019-11-01)
- Adds a **preview** of .NET support for Pulumi. This code is an preview state and is subject

View file

@ -173,6 +173,9 @@ type UpdateProgram struct {
// RenewUpdateLeaseRequest defines the body of a request to the update lease renewal endpoint of the service API.
type RenewUpdateLeaseRequest struct {
// The current, valid lease token.
// DEPRECATED as of Pulumi API version 5+. Pulumi API will expect the update token
// in the Authorization header instead of this property. This property will be removed
// when the minimum supported API version on the service is raised to 5.
Token string `json:"token"`
// The duration for which to renew the lease in seconds (maximum 300).
Duration int `json:"duration"`

View file

@ -165,7 +165,7 @@ func pulumiAPICall(ctx context.Context, d diag.Sink, cloudAPI, method, path stri
userAgent := fmt.Sprintf("pulumi-cli/1 (%s; %s)", version.Version, runtime.GOOS)
req.Header.Set("User-Agent", userAgent)
// Specify the specific API version we accept.
req.Header.Set("Accept", "application/vnd.pulumi+4")
req.Header.Set("Accept", "application/vnd.pulumi+5")
// Apply credentials if provided.
if tok.String() != "" {

View file

@ -596,7 +596,6 @@ func (pc *Client) RenewUpdateLease(ctx context.Context, update UpdateIdentifier,
duration time.Duration) (string, error) {
req := apitype.RenewUpdateLeaseRequest{
Token: token,
Duration: int(duration / time.Second),
}
var resp apitype.RenewUpdateLeaseResponse
@ -604,8 +603,8 @@ func (pc *Client) RenewUpdateLease(ctx context.Context, update UpdateIdentifier,
// While renewing a lease uses POST, it is safe to send multiple requests (consider that we do this multiple times
// during a long running update). Since we would fail our update operation if we can't renew our lease, we'll retry
// these POST operations.
if err := pc.restCallWithOptions(ctx, "POST", getUpdatePath(update, "renew_lease"), nil,
req, &resp, httpCallOptions{RetryAllMethods: true}); err != nil {
if err := pc.updateRESTCall(ctx, "POST", getUpdatePath(update, "renew_lease"), nil, req, &resp,
updateAccessToken(token), httpCallOptions{RetryAllMethods: true}); err != nil {
return "", err
}
return resp.Token, nil