-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Case Wylie <[email protected]>
- Loading branch information
Showing
19 changed files
with
176 additions
and
160 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
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
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,42 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors | ||
|
||
// Package helpers provides generic helper functions with no external imports | ||
package helpers | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
) | ||
|
||
// Nonstandard URL schemes or prefixes | ||
const ( | ||
OCIURLScheme = "oci" | ||
OCIURLPrefix = "oci://" | ||
) | ||
|
||
// IsURL is a helper function to check if a URL is valid. | ||
func IsURL(source string) bool { | ||
parsedURL, err := url.Parse(source) | ||
return err == nil && parsedURL.Scheme != "" && parsedURL.Host != "" | ||
} | ||
|
||
// IsOCIURL returns true if the given URL is an OCI URL. | ||
func IsOCIURL(source string) bool { | ||
parsedURL, err := url.Parse(source) | ||
return err == nil && parsedURL.Scheme == "oci" | ||
} | ||
|
||
// DoHostnamesMatch returns a boolean indicating if the hostname of two different URLs are the same. | ||
func DoHostnamesMatch(url1 string, url2 string) (bool, error) { | ||
parsedURL1, err := url.Parse(url1) | ||
if err != nil { | ||
return false, fmt.Errorf("unable to parse the url (%s): %w", url1, err) | ||
} | ||
parsedURL2, err := url.Parse(url2) | ||
if err != nil { | ||
return false, fmt.Errorf("unable to parse the url (%s): %w", url2, err) | ||
} | ||
|
||
return parsedURL1.Hostname() == parsedURL2.Hostname(), nil | ||
} |
Oops, something went wrong.