@@ -19,15 +19,20 @@ package pull
19
19
import (
20
20
"errors"
21
21
"fmt"
22
+ "net/url"
22
23
"os"
23
24
"path/filepath"
24
25
25
26
"github.com/Masterminds/semver/v3"
27
+ "github.com/google/go-containerregistry/pkg/name"
26
28
"github.com/spf13/cobra"
27
29
)
28
30
29
31
func parseAndValidateParameters (_ * cobra.Command , args []string ) error {
30
32
var err error
33
+ if err = validateSourceRegistry (); err != nil {
34
+ return err
35
+ }
31
36
if err = parseAndValidateVersionFlags (); err != nil {
32
37
return err
33
38
}
@@ -44,6 +49,31 @@ func parseAndValidateParameters(_ *cobra.Command, args []string) error {
44
49
return nil
45
50
}
46
51
52
+ func validateSourceRegistry () error {
53
+ if SourceRegistryRepo == enterpriseEditionRepo {
54
+ return nil // Default is fine
55
+ }
56
+
57
+ // We first validate that passed repository reference is correct and can be parsed
58
+ if _ , err := name .NewRepository (SourceRegistryRepo ); err != nil {
59
+ return fmt .Errorf ("Validate registry address: %w" , err )
60
+ }
61
+
62
+ // Then we parse it as URL to validate that it contains everything we need
63
+ registryUrl , err := url .ParseRequestURI ("docker://" + SourceRegistryRepo )
64
+ if err != nil {
65
+ return fmt .Errorf ("Validate source registry parameter: %w" , err )
66
+ }
67
+ if registryUrl .Host == "" {
68
+ return errors .New ("--source you provided contains no registry host. Please specify source registry host address correctly." )
69
+ }
70
+ if registryUrl .Path == "" {
71
+ return errors .New ("--source you provided contains no registry path. Please specify source registry repo path correctly." )
72
+ }
73
+
74
+ return nil
75
+ }
76
+
47
77
func validateImagesBundlePathArg (args []string ) error {
48
78
if len (args ) != 1 {
49
79
return errors .New ("This command requires exactly 1 argument" )
@@ -74,7 +104,7 @@ func validateImagesBundlePathArg(args []string) error {
74
104
return fmt .Errorf ("Read bundle directory: %w" , err )
75
105
}
76
106
77
- if len (dirEntries ) == 0 || (len (dirEntries ) == 1 && dirEntries [0 ].Name () == ".tmp" && dirEntries [0 ].IsDir ()) {
107
+ if len (dirEntries ) == 0 || (len (dirEntries ) == 1 && dirEntries [0 ].Name () == ".tmp" && dirEntries [0 ].IsDir ()) {
78
108
return nil
79
109
}
80
110
0 commit comments