You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by dr...@apache.org on 2018/01/11 14:02:24 UTC

[1/3] brooklyn-client git commit: br catalog add: Fix path parsing errors on Windows

Repository: brooklyn-client
Updated Branches:
  refs/heads/master 1849ff984 -> 48e9f40d1


br catalog add: Fix path parsing errors on Windows

br has trouble working with files on Windows due to its attempt to
coerce filenames to file: URLs, which are ill-defined and unreliable
when it comes to backslashes and drive letters. Code revised to handle
files as files instead of URLs to avoid a number of issues.

Project: http://git-wip-us.apache.org/repos/asf/brooklyn-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-client/commit/3c599dee
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-client/tree/3c599dee
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-client/diff/3c599dee

Branch: refs/heads/master
Commit: 3c599dee97344cebf47ad7db3772afe98ffe16d6
Parents: 1849ff9
Author: Richard Downer <ri...@apache.org>
Authored: Thu Jan 11 11:36:24 2018 +0000
Committer: Richard Downer <ri...@apache.org>
Committed: Thu Jan 11 11:37:34 2018 +0000

----------------------------------------------------------------------
 cli/api/catalog/catalog.go | 52 +++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/3c599dee/cli/api/catalog/catalog.go
----------------------------------------------------------------------
diff --git a/cli/api/catalog/catalog.go b/cli/api/catalog/catalog.go
index b0e40bb..5a9574f 100644
--- a/cli/api/catalog/catalog.go
+++ b/cli/api/catalog/catalog.go
@@ -219,6 +219,7 @@ func AddCatalog(network *net.Network, resource string) (*models.CatalogBundleAdd
 	urlString := "/v1/catalog"
 	urlStringWithDetail := urlString + "?detail=true"
 	var result models.CatalogBundleAddResult
+	var body []byte
 
 	//Force auto-detect by default
 	contentType := "application/octet-stream"
@@ -227,18 +228,15 @@ func AddCatalog(network *net.Network, resource string) (*models.CatalogBundleAdd
 		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)
-	}
-
-	if "" == u.Scheme || "file" == u.Scheme {
-                if "file" == u.Scheme {
+	//If the resource exists as a file, or if the resource-parsed-as-URL as file scheme
+	_, err = os.Stat(resource)
+	if err == nil || "file" == u.Scheme {
+		if "file" == u.Scheme {
 			if u.Path == "" {
 				return nil, errors.New("No resource in 'file:' URL: " + resource)
 			}
-                        resource = u.Path
-                }
+			resource = u.Path
+		}
 
 		file, err := os.Open(filepath.Clean(resource))
 		if err != nil {
@@ -250,22 +248,16 @@ func AddCatalog(network *net.Network, resource string) (*models.CatalogBundleAdd
 			return nil, err
 		}
 
+		var dat []byte
+
 		if fileStat.IsDir() {
 			//A dir is a special case, we need to zip it up, and call a different network method
 			buf, err := ZipResource(resource)
 			if err != nil {
 				return nil, err
 			}
-			body, err := network.SendPostRequestWithContentType(urlStringWithDetail, buf.Bytes(), "application/x-zip")
-			if err != nil {
-				return nil, 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
+			dat = buf.Bytes()
+			contentType = "application/x-zip"
 		} else {
 			extension := filepath.Ext(resource)
 			lowercaseExtension := strings.ToLower(extension)
@@ -278,14 +270,28 @@ func AddCatalog(network *net.Network, resource string) (*models.CatalogBundleAdd
 			} else if lowercaseExtension == ".yaml" || lowercaseExtension == ".bom" {
 				contentType = "application/x-yaml"
 			}
+
+			dat, err = ioutil.ReadFile(resource)
+			if err != nil {
+				return nil, err
+			}
 		}
 
-	}
+		body, err = network.SendPostRequestWithContentType(urlStringWithDetail, dat, contentType)
+		if err != nil {
+			return nil, err
+		}
 
-	body, err := network.SendPostResourceRequest(urlString, resource, contentType)
-	if err != nil {
-		return nil, err
+	} else if "http" == u.Scheme || "https" == u.Scheme {
+		body, err = network.SendPostResourceRequest(urlString, resource, contentType)
+		if err != nil {
+			return nil, err
+		}
+
+	} else {
+		return nil, errors.New("File does not exist or unrecognised URL protocol scheme: " + resource)
 	}
+
 	err = json.Unmarshal(body, &result)
 	if result.Code == "" {
 		// detail API not supported, just store the types


[3/3] brooklyn-client git commit: This closes #66

Posted by dr...@apache.org.
This closes #66


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-client/commit/48e9f40d
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-client/tree/48e9f40d
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-client/diff/48e9f40d

Branch: refs/heads/master
Commit: 48e9f40d13a584fe590ab6b1b419cb5416469b5f
Parents: 1849ff9 bc189ac
Author: Duncan Godwin <dr...@googlemail.com>
Authored: Thu Jan 11 14:02:15 2018 +0000
Committer: Duncan Godwin <dr...@googlemail.com>
Committed: Thu Jan 11 14:02:15 2018 +0000

----------------------------------------------------------------------
 cli/api/catalog/catalog.go | 53 +++++++++++++++++++++++------------------
 1 file changed, 30 insertions(+), 23 deletions(-)
----------------------------------------------------------------------



[2/3] brooklyn-client git commit: `br` on Windows generates incorrect ZIP archives

Posted by dr...@apache.org.
`br` on Windows generates incorrect ZIP archives

The ZIP archive should use / internally but when on Windows `br` used
\ instead. This affects the `br catalog add` command when given a
directory.

Project: http://git-wip-us.apache.org/repos/asf/brooklyn-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-client/commit/bc189ac0
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-client/tree/bc189ac0
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-client/diff/bc189ac0

Branch: refs/heads/master
Commit: bc189ac0e69b541c1ba842adf481ca2e84b59f2a
Parents: 3c599de
Author: Richard Downer <ri...@apache.org>
Authored: Thu Jan 11 11:11:08 2018 +0000
Committer: Richard Downer <ri...@apache.org>
Committed: Thu Jan 11 11:37:43 2018 +0000

----------------------------------------------------------------------
 cli/api/catalog/catalog.go | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/bc189ac0/cli/api/catalog/catalog.go
----------------------------------------------------------------------
diff --git a/cli/api/catalog/catalog.go b/cli/api/catalog/catalog.go
index 5a9574f..4c985ec 100644
--- a/cli/api/catalog/catalog.go
+++ b/cli/api/catalog/catalog.go
@@ -193,6 +193,7 @@ func ZipResource(resource string) (*bytes.Buffer, error) {
 		if err != nil {
 			return err
 		}
+		relativePath = strings.Replace(relativePath, "\\", "/", -1)
 		f, err := writer.Create(relativePath)
 		if err != nil {
 			return err