Skip to content

Commit 32e3864

Browse files
committed
Only modify the redirect response for requests hitting the artifact service
1 parent 161615e commit 32e3864

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

src/tools/aws.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ func CheckReauth() {
9494
for {
9595
timeSince := time.Since(CodeArtifactAuthInfo.LastAuth).Minutes()
9696
// Panic and shut down the proxy if we couldn't reauthenticate within the 15 minute window for some reason.
97-
if timeSince > float64(5) {
97+
if timeSince > float64(60) {
9898
log.Panic("Was unable to re-authenticate prior to our token expiring, shutting down proxty...")
9999
}
100100

101-
if CodeArtifactAuthInfo.AuthorizationToken == "" || timeSince > float64(1) {
101+
if CodeArtifactAuthInfo.AuthorizationToken == "" || timeSince > float64(45) {
102102
log.Printf("%f minutes until the CodeArtifact token expires, attempting a reauth.", 60-timeSince)
103103
Authenticate()
104104
}

src/tools/proxy.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func ProxyRequestHandler(p *httputil.ReverseProxy) func(http.ResponseWriter, *ht
5050

5151
func ProxyResponseHandler() func(*http.Response) error {
5252
return func(r *http.Response) error {
53-
log.Printf("Received response from %s", r.Request.URL.String())
53+
log.Printf("Received %d response from %s", r.StatusCode, r.Request.URL.String())
5454
log.Printf("RES: %s \"%s\" %d \"%s\" \"%s\"", r.Request.RemoteAddr, r.Request.Method, r.StatusCode, r.Request.RequestURI, r.Request.UserAgent())
5555

5656
contentType := r.Header.Get("Content-Type")
@@ -67,11 +67,15 @@ func ProxyResponseHandler() func(*http.Response) error {
6767
if r.StatusCode == 301 || r.StatusCode == 302 {
6868
location, _ := r.Location()
6969

70-
location.Host = originalUrl.Host
71-
location.Scheme = originalUrl.Scheme
72-
location.Path = strings.Replace(location.Path, u.Path, "", 1)
70+
// Only attempt to rewrite the location if the host matches the CodeArtifact host
71+
// Otherwise leave the original location intact (e.g a redirect to a S3 presigned URL)
72+
if location.Host == u.Host {
73+
location.Host = originalUrl.Host
74+
location.Scheme = originalUrl.Scheme
75+
location.Path = strings.Replace(location.Path, u.Path, "", 1)
7376

74-
r.Header.Set("Location", location.String())
77+
r.Header.Set("Location", location.String())
78+
}
7579
}
7680

7781
// Do some quick fixes to the HTTP response for NPM install requests

0 commit comments

Comments
 (0)