diff --git a/cli/api/catalog/catalog.go b/cli/api/catalog/catalog.go index 108cf4b..d8132ca 100644 --- a/cli/api/catalog/catalog.go +++ b/cli/api/catalog/catalog.go @@ -215,9 +215,10 @@ func ZipResource(resource string) (*bytes.Buffer, error) { return buf, err; } -func AddCatalog(network *net.Network, resource string) (map[string]models.CatalogEntitySummary, error) { +func AddCatalog(network *net.Network, resource string) (*models.CatalogBundleAddResult, error) { urlString := "/v1/catalog" - var entities map[string]models.CatalogEntitySummary + urlStringWithDetail := urlString + "?detail=true" + var result models.CatalogBundleAddResult //Force auto-detect by default contentType := "application/octet-stream" @@ -255,19 +256,25 @@ func AddCatalog(network *net.Network, resource string) (map[string]models.Catalo if err != nil { return nil, err } - body, err := network.SendPostRequestWithContentType(urlString, buf.Bytes(), "application/x-zip") + body, err := network.SendPostRequestWithContentType(urlStringWithDetail, buf.Bytes(), "application/x-zip") if err != nil { return nil, err } - err = json.Unmarshal(body, &entities) - return entities, err + err = json.Unmarshal(body, &result) + if result.Code == "" { + // older version of server, doesn't support detail + err = json.Unmarshal(body, &result.Types) + } + return &result, err } else { extension := filepath.Ext(resource) lowercaseExtension := strings.ToLower(extension) if lowercaseExtension == ".zip" { contentType = "application/x-zip" + urlString = urlStringWithDetail } else if lowercaseExtension == ".jar" { contentType = "application/x-jar" + urlString = urlStringWithDetail } } @@ -277,9 +284,12 @@ func AddCatalog(network *net.Network, resource string) (map[string]models.Catalo if err != nil { return nil, err } - err = json.Unmarshal(body, &entities) - - return entities, err + err = json.Unmarshal(body, &result) + if result.Code == "" { + // detail API not supported, just store the types + err = json.Unmarshal(body, &result.Types) + } + return &result, err } func GetLocation(network *net.Network, locationId string) (models.CatalogItemSummary, error) { diff --git a/cli/commands/catalog-add.go b/cli/commands/catalog-add.go index 0f67152..2e633ff 100644 --- a/cli/commands/catalog-add.go +++ b/cli/commands/catalog-add.go @@ -58,7 +58,14 @@ func (cmd *CatalogAdd) Run(scope scope.Scope, c *cli.Context) { if nil != err { error_handler.ErrorExit(err) } - for id, _ := range create { - fmt.Println(id) + if "" != create.Message { + fmt.Println(create.Message) + for id, _ := range create.Types { + fmt.Printf("* %s\n", id) + } + } else { + for id, _ := range create.Types { + fmt.Println(id) + } } } diff --git a/cli/models/catalog.go b/cli/models/catalog.go index edc6b0e..be6c443 100644 --- a/cli/models/catalog.go +++ b/cli/models/catalog.go @@ -54,6 +54,13 @@ type CatalogEntitySummary struct { Sensors []SensorSummary `json:"sensors"` } +type CatalogBundleAddResult struct { + Message string `json:"message"` + Bundle string `json:"bundle"` + Code string `json:"code"` + Types map[string]CatalogItemSummary `json:"types"` +} + func createTableWithIdentityDetails(item IdentityDetails) (terminal.Table) { table := terminal.NewTable([]string{"Id:", item.Id}) table.Add("Version:", item.Version) @@ -184,4 +191,4 @@ func displayAsJson(v interface{}, jsonPath string) (err error) { return eval.Error } return nil -} \ No newline at end of file +}