Skip to content

Commit a245052

Browse files
committed
show bundle info and message when doing catalog add
also supports backwards compatibility as only some API methods support the detail
1 parent 41edfec commit a245052

3 files changed

Lines changed: 35 additions & 11 deletions

File tree

cli/api/catalog/catalog.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,10 @@ func ZipResource(resource string) (*bytes.Buffer, error) {
215215
return buf, err;
216216
}
217217

218-
func AddCatalog(network *net.Network, resource string) (map[string]models.CatalogEntitySummary, error) {
218+
func AddCatalog(network *net.Network, resource string) (*models.CatalogBundleAddResult, error) {
219219
urlString := "/v1/catalog"
220-
var entities map[string]models.CatalogEntitySummary
220+
urlStringWithDetail := urlString + "?detail=true"
221+
var result models.CatalogBundleAddResult
221222

222223
//Force auto-detect by default
223224
contentType := "application/octet-stream"
@@ -255,19 +256,25 @@ func AddCatalog(network *net.Network, resource string) (map[string]models.Catalo
255256
if err != nil {
256257
return nil, err
257258
}
258-
body, err := network.SendPostRequestWithContentType(urlString, buf.Bytes(), "application/x-zip")
259+
body, err := network.SendPostRequestWithContentType(urlStringWithDetail, buf.Bytes(), "application/x-zip")
259260
if err != nil {
260261
return nil, err
261262
}
262-
err = json.Unmarshal(body, &entities)
263-
return entities, err
263+
err = json.Unmarshal(body, &result)
264+
if result.Code == "" {
265+
// older version of server, doesn't support detail
266+
err = json.Unmarshal(body, &result.Types)
267+
}
268+
return &result, err
264269
} else {
265270
extension := filepath.Ext(resource)
266271
lowercaseExtension := strings.ToLower(extension)
267272
if lowercaseExtension == ".zip" {
268273
contentType = "application/x-zip"
274+
urlString = urlStringWithDetail
269275
} else if lowercaseExtension == ".jar" {
270276
contentType = "application/x-jar"
277+
urlString = urlStringWithDetail
271278
}
272279
}
273280

@@ -277,9 +284,12 @@ func AddCatalog(network *net.Network, resource string) (map[string]models.Catalo
277284
if err != nil {
278285
return nil, err
279286
}
280-
err = json.Unmarshal(body, &entities)
281-
282-
return entities, err
287+
err = json.Unmarshal(body, &result)
288+
if result.Code == "" {
289+
// detail API not supported, just store the types
290+
err = json.Unmarshal(body, &result.Types)
291+
}
292+
return &result, err
283293
}
284294

285295
func GetLocation(network *net.Network, locationId string) (models.CatalogItemSummary, error) {

cli/commands/catalog-add.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@ func (cmd *CatalogAdd) Run(scope scope.Scope, c *cli.Context) {
5858
if nil != err {
5959
error_handler.ErrorExit(err)
6060
}
61-
for id, _ := range create {
62-
fmt.Println(id)
61+
if "" != create.Message {
62+
fmt.Println(create.Message)
63+
for id, _ := range create.Types {
64+
fmt.Printf("* %s\n", id)
65+
}
66+
} else {
67+
for id, _ := range create.Types {
68+
fmt.Println(id)
69+
}
6370
}
6471
}

cli/models/catalog.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ type CatalogEntitySummary struct {
5454
Sensors []SensorSummary `json:"sensors"`
5555
}
5656

57+
type CatalogBundleAddResult struct {
58+
Message string `json:"message"`
59+
Bundle string `json:"bundle"`
60+
Code string `json:"code"`
61+
Types map[string]CatalogItemSummary `json:"types"`
62+
}
63+
5764
func createTableWithIdentityDetails(item IdentityDetails) (terminal.Table) {
5865
table := terminal.NewTable([]string{"Id:", item.Id})
5966
table.Add("Version:", item.Version)
@@ -184,4 +191,4 @@ func displayAsJson(v interface{}, jsonPath string) (err error) {
184191
return eval.Error
185192
}
186193
return nil
187-
}
194+
}

0 commit comments

Comments
 (0)