-
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.
## Description When using Zarf as a library for DoHostnamesMatch you get all of the message dependencies. This PR is a feature to remove those dependencies and still get the same functionality with a small footprint. ## Related Issue Fixes #1949 <!-- or --> Relates to #1949 ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Other (security config, docs update, etc) ## Checklist before merging - [x] Test, docs, adr added or updated as needed - [x] [Contributor Guide Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow) followed --------- Signed-off-by: Case Wylie <[email protected]> Co-authored-by: Lucas Rodriguez <[email protected]> Co-authored-by: Wayne Starr <[email protected]>
- Loading branch information
1 parent
304f70a
commit d0da732
Showing
18 changed files
with
180 additions
and
136 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.