@@ -54,38 +54,45 @@ func parseDevfile(d DevfileObj, flattenedDevfile bool) (DevfileObj, error) {
54
54
return d , nil
55
55
}
56
56
57
+ // ParserArgs is the struct to pass into parser functions which contains required info for parsing devfile.
58
+ // It accepts devfile path, devfile URL or devfile content in []byte format.
59
+ // Path is a relative or absolute devfile path.
60
+ // URL is the URL address of the specific devfile.
61
+ // Data is the devfile content in []byte format.
62
+ // FlattenedDevfile defines if the returned devfileObj is flattened content (true) or raw content (false), the value is default to be true.
63
+ // RegistryURLs is a list of registry hosts which parse should pull parent devfile from.
57
64
type ParserArgs struct {
58
- path string
59
- url string
60
- data []byte
61
- flattenedDevfile * bool // default to true
62
- registryURLs []string
65
+ Path string
66
+ URL string
67
+ Data []byte
68
+ FlattenedDevfile * bool // default to true
69
+ RegistryURLs []string
63
70
}
64
71
65
72
// ParseDevfile func populates the devfile data, parses and validates the devfile integrity.
66
73
// Creates devfile context and runtime objects
67
74
func ParseDevfile (args ParserArgs ) (d DevfileObj , err error ) {
68
- if args .data != nil {
75
+ if args .Data != nil {
69
76
d .Ctx = devfileCtx.DevfileCtx {}
70
- err = d .Ctx .SetDevfileContentFromBytes (args .data )
77
+ err = d .Ctx .SetDevfileContentFromBytes (args .Data )
71
78
if err != nil {
72
79
return d , errors .Wrap (err , "failed to set devfile content from bytes" )
73
80
}
74
- } else if args .path != "" {
75
- d .Ctx = devfileCtx .NewDevfileCtx (args .path )
76
- } else if args .url != "" {
77
- d .Ctx = devfileCtx .NewURLDevfileCtx (args .url )
81
+ } else if args .Path != "" {
82
+ d .Ctx = devfileCtx .NewDevfileCtx (args .Path )
83
+ } else if args .URL != "" {
84
+ d .Ctx = devfileCtx .NewURLDevfileCtx (args .URL )
78
85
} else {
79
86
return d , errors .Wrap (err , "the devfile source is not provided" )
80
87
}
81
88
82
- if args .registryURLs != nil {
83
- d .Ctx .SetRegistryURLs (args .registryURLs )
89
+ if args .RegistryURLs != nil {
90
+ d .Ctx .SetRegistryURLs (args .RegistryURLs )
84
91
}
85
92
86
93
flattenedDevfile := true
87
- if args .flattenedDevfile != nil {
88
- flattenedDevfile = * args .flattenedDevfile
94
+ if args .FlattenedDevfile != nil {
95
+ flattenedDevfile = * args .FlattenedDevfile
89
96
}
90
97
91
98
return populateAndParseDevfile (d , flattenedDevfile )
@@ -167,7 +174,7 @@ func parseParentAndPlugin(d DevfileObj) (err error) {
167
174
return err
168
175
}
169
176
} else {
170
- return fmt .Errorf ("parent URI or registry id undefined, currently only URI and Id are suppported" )
177
+ return fmt .Errorf ("parent URI or parent Id undefined, currently only URI and Id are suppported" )
171
178
}
172
179
173
180
parentWorkspaceContent := parentDevfileObj .Data .GetDevfileWorkspace ()
@@ -253,33 +260,33 @@ func parseFromURI(uri string, curDevfileCtx devfileCtx.DevfileCtx) (DevfileObj,
253
260
return populateAndParseDevfile (d , true )
254
261
}
255
262
256
- func parseFromRegistry (registryId , registryURL string , curDevfileCtx devfileCtx.DevfileCtx ) (DevfileObj , error ) {
263
+ func parseFromRegistry (parentId , registryURL string , curDevfileCtx devfileCtx.DevfileCtx ) (DevfileObj , error ) {
257
264
if registryURL != "" {
258
- devfileContent , err := getDevfileFromRegistry (registryId , registryURL )
265
+ devfileContent , err := getDevfileFromRegistry (parentId , registryURL )
259
266
if err != nil {
260
267
return DevfileObj {}, err
261
268
}
262
- return ParseDevfile (ParserArgs {data : devfileContent , registryURLs : curDevfileCtx .GetRegistryURLs ()})
269
+ return ParseDevfile (ParserArgs {Data : devfileContent , RegistryURLs : curDevfileCtx .GetRegistryURLs ()})
263
270
} else if curDevfileCtx .GetRegistryURLs () != nil {
264
271
for _ , registry := range curDevfileCtx .GetRegistryURLs () {
265
- devfileContent , err := getDevfileFromRegistry (registryId , registry )
272
+ devfileContent , err := getDevfileFromRegistry (parentId , registry )
266
273
if devfileContent != nil && err == nil {
267
- return ParseDevfile (ParserArgs {data : devfileContent , registryURLs : curDevfileCtx .GetRegistryURLs ()})
274
+ return ParseDevfile (ParserArgs {Data : devfileContent , RegistryURLs : curDevfileCtx .GetRegistryURLs ()})
268
275
}
269
276
}
270
277
} else {
271
278
return DevfileObj {}, fmt .Errorf ("failed to parse from registry, registry URL is not provided" )
272
279
}
273
280
274
- return DevfileObj {}, fmt .Errorf ("failed to get registry id : %s from registry URLs provided" , registryId )
281
+ return DevfileObj {}, fmt .Errorf ("failed to get parent Id : %s from registry URLs provided" , parentId )
275
282
}
276
283
277
- func getDevfileFromRegistry (registryId , registryURL string ) ([]byte , error ) {
284
+ func getDevfileFromRegistry (parentId , registryURL string ) ([]byte , error ) {
278
285
if ! strings .HasPrefix (registryURL , "http://" ) && ! strings .HasPrefix (registryURL , "https://" ) {
279
286
registryURL = fmt .Sprintf ("http://%s" , registryURL )
280
287
}
281
288
param := util.HTTPRequestParams {
282
- URL : fmt .Sprintf ("%s/devfiles/%s" , registryURL , registryId ),
289
+ URL : fmt .Sprintf ("%s/devfiles/%s" , registryURL , parentId ),
283
290
}
284
291
return util .HTTPGetRequest (param , 0 )
285
292
}
0 commit comments