Github user geomacy commented on a diff in the pull request:
https://github.com/apache/brooklyn-client/pull/44#discussion_r110366235
--- Diff: cli/api/catalog/catalog.go ---
@@ -170,15 +178,102 @@ func Locations(network *net.Network)
([]models.CatalogItemSummary, error) {
return catalogLocations, err
}
+
+func ZipResource(resource string) (*bytes.Buffer, error) {
+ buf := new(bytes.Buffer)
+ writer := zip.NewWriter(buf)
+ defer writer.Close()
+
+ walkFn := func(path string, info os.FileInfo, err error) error {
+ if info.IsDir() {
+ return nil
+ }
+
+ relativePath, err := filepath.Rel(resource, path)
+ if err != nil {
+ return err
+ }
+ f, err := writer.Create(relativePath)
+ if err != nil {
+ return err
+ }
+
+ fileBytes, err := ioutil.ReadFile(path)
+ if err != nil {
+ return err
+ }
+
+ _, err = f.Write(fileBytes)
+ if err != nil {
+ return err
+ }
+ return nil
+ }
+
+ err := filepath.Walk(resource, walkFn)
+
+ return buf, err;
+}
+
func AddCatalog(network *net.Network, resource string)
(map[string]models.CatalogEntitySummary, error) {
- url := "/v1/catalog"
+ urlString := "/v1/catalog"
var entities map[string]models.CatalogEntitySummary
- body, err := network.SendPostResourceRequest(url, resource,
"application/json")
+
+ //Assume application/json. This is correct for http/file resources.
+ //Zips will need application/x-zip
+ contentType := "application/json"
+ u, err := url.Parse(resource)
+ if err != nil {
+ return nil, err
+ }
+
+ //Only deal with the below file types
+ if "" != u.Scheme && "file" != u.Scheme && "http" != u.Scheme &&
"https" != u.Scheme{
+ return nil, errors.New("Unrecognised protocol scheme: " +
u.Scheme)
--- End diff --
"Unsupported" maybe
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---