You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/05/30 18:59:11 UTC

[GitHub] dubee closed pull request #300: Bug fix: Use configured prototcol for API requests

dubee closed pull request #300: Bug fix: Use configured prototcol for API requests
URL: https://github.com/apache/incubator-openwhisk-cli/pull/300
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/commands/api.go b/commands/api.go
index 18fb6a98..c7b41576 100644
--- a/commands/api.go
+++ b/commands/api.go
@@ -913,7 +913,11 @@ func parseApi(cmd *cobra.Command, args []string) (*whisk.Api, *QualifiedName, er
 	} else {
 		urlActionPackage = "default"
 	}
-	api.Action.BackendUrl = "https://" + Client.Config.Host + "/api/v1/web/" + qName.GetNamespace() + "/" + urlActionPackage + "/" + qName.GetEntity() + ".http"
+	backendUrl := Client.Config.Host + "/api/v1/web/" + qName.GetNamespace() + "/" + urlActionPackage + "/" + qName.GetEntity() + ".http"
+	if !strings.HasPrefix(backendUrl, "http") {
+		backendUrl = "https://" + backendUrl
+	}
+	api.Action.BackendUrl = backendUrl
 	api.Action.BackendMethod = api.GatewayMethod
 	api.Action.Name = qName.GetEntityName()
 	api.Action.Namespace = qName.GetNamespace()
diff --git a/tests/src/test/scala/whisk/core/cli/test/ApiGwCliBasicTests.scala b/tests/src/test/scala/whisk/core/cli/test/ApiGwCliBasicTests.scala
index 2c7e64e9..abc682d0 100644
--- a/tests/src/test/scala/whisk/core/cli/test/ApiGwCliBasicTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/ApiGwCliBasicTests.scala
@@ -109,8 +109,9 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
     rr.stdout should include(testbasepath + testrelpath)
   }
 
-  def verifyApiGet(rr: RunResult): Unit = {
+  def verifyApiGet(rr: RunResult, apihost:String): Unit = {
     rr.stdout should include regex (s""""operationId":\\s+"getPathWithSub_pathsInIt"""")
+    rr.stdout should include regex (s""""target-url":\\s+"https://$apihost""")
   }
 
   def verifyApiFullList(rr: RunResult,
@@ -447,7 +448,7 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
       rr = apiList(basepathOrApiName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
       verifyApiFullList(rr, clinamespace, actionName, testurlop, testbasepath, testrelpath, testapiname)
       rr = apiGet(basepathOrApiName = Some(testbasepath))
-      verifyApiGet(rr)
+      verifyApiGet(rr, wskprops.apihost)
       val deleteresult = apiDelete(basepathOrApiName = testbasepath)
       verifyApiDeleted(deleteresult)
     } finally {
@@ -456,6 +457,43 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
     }
   }
 
+  it should "verify successful creation and deletion of a new API when apihost specifies the protocol" in {
+    val testName = "CLI_APIGWTEST2"
+    val testbasepath = "/" + testName + "_bp"
+    val testrelpath = "/path/with/sub_paths/in/it"
+    val testnewrelpath = "/path_new"
+    val testurlop = "get"
+    val testapiname = testName + " API Name"
+    val actionName = testName + "_action"
+    try {
+      println("cli namespace: " + clinamespace)
+
+      // Create the action for the API.  It must be a "web-action" action.
+      val file = TestUtils.getTestActionFilename(s"echo.js")
+      wsk.action.create(name = actionName, artifact = Some(file), expectedExitCode = createCode, web = Some("true"))
+
+      val explicitProtocol = if (wskprops.apihost.startsWith("http")) "" else "https://"
+      val wskpropsOverride = WskProps(apihost = explicitProtocol + wskprops.apihost)
+      var rr = apiCreate(
+        basepath = Some(testbasepath),
+        relpath = Some(testrelpath),
+        operation = Some(testurlop),
+        action = Some(actionName),
+        apiname = Some(testapiname))(wskpropsOverride)
+      verifyApiCreated(rr)
+      rr = apiList(basepathOrApiName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
+      verifyApiFullList(rr, clinamespace, actionName, testurlop, testbasepath, testrelpath, testapiname)
+      rr = apiGet(basepathOrApiName = Some(testbasepath))
+      verifyApiGet(rr, wskprops.apihost)
+      val deleteresult = apiDelete(basepathOrApiName = testbasepath)
+      verifyApiDeleted(deleteresult)
+    } finally {
+      wsk.action.delete(name = actionName, expectedExitCode = DONTCARE_EXIT)
+      apiDelete(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
+    }
+  }
+
+
   it should "verify get API name " in {
     val testName = "CLI_APIGWTEST3"
     val testbasepath = "/" + testName + "_bp"


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services