Skip to content

Commit

Permalink
Scheme isn't included in the presigner (#1233)
Browse files Browse the repository at this point in the history
  • Loading branch information
xibz authored Apr 26, 2017
1 parent d3942f7 commit 6f5e72f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion service/rds/rdsutils/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rdsutils

import (
"net/http"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws/credentials"
Expand All @@ -15,6 +16,8 @@ import (
// region is the region of database that the auth token would be generated for. The dbUser is the user
// that the request would be authenticated with. The creds are the credentials the auth token is signed
// with.
//
// The url that is returned will not contain the scheme.
func BuildAuthToken(endpoint, region, dbUser string, creds *credentials.Credentials) (string, error) {
req, err := http.NewRequest("GET", endpoint, nil)
if err != nil {
Expand All @@ -33,5 +36,12 @@ func BuildAuthToken(endpoint, region, dbUser string, creds *credentials.Credenti
return "", err
}

return req.URL.String(), nil
url := req.URL.String()
if strings.HasPrefix(url, "http://") {
url = url[len("http://"):]
} else if strings.HasPrefix(url, "https://") {
url = url[len("https://"):]
}

return url, nil
}
2 changes: 1 addition & 1 deletion service/rds/rdsutils/connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ func TestBuildAuthToken(t *testing.T) {

url, err := rdsutils.BuildAuthToken(endpoint, region, user, creds)
assert.NoError(t, err)
assert.Regexp(t, `^https://prod-instance\.us-east-1\.rds\.amazonaws\.com:3306\?Action=connect.*?DBUser=mysqlUser.*`, url)
assert.Regexp(t, `^prod-instance\.us-east-1\.rds\.amazonaws\.com:3306\?Action=connect.*?DBUser=mysqlUser.*`, url)
}

0 comments on commit 6f5e72f

Please sign in to comment.