From commits-return-4841-archive-asf-public=cust-asf.ponee.io@openwhisk.apache.org Wed May 30 20:59:17 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id E089818063B for ; Wed, 30 May 2018 20:59:16 +0200 (CEST) Received: (qmail 81358 invoked by uid 500); 30 May 2018 18:59:16 -0000 Mailing-List: contact commits-help@openwhisk.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openwhisk.apache.org Delivered-To: mailing list commits@openwhisk.apache.org Received: (qmail 81348 invoked by uid 99); 30 May 2018 18:59:16 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 May 2018 18:59:16 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 6C865829E7; Wed, 30 May 2018 18:59:15 +0000 (UTC) Date: Wed, 30 May 2018 18:59:15 +0000 To: "commits@openwhisk.apache.org" Subject: [incubator-openwhisk-cli] branch master updated: Bug fix: Use configured prototcol for API requests (#300) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <152770675535.1479.5779878376872984798@gitbox.apache.org> From: dubeejw@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: incubator-openwhisk-cli X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: e8cc839421e501c84b041248ebdf092499e1df12 X-Git-Newrev: 0c34a07f28d98f386a34f76ba56c07521192c38f X-Git-Rev: 0c34a07f28d98f386a34f76ba56c07521192c38f X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. dubeejw pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-cli.git The following commit(s) were added to refs/heads/master by this push: new 0c34a07 Bug fix: Use configured prototcol for API requests (#300) 0c34a07 is described below commit 0c34a07f28d98f386a34f76ba56c07521192c38f Author: David Grove AuthorDate: Wed May 30 14:59:08 2018 -0400 Bug fix: Use configured prototcol for API requests (#300) Add check to see if Client.Config.Host already specifies the protocol to use before prepending https:// in URL construction. Fixes a bug where if .wskprops specifies a APIHOST with a protocol, `wsk api create` generates an invalid backend URL (https://https://APIHOST/...). Also add unit test to check for this error condition. Fixes #125. --- commands/api.go | 6 +++- .../whisk/core/cli/test/ApiGwCliBasicTests.scala | 42 ++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/commands/api.go b/commands/api.go index 18fb6a9..c7b4157 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 2c7e64e..abc682d 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" -- To stop receiving notification emails like this one, please contact dubeejw@apache.org.