Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ability to uds create to local output path #547

Merged
merged 4 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/pkg/bundle/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/defenseunicorns/uds-cli/src/config"
"github.com/defenseunicorns/uds-cli/src/pkg/bundler/fetcher"
"github.com/defenseunicorns/uds-cli/src/pkg/utils"
"github.com/defenseunicorns/uds-cli/src/types"
"github.com/defenseunicorns/zarf/src/pkg/cluster"
"github.com/defenseunicorns/zarf/src/pkg/message"
Expand Down Expand Up @@ -76,14 +77,6 @@ func (b *Bundle) ClearPaths() {
_ = os.RemoveAll(b.tmp)
}

// Checks if string is an oci url
func (b *Bundle) isURL(s string) bool {
if strings.Contains(s, "://") || strings.Contains(s, ".") && len(s) > 1 {
return true
}
return false
}

// ValidateBundleResources validates the bundle's metadata and package references
func (b *Bundle) ValidateBundleResources(bundle *types.UDSBundle, spinner *message.Spinner) error {
// TODO: need to validate arch of local OS
Expand Down Expand Up @@ -162,7 +155,7 @@ func (b *Bundle) ValidateBundleResources(bundle *types.UDSBundle, spinner *messa
}
} else {
// atm we don't support outputting a bundle with local pkgs outputting to OCI
if b.isURL(b.cfg.CreateOpts.Output) {
if utils.IsRegistryURL(b.cfg.CreateOpts.Output) {
return fmt.Errorf("detected local Zarf package: %s, outputting to an OCI registry is not supported when using local Zarf packages", pkg.Name)
}
var fullPkgName string
Expand Down
13 changes: 2 additions & 11 deletions src/pkg/bundler/bundler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
package bundler

import (
"strings"

"github.com/defenseunicorns/uds-cli/src/pkg/utils"
"github.com/defenseunicorns/uds-cli/src/types"
)

Expand Down Expand Up @@ -41,17 +40,9 @@ func NewBundler(opts *Options) *Bundler {
return &b
}

// Checks if string is an oci url
func isURL(s string) bool {
if strings.Contains(s, "://") || strings.Contains(s, ".") && len(s) > 1 {
return true
}
return false
}

// Create creates a bundle
func (b *Bundler) Create() error {
if isURL(b.output) {
if utils.IsRegistryURL(b.output) {
remoteBundle := NewRemoteBundle(&RemoteBundleOpts{Bundle: b.bundle, Output: b.output})
err := remoteBundle.create(nil)
if err != nil {
Expand Down
46 changes: 46 additions & 0 deletions src/pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"

"github.com/defenseunicorns/uds-cli/src/config"
Expand Down Expand Up @@ -138,3 +139,48 @@
func IsRemotePkg(pkg types.Package) bool {
return pkg.Repository != ""
}

func hasScheme(s string) bool {
return strings.Contains(s, "://")
}

func hasDomain(s string) bool {
return strings.Contains(s, ".") && len(s) > 1
TristanHoladay marked this conversation as resolved.
Show resolved Hide resolved
}

func hasPort(s string) bool {
// look for colon and port (e.g localhost:31999)
colonIndex := strings.Index(s, ":")
firstSlashIndex := strings.Index(s, "/")
endIndex := firstSlashIndex
if firstSlashIndex == -1 {
endIndex = len(s) - 1
}
if colonIndex != -1 {
port := s[colonIndex+1 : endIndex]

// port valid number ?
_, err := strconv.Atoi(port)
if err == nil {
return true
}
}
return false
}

// Checks if string is an oci url

Check warning on line 171 in src/pkg/utils/utils.go

View workflow job for this annotation

GitHub Actions / validate

comment on exported function IsRegistryURL should be of the form "IsRegistryURL ..."
TristanHoladay marked this conversation as resolved.
Show resolved Hide resolved
func IsRegistryURL(s string) bool {
if hasScheme(s) {
return true
}

if hasDomain(s) {
return true
}

if hasPort(s) {
return true
}

return false
}
Loading