-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- The UAA target defaults to /uaa on Operations Manager, but can now be overridden in cases where UAA is not located at the default location. - Consistently parse target and allow http(s):// protocol prefix.
- Loading branch information
Showing
7 changed files
with
176 additions
and
66 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
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
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,55 @@ | ||
package network | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net/url" | ||
"strings" | ||
) | ||
|
||
// parseURL takes a candidate target URL and attempts to parse it with sane defaults | ||
func parseURL(u string) (*url.URL, error) { | ||
// default the target protocol to https if none specified | ||
if !strings.Contains(u, "://") { | ||
u = "https://" + u | ||
} | ||
|
||
targetURL, err := url.Parse(u) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// at a minimum ensure we have a host with http(s) protocol | ||
if targetURL.Scheme != "https" && targetURL.Scheme != "http" { | ||
return nil, fmt.Errorf("error parsing URL, expected http(s) protocol but got %s", targetURL.Scheme) | ||
} | ||
if targetURL.Host == "" { | ||
return nil, errors.New("target flag is required, run `om help` for more info") | ||
} | ||
|
||
return targetURL, nil | ||
} | ||
|
||
// parseOpsmanAndUAAURLs takes a candidate OpsMan and UAA target URLs and attempts to parse both of them, defaulting | ||
// the UAA target to the /uaa path under the OpsMan target if none specified. | ||
func parseOpsmanAndUAAURLs(opsmanTarget, uaaTarget string) (*url.URL, *url.URL, error) { | ||
opsmanURL, err := parseURL(opsmanTarget) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("could not parse Opsman target URL: %w", err) | ||
} | ||
|
||
var uaaURL *url.URL | ||
if uaaTarget != "" { | ||
uaaURL, err = parseURL(uaaTarget) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("could not parse UAA target URL: %w", err) | ||
} | ||
} else { | ||
// default to opsman URL with /uaa path (shallow copy) | ||
t := *opsmanURL | ||
t.Path = "/uaa" | ||
uaaURL = &t | ||
} | ||
|
||
return opsmanURL, uaaURL, nil | ||
} |
Oops, something went wrong.