-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure sdkv2 replace mirrors the bridge replace (#248)
Fixes #243 After this change the terraform SDK v2 override follows the replace from the selected bridge version exactly. I think this is what we want - this is compensating for the inability of Go tooling to propagate the replace to dependencies. The change also starts to unconditionally insert this replace. This is because on the latest bridge tfgen somehow depends on sdkv2 and even providers such as pulumi-random that presumably do not need sdkv2 now depend on it and need the replace accordingly, see pulumi/pulumi-random#687 for example.
- Loading branch information
Showing
5 changed files
with
145 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// HTTP-related effects. | ||
package upgrade | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
// Use this function in steps to perform HTTP GET. | ||
func getHTTP(ctx context.Context, url string) ([]byte, error) { | ||
h, ok := ctx.Value(httpHandlerKey).(httpHandler) | ||
if !ok { | ||
h = &defaultHttpHandler{ | ||
retryAttempts: 5, | ||
delay: func(attempt int) time.Duration { | ||
n := (attempt + 1) * (attempt + 1) | ||
return time.Duration(n) * time.Second | ||
}, | ||
} | ||
} | ||
return h.getHTTP(url) | ||
} | ||
|
||
// Set this to a mock in tests to avoid hitting actual HTTP. | ||
type httpHandler interface { | ||
getHTTP(url string) ([]byte, error) | ||
} | ||
|
||
var httpHandlerKey = struct{}{} | ||
|
||
type defaultHttpHandler struct { | ||
retryAttempts int | ||
delay func(attempt int) time.Duration | ||
} | ||
|
||
func (*defaultHttpHandler) tryGetHTTP(url string) (content []byte, finalError error) { | ||
resp, err := http.Get(url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer func() { | ||
if err := resp.Body.Close(); err != nil && finalError == nil { | ||
finalError = err | ||
} | ||
}() | ||
if resp.StatusCode != 200 { | ||
return nil, fmt.Errorf("Non-200 code for GET %v: %v", url, resp.StatusCode) | ||
} | ||
respBytes, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if err := resp.Body.Close(); err != nil { | ||
return nil, err | ||
} | ||
return respBytes, nil | ||
} | ||
|
||
func (h *defaultHttpHandler) getHTTP(url string) ([]byte, error) { | ||
var c []byte | ||
var err error | ||
for attempt := 0; attempt < h.retryAttempts; attempt++ { | ||
c, err = h.tryGetHTTP(url) | ||
if err == nil { | ||
return c, nil | ||
} | ||
time.Sleep(h.delay(attempt)) | ||
} | ||
return nil, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters