Aurora endpoint may now be explicitly provided with or without protocol and with or without port.

This commit is contained in:
Renan DelValle 2018-12-17 18:00:20 -08:00
parent ef421f60c3
commit 56b325ed80
No known key found for this signature in database
GPG key ID: C240AD6D6F443EC9
3 changed files with 89 additions and 2 deletions

38
util.go
View file

@ -1,7 +1,11 @@
package realis
import (
"net/url"
"strings"
"github.com/paypal/gorealis/gen-go/apache/aurora"
"github.com/pkg/errors"
)
var ActiveStates = make(map[aurora.ScheduleStatus]bool)
@ -35,3 +39,37 @@ func init() {
AwaitingPulseJobUpdateStates[status] = true
}
}
func validateAndPopulateAuroraURL(urlStr string) (string, error) {
// If no protocol defined, assume http
if !(strings.HasPrefix(urlStr, "http") || strings.HasPrefix(urlStr, "https")) {
urlStr = "http://" + urlStr
}
u, err := url.Parse(urlStr)
if err != nil {
return "", errors.Wrap(err, "error parsing url")
}
// If no path provided assume /api
if u.Path == "" {
u.Path = "/api"
}
// If no port provided, assume default 8081
if u.Port() == "" {
u.Host = u.Host + ":8081"
}
if !(u.Scheme == "http" || u.Scheme == "https") {
return "", errors.Errorf("only protocols http and https are supported %v\n", u.Scheme)
}
if u.Path != "/api" {
return "", errors.Errorf("expected /api path %v\n", u.Path)
}
return u.String(), nil
}