Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 18 additions & 8 deletions cli/api/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}

Expand All @@ -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) {
Expand Down
11 changes: 9 additions & 2 deletions cli/commands/catalog-add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
9 changes: 8 additions & 1 deletion cli/models/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -184,4 +191,4 @@ func displayAsJson(v interface{}, jsonPath string) (err error) {
return eval.Error
}
return nil
}
}