Skip to content
Permalink
Browse files
This closes #53
  • Loading branch information
ahgittin committed Jun 6, 2017
2 parents 41edfec + a245052 commit 005bd109b0f1ce352283d22002512b05c06ba67b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
@@ -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) {
@@ -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)
}
}
}
@@ -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
}
}

0 comments on commit 005bd10

Please sign in to comment.