You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ra...@apache.org on 2017/08/08 17:14:38 UTC
[incubator-openwhisk] branch master updated: Remove "experimental"
gateway api (#2547)
This is an automated email from the ASF dual-hosted git repository.
rabbah pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git
The following commit(s) were added to refs/heads/master by this push:
new 5e95f02 Remove "experimental" gateway api (#2547)
5e95f02 is described below
commit 5e95f0240eec7ea3aded961a6671f16d75c03a17
Author: David Cariello <dr...@us.ibm.com>
AuthorDate: Tue Aug 8 12:14:35 2017 -0500
Remove "experimental" gateway api (#2547)
---
ansible/roles/routemgmt/files/installRouteMgmt.sh | 30 +-
tests/dat/apigw/testswaggerdoc1 | 104 ++-
tests/dat/apigw/testswaggerdoc1V2 | 61 --
tests/dat/apigw/testswaggerdoc2 | 272 +++----
tests/dat/apigw/testswaggerdoc2V2 | 117 ----
.../apigw/healthtests/ApiGwEndToEndTests.scala | 73 +-
tests/src/test/scala/common/Wsk.scala | 8 -
.../actions/test/ApiGwRoutemgmtActionTests.scala | 283 +-------
.../scala/whisk/core/cli/test/ApiGwTests.scala | 475 ++-----------
.../whisk/core/cli/test/WskBasicUsageTests.scala | 95 +--
tools/cli/go-whisk-cli/commands/api.go | 778 ++-------------------
tools/cli/go-whisk-cli/commands/wsk.go | 1 -
.../go-whisk-cli/wski18n/resources/en_US.all.json | 12 -
tools/cli/go-whisk/whisk/api.go | 220 +-----
14 files changed, 269 insertions(+), 2260 deletions(-)
diff --git a/ansible/roles/routemgmt/files/installRouteMgmt.sh b/ansible/roles/routemgmt/files/installRouteMgmt.sh
index 73646ca..63da557 100755
--- a/ansible/roles/routemgmt/files/installRouteMgmt.sh
+++ b/ansible/roles/routemgmt/files/installRouteMgmt.sh
@@ -35,9 +35,9 @@ fi
export WSK_CONFIG_FILE= # override local property file to avoid namespace clashes
-echo Installing routemgmt package.
-$WSK_CLI -i --apihost "$APIHOST" package update --auth "$AUTH" --shared no "$NAMESPACE/routemgmt" \
--a description "This experimental package manages the gateway API configuration." \
+echo Installing apimgmt package
+$WSK_CLI -i --apihost "$APIHOST" package update --auth "$AUTH" --shared no "$NAMESPACE/apimgmt" \
+-a description "This package manages the gateway API configuration." \
-p gwUser "$GW_USER" \
-p gwPwd "$GW_PWD" \
-p gwUrl "$GW_HOST" \
@@ -48,30 +48,6 @@ zip -j "$OPENWHISK_HOME/core/routemgmt/getApi/getApi.zip" "$OPENWHISK_HOME/core/
zip -j "$OPENWHISK_HOME/core/routemgmt/createApi/createApi.zip" "$OPENWHISK_HOME/core/routemgmt/createApi/createApi.js" "$OPENWHISK_HOME/core/routemgmt/createApi/package.json" "$OPENWHISK_HOME/core/routemgmt/common/utils.js" "$OPENWHISK_HOME/core/routemgmt/common/apigw-utils.js"
zip -j "$OPENWHISK_HOME/core/routemgmt/deleteApi/deleteApi.zip" "$OPENWHISK_HOME/core/routemgmt/deleteApi/deleteApi.js" "$OPENWHISK_HOME/core/routemgmt/deleteApi/package.json" "$OPENWHISK_HOME/core/routemgmt/common/utils.js" "$OPENWHISK_HOME/core/routemgmt/common/apigw-utils.js"
-echo Installing routemgmt actions
-$WSK_CLI -i --apihost "$APIHOST" action update --auth "$AUTH" "$NAMESPACE/routemgmt/getApi" "$OPENWHISK_HOME/core/routemgmt/getApi/getApi.zip" \
--a description 'Retrieve the specified API configuration (in JSON format)' \
---kind nodejs:default \
--a web-export true -a final true -a require-whisk-auth true
-
-$WSK_CLI -i --apihost "$APIHOST" action update --auth "$AUTH" "$NAMESPACE/routemgmt/createApi" "$OPENWHISK_HOME/core/routemgmt/createApi/createApi.zip" \
--a description 'Create an API' \
---kind nodejs:default \
--a web-export true -a final true -a require-whisk-auth true
-
-$WSK_CLI -i --apihost "$APIHOST" action update --auth "$AUTH" "$NAMESPACE/routemgmt/deleteApi" "$OPENWHISK_HOME/core/routemgmt/deleteApi/deleteApi.zip" \
--a description 'Delete the API' \
---kind nodejs:default \
--a web-export true -a final true -a require-whisk-auth true
-
-echo Installing apimgmt package
-$WSK_CLI -i --apihost "$APIHOST" package update --auth "$AUTH" --shared no "$NAMESPACE/apimgmt" \
--a description "This package manages the gateway API configuration." \
--p gwUser "$GW_USER" \
--p gwPwd "$GW_PWD" \
--p gwUrl "$GW_HOST" \
--p gwUrlV2 "$GW_HOST_V2"
-
echo Installing apimgmt actions
$WSK_CLI -i --apihost "$APIHOST" action update --auth "$AUTH" "$NAMESPACE/apimgmt/getApi" "$OPENWHISK_HOME/core/routemgmt/getApi/getApi.zip" \
-a description 'Retrieve the specified API configuration (in JSON format)' \
diff --git a/tests/dat/apigw/testswaggerdoc1 b/tests/dat/apigw/testswaggerdoc1
index f627fb6..623ae43 100644
--- a/tests/dat/apigw/testswaggerdoc1
+++ b/tests/dat/apigw/testswaggerdoc1
@@ -8,76 +8,54 @@
"paths": {
"/path": {
"get": {
+ "operationId": "get_/path",
"responses": {
"default": {
"description": "Default response"
}
},
- "x-ibm-op-ext": {
- "actionName": "CLI_APIGWTEST7_action",
- "actionNamespace": "guest",
- "backendMethod": "POST",
- "backendUrl": "https://999.999.99.999/api/v1/namespaces/guest/actions/CLI_APIGWTEST7_action",
- "policies": [
- {
- "type": "reqMapping",
- "value": [
- {
- "action": "transform",
- "from": {
- "location": "query",
- "name": "*"
- },
- "to": {
- "location": "body",
- "name": "*"
- }
- },
- {
- "action": "insert",
- "from": {
- "value": "Basic I34EJL53W3HGP64AB4E4DJ37FFGA424238GF6J"
- },
- "to": {
- "location": "header",
- "name": "Authorization"
- }
- },
- {
- "action": "insert",
- "from": {
- "value": "application/json"
- },
- "to": {
- "location": "header",
- "name": "Content-Type"
- }
- },
- {
- "action": "insert",
- "from": {
- "value": "true"
- },
- "to": {
- "location": "query",
- "name": "blocking"
- }
- },
- {
- "action": "insert",
- "from": {
- "value": "true"
- },
- "to": {
- "location": "query",
- "name": "result"
- }
- }
- ]
- }
- ]
+ "x-openwhisk": {
+ "action": "CLI_APIGWTEST7_action",
+ "namespace": "whisk.system",
+ "package": "",
+ "url": "https://172.17.0.1/api/v1/web/whisk.system/default/CLI_APIGWTEST7_action.http"
}
}
}
+ },
+ "x-ibm-configuration": {
+ "assembly": {
+ "execute": [
+ {
+ "set-variable": {
+ "actions": [
+ {
+ "set": "message.headers.Authorization",
+ "value": "Basic Nzg5YzQ2YjEtNzFmNi00ZWQ1LThjNTQtODE2YWE0ZjhjNTAyOmFiY3pPM3haQ0xyTU42djJCS0sxZFhZRnBYbFBrY2NPRnFtMTJDZEFzTWdSVTRWck5aOWx5R1ZDR3VNREdJd1A="
+ }
+ ]
+ }
+ },
+ {
+ "operation-switch": {
+ "case": [
+ {
+ "execute": [
+ {
+ "invoke": {
+ "target-url": "https://172.17.0.1/api/v1/web/whisk.system/default/CLI_APIGWTEST7_action.http",
+ "verb": "keep"
+ }
+ }
+ ],
+ "operations": [
+ "get_/path"
+ ]
+ }
+ ]
+ }
+ }
+ ]
+ }
}
}
diff --git a/tests/dat/apigw/testswaggerdoc1V2 b/tests/dat/apigw/testswaggerdoc1V2
deleted file mode 100644
index 623ae43..0000000
--- a/tests/dat/apigw/testswaggerdoc1V2
+++ /dev/null
@@ -1,61 +0,0 @@
-{
- "swagger": "2.0",
- "basePath": "/CLI_APIGWTEST7_bp",
- "info": {
- "title": "CLI_APIGWTEST7 API Name",
- "version": "1.0.0"
- },
- "paths": {
- "/path": {
- "get": {
- "operationId": "get_/path",
- "responses": {
- "default": {
- "description": "Default response"
- }
- },
- "x-openwhisk": {
- "action": "CLI_APIGWTEST7_action",
- "namespace": "whisk.system",
- "package": "",
- "url": "https://172.17.0.1/api/v1/web/whisk.system/default/CLI_APIGWTEST7_action.http"
- }
- }
- }
- },
- "x-ibm-configuration": {
- "assembly": {
- "execute": [
- {
- "set-variable": {
- "actions": [
- {
- "set": "message.headers.Authorization",
- "value": "Basic Nzg5YzQ2YjEtNzFmNi00ZWQ1LThjNTQtODE2YWE0ZjhjNTAyOmFiY3pPM3haQ0xyTU42djJCS0sxZFhZRnBYbFBrY2NPRnFtMTJDZEFzTWdSVTRWck5aOWx5R1ZDR3VNREdJd1A="
- }
- ]
- }
- },
- {
- "operation-switch": {
- "case": [
- {
- "execute": [
- {
- "invoke": {
- "target-url": "https://172.17.0.1/api/v1/web/whisk.system/default/CLI_APIGWTEST7_action.http",
- "verb": "keep"
- }
- }
- ],
- "operations": [
- "get_/path"
- ]
- }
- ]
- }
- }
- ]
- }
- }
-}
diff --git a/tests/dat/apigw/testswaggerdoc2 b/tests/dat/apigw/testswaggerdoc2
index 7d710d8..2556853 100644
--- a/tests/dat/apigw/testswaggerdoc2
+++ b/tests/dat/apigw/testswaggerdoc2
@@ -2,226 +2,116 @@
"swagger": "2.0",
"basePath": "/test1/v1",
"info": {
- "title": "/test1/v1",
+ "title": "CLI_APIGWTEST13 API Name",
"version": "1.0.0"
},
"paths": {
- "/whisk.system/utils/echo": {
+ "/whisk_system/utils/echo": {
"get": {
+ "operationId": "get_/whisk_system/utils/echo",
"responses": {
"default": {
"description": "Default response"
}
},
- "x-ibm-op-ext": {
- "actionName": "test1a",
- "actionNamespace": "guest",
- "backendMethod": "POST",
- "backendUrl": "https://192.168.33.13/api/v1/namespaces/guest/actions/test1a",
- "policies": [
- {
- "type": "reqMapping",
- "value": [
- {
- "action": "transform",
- "from": {
- "location": "query",
- "name": "*"
- },
- "to": {
- "location": "body",
- "name": "*"
- }
- },
- {
- "action": "insert",
- "from": {
- "value": "Basic MjNiYzQ2YjEtNzFmNi00ZWQ1LThjNTQtODE2YWE0ZjhjNTAyOjEyM3pPM3haQ0xyTU42djJCS0sxZFhZRnBYbFBrY2NPRnFtMTJDZEFzTWdSVTRWck5aOWx5R1ZDR3VNREdJd1A="
- },
- "to": {
- "location": "header",
- "name": "Authorization"
- }
- },
- {
- "action": "insert",
- "from": {
- "value": "application/json"
- },
- "to": {
- "location": "header",
- "name": "Content-Type"
- }
- },
- {
- "action": "insert",
- "from": {
- "value": "true"
- },
- "to": {
- "location": "query",
- "name": "blocking"
- }
- },
- {
- "action": "insert",
- "from": {
- "value": "true"
- },
- "to": {
- "location": "query",
- "name": "result"
- }
- }
- ]
- }
- ]
+ "x-openwhisk": {
+ "action": "test1a",
+ "namespace": "whisk.system",
+ "package": "",
+ "url": "https://172.17.0.1/api/v1/web/whisk.system/default/test1a.http"
}
},
"post": {
+ "operationId": "post_/whisk_system/utils/echo",
"responses": {
"default": {
"description": "Default response"
}
},
- "x-ibm-op-ext": {
- "actionName": "test1a",
- "actionNamespace": "guest",
- "backendMethod": "POST",
- "backendUrl": "https://192.168.33.13/api/v1/namespaces/guest/actions/test1a",
- "policies": [
- {
- "type": "reqMapping",
- "value": [
- {
- "action": "transform",
- "from": {
- "location": "query",
- "name": "*"
- },
- "to": {
- "location": "body",
- "name": "*"
- }
- },
- {
- "action": "insert",
- "from": {
- "value": "Basic MjNiYzQ2YjEtNzFmNi00ZWQ1LThjNTQtODE2YWE0ZjhjNTAyOjEyM3pPM3haQ0xyTU42djJCS0sxZFhZRnBYbFBrY2NPRnFtMTJDZEFzTWdSVTRWck5aOWx5R1ZDR3VNREdJd1A="
- },
- "to": {
- "location": "header",
- "name": "Authorization"
- }
- },
- {
- "action": "insert",
- "from": {
- "value": "application/json"
- },
- "to": {
- "location": "header",
- "name": "Content-Type"
- }
- },
- {
- "action": "insert",
- "from": {
- "value": "true"
- },
- "to": {
- "location": "query",
- "name": "blocking"
- }
- },
- {
- "action": "insert",
- "from": {
- "value": "true"
- },
- "to": {
- "location": "query",
- "name": "result"
- }
- }
- ]
- }
- ]
+ "x-openwhisk": {
+ "action": "test1a",
+ "namespace": "whisk.system",
+ "package": "",
+ "url": "https://172.17.0.1/api/v1/web/whisk.system/default/test1a.http"
}
}
},
- "/whisk.system/utils/split": {
+ "/whisk_system/utils/split": {
"post": {
+ "operationId": "post_/whisk_system/utils/split",
"responses": {
"default": {
"description": "Default response"
}
},
- "x-ibm-op-ext": {
- "actionName": "test1a",
- "actionNamespace": "guest",
- "backendMethod": "POST",
- "backendUrl": "https://192.168.33.13/api/v1/namespaces/guest/actions/test1a",
- "policies": [
- {
- "type": "reqMapping",
- "value": [
- {
- "action": "transform",
- "from": {
- "location": "query",
- "name": "*"
- },
- "to": {
- "location": "body",
- "name": "*"
- }
- },
- {
- "action": "insert",
- "from": {
- "value": "Basic MjNiYzQ2YjEtNzFmNi00ZWQ1LThjNTQtODE2YWE0ZjhjNTAyOjEyM3pPM3haQ0xyTU42djJCS0sxZFhZRnBYbFBrY2NPRnFtMTJDZEFzTWdSVTRWck5aOWx5R1ZDR3VNREdJd1A="
- },
- "to": {
- "location": "header",
- "name": "Authorization"
- }
- },
- {
- "action": "insert",
- "from": {
- "value": "application/json"
- },
- "to": {
- "location": "header",
- "name": "Content-Type"
+ "x-openwhisk": {
+ "action": "test1a",
+ "namespace": "whisk.system",
+ "package": "",
+ "url": "https://172.17.0.1/api/v1/web/whisk.system/default/test1a.http"
+ }
+ }
+ }
+ },
+ "x-ibm-configuration": {
+ "assembly": {
+ "execute": [
+ {
+ "set-variable": {
+ "actions": [
+ {
+ "set": "message.headers.Authorization",
+ "value": "Basic Nzg5YzQ2YjEtNzFmNi00ZWQ1LThjNTQtODE2YWE0ZjhjNTAyOmFiY3pPM3haQ0xyTU42djJCS0sxZFhZRnBYbFBrY2NPRnFtMTJDZEFzTWdSVTRWck5aOWx5R1ZDR3VNREdJd1A="
+ }
+ ]
+ }
+ },
+ {
+ "operation-switch": {
+ "case": [
+ {
+ "operations": [
+ "get_/whisk_system/utils/echo"
+ ],
+ "execute": [
+ {
+ "invoke": {
+ "target-url": "https://172.17.0.1/api/v1/web/whisk.system/default/test1a.http",
+ "verb": "get"
+ }
}
- },
- {
- "action": "insert",
- "from": {
- "value": "true"
- },
- "to": {
- "location": "query",
- "name": "blocking"
+ ]
+ },
+ {
+ "operations": [
+ "post_/whisk_system/utils/echo"
+ ],
+ "execute": [
+ {
+ "invoke": {
+ "target-url": "https://172.17.0.1/api/v1/web/whisk.system/default/test1a.http",
+ "verb": "post"
+ }
}
- },
- {
- "action": "insert",
- "from": {
- "value": "true"
- },
- "to": {
- "location": "query",
- "name": "result"
+ ]
+ },
+ {
+ "operations": [
+ "post_/whisk_system/utils/split"
+ ],
+ "execute": [
+ {
+ "invoke": {
+ "target-url": "https://172.17.0.1/api/v1/web/whisk.system/default/test1a.http",
+ "verb": "post"
+ }
}
- }
- ]
- }
- ]
+ ]
+ }
+ ]
+ }
}
- }
+ ]
}
}
-}
\ No newline at end of file
+}
diff --git a/tests/dat/apigw/testswaggerdoc2V2 b/tests/dat/apigw/testswaggerdoc2V2
deleted file mode 100644
index 2556853..0000000
--- a/tests/dat/apigw/testswaggerdoc2V2
+++ /dev/null
@@ -1,117 +0,0 @@
-{
- "swagger": "2.0",
- "basePath": "/test1/v1",
- "info": {
- "title": "CLI_APIGWTEST13 API Name",
- "version": "1.0.0"
- },
- "paths": {
- "/whisk_system/utils/echo": {
- "get": {
- "operationId": "get_/whisk_system/utils/echo",
- "responses": {
- "default": {
- "description": "Default response"
- }
- },
- "x-openwhisk": {
- "action": "test1a",
- "namespace": "whisk.system",
- "package": "",
- "url": "https://172.17.0.1/api/v1/web/whisk.system/default/test1a.http"
- }
- },
- "post": {
- "operationId": "post_/whisk_system/utils/echo",
- "responses": {
- "default": {
- "description": "Default response"
- }
- },
- "x-openwhisk": {
- "action": "test1a",
- "namespace": "whisk.system",
- "package": "",
- "url": "https://172.17.0.1/api/v1/web/whisk.system/default/test1a.http"
- }
- }
- },
- "/whisk_system/utils/split": {
- "post": {
- "operationId": "post_/whisk_system/utils/split",
- "responses": {
- "default": {
- "description": "Default response"
- }
- },
- "x-openwhisk": {
- "action": "test1a",
- "namespace": "whisk.system",
- "package": "",
- "url": "https://172.17.0.1/api/v1/web/whisk.system/default/test1a.http"
- }
- }
- }
- },
- "x-ibm-configuration": {
- "assembly": {
- "execute": [
- {
- "set-variable": {
- "actions": [
- {
- "set": "message.headers.Authorization",
- "value": "Basic Nzg5YzQ2YjEtNzFmNi00ZWQ1LThjNTQtODE2YWE0ZjhjNTAyOmFiY3pPM3haQ0xyTU42djJCS0sxZFhZRnBYbFBrY2NPRnFtMTJDZEFzTWdSVTRWck5aOWx5R1ZDR3VNREdJd1A="
- }
- ]
- }
- },
- {
- "operation-switch": {
- "case": [
- {
- "operations": [
- "get_/whisk_system/utils/echo"
- ],
- "execute": [
- {
- "invoke": {
- "target-url": "https://172.17.0.1/api/v1/web/whisk.system/default/test1a.http",
- "verb": "get"
- }
- }
- ]
- },
- {
- "operations": [
- "post_/whisk_system/utils/echo"
- ],
- "execute": [
- {
- "invoke": {
- "target-url": "https://172.17.0.1/api/v1/web/whisk.system/default/test1a.http",
- "verb": "post"
- }
- }
- ]
- },
- {
- "operations": [
- "post_/whisk_system/utils/split"
- ],
- "execute": [
- {
- "invoke": {
- "target-url": "https://172.17.0.1/api/v1/web/whisk.system/default/test1a.http",
- "verb": "post"
- }
- }
- ]
- }
- ]
- }
- }
- ]
- }
- }
-}
diff --git a/tests/src/test/scala/apigw/healthtests/ApiGwEndToEndTests.scala b/tests/src/test/scala/apigw/healthtests/ApiGwEndToEndTests.scala
index a5e1268..200d7a1 100644
--- a/tests/src/test/scala/apigw/healthtests/ApiGwEndToEndTests.scala
+++ b/tests/src/test/scala/apigw/healthtests/ApiGwEndToEndTests.scala
@@ -36,7 +36,6 @@ import common.TestUtils
import common.TestUtils._
import common.Wsk
import common.WskProps
-import common.WskPropsV2
import common.WskTestHelpers
import spray.json._
import spray.json.DefaultJsonProtocol._
@@ -66,81 +65,11 @@ class ApiGwEndToEndTests
*/
override def beforeAll() = {
cliWskPropsFile.deleteOnExit()
- val wskprops = WskPropsV2(token = "SOME TOKEN")
+ val wskprops = WskProps(token = "SOME TOKEN")
wskprops.writeFile(cliWskPropsFile)
println(s"wsk temporary props file created here: ${cliWskPropsFile.getCanonicalPath()}")
}
- behavior of "Wsk api-experimental"
-
- it should s"create an API and successfully invoke that API" in {
- val testName = "APIGWe_HEALTHTEST1"
- val testbasepath = "/" + testName + "_bp"
- val testrelpath = "/path"
- val testurlop = "get"
- val testapiname = testName + " API Name"
- val actionName = testName + "_echo"
- val urlqueryparam = "name"
- val urlqueryvalue = "test"
-
- try {
- println("cli namespace: " + clinamespace)
-
- // Create the action for the API
- val file = TestUtils.getTestActionFilename(s"echo.js")
- wsk.action.create(name = actionName, artifact = Some(file), expectedExitCode = SUCCESS_EXIT)
-
- // Create the API
- var rr = wsk.apiexperimental.create(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- val apiurl = rr.stdout.split("\n")(1)
- println(s"apiurl: '${apiurl}'")
-
- // Validate the API was successfully created
- // List result will look like:
- // ok: APIs
- // Action Verb API Name URL
- // /_//whisk.system/utils/echo get APIGW_HEALTHTEST1 API Name http://172.17.0.1:9001/api/ab9082cd-ea8e-465a-8a65-b491725cc4ef/APIGW_HEALTHTEST1_bp/path
- rr = wsk.apiexperimental.list(basepathOrApiName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath + testrelpath)
-
- // Recreate the API using a JSON swagger file
- rr = wsk.apiexperimental.get(basepathOrApiName = Some(testbasepath))
- val swaggerfile = File.createTempFile("api", ".json")
- swaggerfile.deleteOnExit()
- val bw = new BufferedWriter(new FileWriter(swaggerfile))
- bw.write(rr.stdout)
- bw.close()
-
- // Delete API to that it can be recreated again using the generated swagger file
- val deleteApiResult = wsk.apiexperimental.delete(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
-
- // Create the API again, but use the swagger file this time
- rr = wsk.apiexperimental.create(swagger = Some(swaggerfile.getAbsolutePath()))
- rr.stdout should include("ok: created API")
- val swaggerapiurl = rr.stdout.split("\n")(1)
- println(s"apiurl: '${swaggerapiurl}'")
-
- // Call the API URL and validate the results
- val response = whisk.utils.retry({
- val response = RestAssured.given().config(sslconfig).get(s"$swaggerapiurl?$urlqueryparam=$urlqueryvalue")
- response.statusCode should be(200)
- response
- }, 5, Some(1.second))
- val responseString = response.body.asString
- println("URL invocation response: " + responseString)
- responseString.parseJson.asJsObject.fields(urlqueryparam).convertTo[String] should be(urlqueryvalue)
-
- } finally {
- println("Deleting action: " + actionName)
- val finallydeleteActionResult = wsk.action.delete(name = actionName, expectedExitCode = DONTCARE_EXIT)
- println("Deleting API: " + testbasepath)
- val finallydeleteApiResult = wsk.apiexperimental.delete(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
- }
-
behavior of "Wsk api"
it should s"create an API and successfully invoke that API" in {
diff --git a/tests/src/test/scala/common/Wsk.scala b/tests/src/test/scala/common/Wsk.scala
index ad17921..540857b 100644
--- a/tests/src/test/scala/common/Wsk.scala
+++ b/tests/src/test/scala/common/Wsk.scala
@@ -75,14 +75,6 @@ case class WskProps(
key: String = WhiskProperties.getFileRelativeToWhiskHome("ansible/roles/nginx/files/openwhisk-client-key.pem").getAbsolutePath ,
namespace: String = "_",
apiversion: String = "v1",
- apihost: String = WhiskProperties.getEdgeHost) {
- def overrides = Seq("-i", "--apihost", apihost, "--apiversion", apiversion)
-}
-
-case class WskPropsV2(
- authKey: String = WhiskProperties.readAuthKey(WhiskProperties.getAuthFileForTesting),
- namespace: String = "_",
- apiversion: String = "v1",
apihost: String = WhiskProperties.getEdgeHost,
token: String = "") {
def overrides = Seq("-i", "--apihost", apihost, "--apiversion", apiversion)
diff --git a/tests/src/test/scala/whisk/core/apigw/actions/test/ApiGwRoutemgmtActionTests.scala b/tests/src/test/scala/whisk/core/apigw/actions/test/ApiGwRoutemgmtActionTests.scala
index 5a0f97c..28f9b0f 100644
--- a/tests/src/test/scala/whisk/core/apigw/actions/test/ApiGwRoutemgmtActionTests.scala
+++ b/tests/src/test/scala/whisk/core/apigw/actions/test/ApiGwRoutemgmtActionTests.scala
@@ -72,136 +72,6 @@ class ApiGwRoutemgmtActionTests
bpOrName: Option[String],
relpath: Option[String] = None,
operation: Option[String] = None,
- docid: Option[String] = None): Vector[JsValue] = {
- val parms = Map[String, JsValue]() ++
- Map("__ow_user" -> wskprops.namespace.toJson) ++
- { bpOrName map { b => Map("basepath" -> b.toJson) } getOrElse Map[String, JsValue]() } ++
- { relpath map { r => Map("relpath" -> r.toJson) } getOrElse Map[String, JsValue]() } ++
- { operation map { o => Map("operation" -> o.toJson) } getOrElse Map[String, JsValue]() } ++
- { docid map { d => Map("docid" -> d.toJson) } getOrElse Map[String, JsValue]() }
-
- val rr = wsk.action.invoke(
- name = "routemgmt/getApi",
- parameters = parms,
- blocking = true,
- result = true,
- expectedExitCode = SUCCESS_EXIT)(wskprops)
- var apiJsArray: JsArray =
- try {
- var apisobj = rr.stdout.parseJson.asJsObject.fields("apis")
- apisobj.convertTo[JsArray]
- } catch {
- case e: Exception =>
- JsArray.empty
- }
- return apiJsArray.elements
- }
-
- def createApi(
- namespace: Option[String] = Some("_"),
- basepath: Option[String] = Some("/"),
- relpath: Option[String],
- operation: Option[String],
- apiname: Option[String],
- action: Option[ApiAction],
- swagger: Option[String] = None,
- expectedExitCode: Int = SUCCESS_EXIT): RunResult = {
- val parms = Map[String, JsValue]() ++
- { namespace map { n => Map("namespace" -> n.toJson) } getOrElse Map[String, JsValue]() } ++
- { basepath map { b => Map("gatewayBasePath" -> b.toJson) } getOrElse Map[String, JsValue]() } ++
- { relpath map { r => Map("gatewayPath" -> r.toJson) } getOrElse Map[String, JsValue]() } ++
- { operation map { o => Map("gatewayMethod" -> o.toJson) } getOrElse Map[String, JsValue]() } ++
- { apiname map { an => Map("apiName" -> an.toJson) } getOrElse Map[String, JsValue]() } ++
- { action map { a => Map("action" -> a.toJson) } getOrElse Map[String, JsValue]() } ++
- { swagger map { s => Map("swagger" -> s.toJson) } getOrElse Map[String, JsValue]() }
- val parm = Map[String, JsValue]("apidoc" -> JsObject(parms)) ++
- { namespace map { n => Map("__ow_user" -> n.toJson) } getOrElse Map[String, JsValue]() }
-
- val rr = wsk.action.invoke(
- name = "routemgmt/createApi",
- parameters = parm,
- blocking = true,
- result = true,
- expectedExitCode = expectedExitCode)(wskprops)
- return rr
- }
-
- def deleteApi(
- namespace: Option[String] = Some("_"),
- basepath: Option[String] = Some("/"),
- relpath: Option[String] = None,
- operation: Option[String] = None,
- apiname: Option[String] = None,
- expectedExitCode: Int = SUCCESS_EXIT): RunResult = {
- val parms = Map[String, JsValue]() ++
- { namespace map { n => Map("__ow_user" -> n.toJson) } getOrElse Map[String, JsValue]() } ++
- { basepath map { b => Map("basepath" -> b.toJson) } getOrElse Map[String, JsValue]() } ++
- { relpath map { r => Map("relpath" -> r.toJson) } getOrElse Map[String, JsValue]() } ++
- { operation map { o => Map("operation" -> o.toJson) } getOrElse Map[String, JsValue]() } ++
- { apiname map { an => Map("apiname" -> an.toJson) } getOrElse Map[String, JsValue]() }
-
- val rr = wsk.action.invoke(
- name = "routemgmt/deleteApi",
- parameters = parms,
- blocking = true,
- result = true,
- expectedExitCode = expectedExitCode)(wskprops)
- return rr
- }
-
- def apiMatchExperimental(
- apiarr: Vector[JsValue],
- basepath: String = "/",
- relpath: String = "",
- operation: String = "",
- apiname: String = "",
- action: ApiAction = null): Boolean = {
- var matches: Boolean = false
- for (api <- apiarr) {
- val basepathExists = JsObjectHelper(api.asJsObject).fieldPathExists("value", "apidoc", "basePath")
- if (basepathExists) {
- System.out.println("basePath exists")
- val basepathMatches = (JsObjectHelper(api.asJsObject).getFieldPath("value", "apidoc", "basePath").get.convertTo[String] == basepath)
- if (basepathMatches) {
- System.out.println("basePath matches: " + basepath)
- val apinameExists = JsObjectHelper(api.asJsObject).fieldPathExists("value", "apidoc", "info", "title")
- if (apinameExists) {
- System.out.println("api name exists")
- val apinameMatches = (JsObjectHelper(api.asJsObject).getFieldPath("value", "apidoc", "info", "title").get.convertTo[String] == apiname)
- if (apinameMatches) {
- System.out.println("api name matches: " + apiname)
- val endpointMatches = JsObjectHelper(api.asJsObject).fieldPathExists("value", "apidoc", "paths", relpath, operation)
- if (endpointMatches) {
- System.out.println("endpoint exists/matches : " + relpath + " " + operation)
- val actionConfig = JsObjectHelper(api.asJsObject).getFieldPath("value", "apidoc", "paths", relpath, operation, "x-ibm-op-ext").get.asJsObject
- val actionMatches = actionMatchExperimental(actionConfig, action)
- if (actionMatches) {
- System.out.println("endpoint action matches")
- matches = true;
- }
- }
- }
- }
- }
- }
- }
- return matches
- }
-
- def actionMatchExperimental(
- jsAction: JsObject,
- action: ApiAction): Boolean = {
- val matches = jsAction.fields("backendMethod").convertTo[String] == action.backendMethod &&
- jsAction.fields("backendUrl").convertTo[String] == action.backendUrl &&
- jsAction.fields("actionNamespace").convertTo[String] == action.namespace &&
- jsAction.fields("actionName").convertTo[String] == action.name
- return matches
- }
-
- def getApisV2(
- bpOrName: Option[String],
- relpath: Option[String] = None,
- operation: Option[String] = None,
docid: Option[String] = None,
accesstoken: Option[String] = Some("AnAccessToken"),
spaceguid: Option[String] = Some("ASpaceGuid") ): Vector[JsValue] = {
@@ -231,7 +101,7 @@ class ApiGwRoutemgmtActionTests
return apiJsArray.elements
}
- def createApiV2(
+ def createApi(
namespace: Option[String] = Some("_"),
basepath: Option[String] = Some("/"),
relpath: Option[String],
@@ -264,7 +134,7 @@ class ApiGwRoutemgmtActionTests
return rr
}
- def deleteApiV2(
+ def deleteApi(
namespace: Option[String] = Some("_"),
basepath: Option[String] = Some("/"),
relpath: Option[String] = None,
@@ -342,7 +212,7 @@ class ApiGwRoutemgmtActionTests
return matches
}
- behavior of "API Gateway routemgmt action parameter validation"
+ behavior of "API Gateway apimgmt action parameter validation"
it should "verify successful creation of a new API" in {
val testName = "APIGWTEST1"
@@ -352,7 +222,7 @@ class ApiGwRoutemgmtActionTests
val testapiname = testName + " API Name"
val actionName = testName + "_action"
val actionNamespace = wskprops.namespace
- val actionUrl = "http://some.whisk.host/api/v1/namespaces/" + actionNamespace + "/actions/" + actionName
+ val actionUrl = "https://some.whisk.host/api/v1/web/" + actionNamespace + "/default/" + actionName + ".json"
val actionAuthKey = testName + "_authkey"
val testaction = ApiAction(name = actionName, namespace = actionNamespace, backendUrl = actionUrl, authkey = actionAuthKey)
@@ -362,7 +232,7 @@ class ApiGwRoutemgmtActionTests
JsObjectHelper(createResult.stdout.parseJson.asJsObject).fieldPathExists("apidoc") should be(true)
val apiVector = getApis(bpOrName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
apiVector.size should be > 0
- apiMatchExperimental(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(true)
+ apiMatch(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(true)
} finally {
val deleteResult = deleteApi(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), expectedExitCode = DONTCARE_EXIT)
}
@@ -376,7 +246,7 @@ class ApiGwRoutemgmtActionTests
val testapiname = testName + " API Name"
val actionName = testName + "_action"
val actionNamespace = wskprops.namespace
- val actionUrl = "http://some.whisk.host/api/v1/namespaces/" + actionNamespace + "/actions/" + actionName
+ val actionUrl = "https://some.whisk.host/api/v1/web/" + actionNamespace + "/default/" + actionName + ".json"
val actionAuthKey = testName + "_authkey"
val testaction = ApiAction(name = actionName, namespace = actionNamespace, backendUrl = actionUrl, authkey = actionAuthKey)
@@ -386,10 +256,10 @@ class ApiGwRoutemgmtActionTests
JsObjectHelper(createResult.stdout.parseJson.asJsObject).fieldPathExists("apidoc") should be(true)
var apiVector = getApis(bpOrName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
apiVector.size should be > 0
- apiMatchExperimental(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(true)
+ apiMatch(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(true)
val deleteResult = deleteApi(namespace = Some(wskprops.namespace), basepath = Some(testbasepath))
apiVector = getApis(bpOrName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
- apiMatchExperimental(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(false)
+ apiMatch(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(false)
} finally {
val deleteResult = deleteApi(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), expectedExitCode = DONTCARE_EXIT)
}
@@ -405,7 +275,7 @@ class ApiGwRoutemgmtActionTests
val testapiname = testName + " API Name"
val actionName = testName + "_action"
val actionNamespace = wskprops.namespace
- val actionUrl = "http://some.whisk.host/api/v1/namespaces/" + actionNamespace + "/actions/" + actionName
+ val actionUrl = "https://some.whisk.host/api/v1/web/" + actionNamespace + "/default/" + actionName + ".json"
val actionAuthKey = testName + "_authkey"
val testaction = ApiAction(name = actionName, namespace = actionNamespace, backendUrl = actionUrl, authkey = actionAuthKey)
@@ -417,143 +287,10 @@ class ApiGwRoutemgmtActionTests
JsObjectHelper(createResult.stdout.parseJson.asJsObject).fieldPathExists("apidoc") should be(true)
var apiVector = getApis(bpOrName = Some(testbasepath))
apiVector.size should be > 0
- apiMatchExperimental(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(true)
- apiMatchExperimental(apiVector, testbasepath, testnewrelpath, testnewurlop, testapiname, testaction) should be(true)
- } finally {
- val deleteResult = deleteApi(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "reject routemgmt actions that are invoked with not enough parameters" in {
- val invalidArgs = Seq(
- //getApi
- ("/whisk.system/routemgmt/getApi", ANY_ERROR_EXIT, "Invalid authentication.", Seq()),
-
- //deleteApi
- ("/whisk.system/routemgmt/deleteApi", ANY_ERROR_EXIT, "Invalid authentication.", Seq("-p", "basepath", "/ApiGwRoutemgmtActionTests_bp")),
- ("/whisk.system/routemgmt/deleteApi", ANY_ERROR_EXIT, "basepath is required", Seq("-p", "__ow_user", "_")),
- ("/whisk.system/routemgmt/deleteApi", ANY_ERROR_EXIT, "When specifying an operation, the path is required",
- Seq("-p", "__ow_user", "_", "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp", "-p", "operation", "get")),
-
- //createApi
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "apidoc is required", Seq("-p", "__ow_user", "_")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "apidoc is missing the namespace field",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", "{}")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "apidoc is missing the gatewayBasePath field",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", """{"namespace":"_"}""")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "apidoc is missing the gatewayPath field",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp"}""")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "apidoc is missing the gatewayMethod field",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp"}""")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "apidoc is missing the action field",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get"}""")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "action is missing the backendMethod field",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{}}""")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "action is missing the backendUrl field",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{"backendMethod":"post"}}""")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "action is missing the namespace field",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{"backendMethod":"post","backendUrl":"URL"}}""")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "action is missing the name field",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{"backendMethod":"post","backendUrl":"URL","namespace":"_"}}""")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "action is missing the authkey field",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{"backendMethod":"post","backendUrl":"URL","namespace":"_","name":"N"}}""")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "swagger and gatewayBasePath are mutually exclusive and cannot be specified together",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{"backendMethod":"post","backendUrl":"URL","namespace":"_","name":"N","authkey":"XXXX"},"swagger":{}}""")),
- ("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "apidoc field cannot be parsed. Ensure it is valid JSON",
- Seq("-p", "__ow_user", "_", "-p", "apidoc", "{1:[}}}")))
-
- invalidArgs foreach {
- case (action: String, exitcode: Int, errmsg: String, params: Seq[String]) =>
- val cmd: Seq[String] = Seq("action",
- "invoke",
- action,
- "-i", "-b", "-r",
- "--apihost", wskprops.apihost,
- "--auth", wskprops.authKey) ++ params
- val rr = wsk.cli(cmd, expectedExitCode = exitcode)
- rr.stderr should include regex (errmsg)
- }
- }
-
- behavior of "API Gateway apimgmt action parameter validation"
-
- it should "verify successful creation of a new V2 API" in {
- val testName = "APIGWTEST1"
- val testbasepath = "/" + testName + "_bp"
- val testrelpath = "/path"
- val testurlop = "get"
- val testapiname = testName + " API Name"
- val actionName = testName + "_action"
- val actionNamespace = wskprops.namespace
- val actionUrl = "https://some.whisk.host/api/v1/web/" + actionNamespace + "/default/" + actionName + ".json"
- val actionAuthKey = testName + "_authkey"
- val testaction = ApiAction(name = actionName, namespace = actionNamespace, backendUrl = actionUrl, authkey = actionAuthKey)
-
- try {
- val createResult = createApiV2(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), relpath = Some(testrelpath),
- operation = Some(testurlop), apiname = Some(testapiname), action = Some(testaction))
- JsObjectHelper(createResult.stdout.parseJson.asJsObject).fieldPathExists("apidoc") should be(true)
- val apiVector = getApisV2(bpOrName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
- apiVector.size should be > 0
- apiMatch(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(true)
- } finally {
- val deleteResult = deleteApiV2(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "verify successful V2 API deletion using basepath" in {
- val testName = "APIGWTEST2"
- val testbasepath = "/" + testName + "_bp"
- val testrelpath = "/path"
- val testurlop = "get"
- val testapiname = testName + " API Name"
- val actionName = testName + "_action"
- val actionNamespace = wskprops.namespace
- val actionUrl = "https://some.whisk.host/api/v1/web/" + actionNamespace + "/default/" + actionName + ".json"
- val actionAuthKey = testName + "_authkey"
- val testaction = ApiAction(name = actionName, namespace = actionNamespace, backendUrl = actionUrl, authkey = actionAuthKey)
-
- try {
- val createResult = createApiV2(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), relpath = Some(testrelpath),
- operation = Some(testurlop), apiname = Some(testapiname), action = Some(testaction))
- JsObjectHelper(createResult.stdout.parseJson.asJsObject).fieldPathExists("apidoc") should be(true)
- var apiVector = getApisV2(bpOrName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
- apiVector.size should be > 0
- apiMatch(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(true)
- val deleteResult = deleteApiV2(namespace = Some(wskprops.namespace), basepath = Some(testbasepath))
- apiVector = getApisV2(bpOrName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
- apiMatch(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(false)
- } finally {
- val deleteResult = deleteApiV2(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "verify successful addition of new relative path to existing V2 API" in {
- val testName = "APIGWTEST3"
- val testbasepath = "/" + testName + "_bp"
- val testrelpath = "/path"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testnewurlop = "delete"
- val testapiname = testName + " API Name"
- val actionName = testName + "_action"
- val actionNamespace = wskprops.namespace
- val actionUrl = "https://some.whisk.host/api/v1/web/" + actionNamespace + "/default/" + actionName + ".json"
- val actionAuthKey = testName + "_authkey"
- val testaction = ApiAction(name = actionName, namespace = actionNamespace, backendUrl = actionUrl, authkey = actionAuthKey)
-
- try {
- var createResult = createApiV2(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), relpath = Some(testrelpath),
- operation = Some(testurlop), apiname = Some(testapiname), action = Some(testaction))
- createResult = createApiV2(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), relpath = Some(testnewrelpath),
- operation = Some(testnewurlop), apiname = Some(testapiname), action = Some(testaction))
- JsObjectHelper(createResult.stdout.parseJson.asJsObject).fieldPathExists("apidoc") should be(true)
- var apiVector = getApisV2(bpOrName = Some(testbasepath))
- apiVector.size should be > 0
apiMatch(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(true)
apiMatch(apiVector, testbasepath, testnewrelpath, testnewurlop, testapiname, testaction) should be(true)
} finally {
- val deleteResult = deleteApiV2(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), expectedExitCode = DONTCARE_EXIT)
+ val deleteResult = deleteApi(namespace = Some(wskprops.namespace), basepath = Some(testbasepath), expectedExitCode = DONTCARE_EXIT)
}
}
diff --git a/tests/src/test/scala/whisk/core/cli/test/ApiGwTests.scala b/tests/src/test/scala/whisk/core/cli/test/ApiGwTests.scala
index 0c1849b..e7abf10 100644
--- a/tests/src/test/scala/whisk/core/cli/test/ApiGwTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/ApiGwTests.scala
@@ -18,6 +18,8 @@
package whisk.core.cli.test
import java.io.File
+import java.io.BufferedWriter
+import java.io.FileWriter
import java.time.Instant
import scala.collection.mutable.ArrayBuffer
import scala.concurrent.duration._
@@ -30,7 +32,6 @@ import common.TestUtils
import common.WhiskProperties
import common.Wsk
import common.WskProps
-import common.WskPropsV2
import common.WskTestHelpers
/**
@@ -94,7 +95,7 @@ class ApiGwTests
override def beforeAll() = {
//cliWskPropsFile = File.createTempFile("wskprops", ".tmp")
cliWskPropsFile.deleteOnExit()
- val wskprops = WskPropsV2(token = "SOME TOKEN")
+ val wskprops = WskProps(token = "SOME TOKEN")
wskprops.writeFile(cliWskPropsFile)
println(s"wsk temporary props file created here: ${cliWskPropsFile.getCanonicalPath()}")
}
@@ -108,51 +109,6 @@ class ApiGwTests
checkThrottle(30)
}
- def apiCreateExperimental(
- basepath: Option[String] = None,
- relpath: Option[String] = None,
- operation: Option[String] = None,
- action: Option[String] = None,
- apiname: Option[String] = None,
- swagger: Option[String] = None,
- expectedExitCode: Int = SUCCESS_EXIT): RunResult = {
-
- checkThrottle()
- wsk.apiexperimental.create(basepath, relpath, operation, action, apiname, swagger, expectedExitCode)
- }
-
- def apiListExperimental(
- basepathOrApiName: Option[String] = None,
- relpath: Option[String] = None,
- operation: Option[String] = None,
- limit: Option[Int] = None,
- since: Option[Instant] = None,
- full: Option[Boolean] = None,
- expectedExitCode: Int = SUCCESS_EXIT): RunResult = {
-
- checkThrottle()
- wsk.apiexperimental.list(basepathOrApiName, relpath, operation, limit, since, full, expectedExitCode)
- }
-
- def apiGetExperimental(
- basepathOrApiName: Option[String] = None,
- full: Option[Boolean] = None,
- expectedExitCode: Int = SUCCESS_EXIT): RunResult = {
-
- checkThrottle()
- wsk.apiexperimental.get(basepathOrApiName, full, expectedExitCode)
- }
-
- def apiDeleteExperimental(
- basepathOrApiName: String,
- relpath: Option[String] = None,
- operation: Option[String] = None,
- expectedExitCode: Int = SUCCESS_EXIT): RunResult = {
-
- checkThrottle()
- wsk.apiexperimental.delete(basepathOrApiName, relpath, operation, expectedExitCode)
- }
-
def apiCreate(
basepath: Option[String] = None,
relpath: Option[String] = None,
@@ -204,402 +160,77 @@ class ApiGwTests
wsk.api.delete(basepathOrApiName, relpath, operation, expectedExitCode, cliCfgFile)
}
- behavior of "Wsk api-experimental"
+ behavior of "Wsk api"
- it should "reject api commands having an invalid path parameter" in {
+ it should "reject an api commands with an invalid path parameter" in {
val badpath = "badpath"
- var rr = apiCreateExperimental(basepath = Some("/basepath"), relpath = Some(badpath), operation = Some("GET"), action = Some("action"), expectedExitCode = ANY_ERROR_EXIT)
+ var rr = apiCreate(basepath = Some("/basepath"), relpath = Some(badpath), operation = Some("GET"), action = Some("action"), expectedExitCode = ANY_ERROR_EXIT)
rr.stderr should include (s"'${badpath}' must begin with '/'")
- rr = apiDeleteExperimental(basepathOrApiName = "/basepath", relpath = Some(badpath), operation = Some("GET"), expectedExitCode = ANY_ERROR_EXIT)
+ rr = apiDelete(basepathOrApiName = "/basepath", relpath = Some(badpath), operation = Some("GET"), expectedExitCode = ANY_ERROR_EXIT)
rr.stderr should include (s"'${badpath}' must begin with '/'")
- rr = apiListExperimental(basepathOrApiName = Some("/basepath"), relpath = Some(badpath), operation = Some("GET"), expectedExitCode = ANY_ERROR_EXIT)
+ rr = apiList(basepathOrApiName = Some("/basepath"), relpath = Some(badpath), operation = Some("GET"), expectedExitCode = ANY_ERROR_EXIT)
rr.stderr should include (s"'${badpath}' must begin with '/'")
}
- it should "verify full list output" in {
- val testName = "CLI_APIGWTEST_RO1"
- val testbasepath = "/" + testName + "_bp"
- val testrelpath = "/path"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName + " API Name"
- val actionName = testName + "_action"
- try {
- println("cli namespace: " + clinamespace)
-
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- println("api create: " + rr.stdout)
- rr.stdout should include("ok: created API")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), full = Some(true))
- println("api list: " + rr.stdout)
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"Action:\\s+/${clinamespace}/${actionName}\n")
- rr.stdout should include regex (s"Verb:\\s+${testurlop}\n")
- rr.stdout should include regex (s"Base path:\\s+${testbasepath}\n")
- rr.stdout should include regex (s"Path:\\s+${testrelpath}\n")
- rr.stdout should include regex (s"API Name:\\s+${testapiname}\n")
- rr.stdout should include regex (s"URL:\\s+")
- rr.stdout should include(testbasepath + testrelpath)
- }
- finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath)
- }
- }
-
- it should "verify successful creation and deletion of a new API" in {
- val testName = "CLI_APIGWTEST1"
- val testbasepath = "/"+testName+"_bp"
- val testrelpath = "/path"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName+" API Name"
- val actionName = testName+"_action"
- try {
- println("cli namespace: "+clinamespace)
-
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath + testrelpath)
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath)
- deleteresult.stdout should include("ok: deleted API")
- }
- finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "verify get API name " in {
- val testName = "CLI_APIGWTEST3"
- val testbasepath = "/"+testName+"_bp"
- val testrelpath = "/path"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName+" API Name"
- val actionName = testName+"_action"
- try {
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiGetExperimental(basepathOrApiName = Some(testapiname))
- rr.stdout should include(testbasepath)
- rr.stdout should include(s"${actionName}")
- }
- finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "verify delete API name " in {
- val testName = "CLI_APIGWTEST4"
- val testbasepath = "/"+testName+"_bp"
- val testrelpath = "/path"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName+" API Name"
- val actionName = testName+"_action"
- try {
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiDeleteExperimental(basepathOrApiName = testapiname)
- rr.stdout should include("ok: deleted API")
- }
- finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "verify delete API basepath " in {
- val testName = "CLI_APIGWTEST5"
- val testbasepath = "/"+testName+"_bp"
- val testrelpath = "/path"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName+" API Name"
- val actionName = testName+"_action"
- try {
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiDeleteExperimental(basepathOrApiName = testbasepath)
- rr.stdout should include("ok: deleted API")
- }
- finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "verify adding endpoints to existing api" in {
- val testName = "CLI_APIGWTEST6"
- val testbasepath = "/"+testName+"_bp"
- val testrelpath = "/path2"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName+" API Name"
- val actionName = testName+"_action"
- val newEndpoint = "/newEndpoint"
- try {
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(newEndpoint), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath))
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath + testrelpath)
- rr.stdout should include(testbasepath + newEndpoint)
- }
- finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "verify successful creation with swagger doc as input" in {
- // NOTE: These values must match the swagger file contents
- val testName = "CLI_APIGWTEST7"
- val testbasepath = "/"+testName+"_bp"
- val testrelpath = "/path"
- val testurlop = "get"
- val testapiname = testName+" API Name"
- val actionName = testName+"_action"
- val swaggerPath = TestUtils.getTestApiGwFilename("testswaggerdoc1")
- try {
- var rr = apiCreateExperimental(swagger = Some(swaggerPath))
- rr.stdout should include("ok: created API")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
- println("list stdout: "+rr.stdout)
- println("list stderr: "+rr.stderr)
- rr.stdout should include("ok: APIs")
- // Actual CLI namespace will vary from local dev to automated test environments, so don't check
- rr.stdout should include regex (s"/[@\\w._\\-]+/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath + testrelpath)
- }
- finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "verify adding endpoints to two existing apis" in {
- val testName = "CLI_APIGWTEST8"
- val testbasepath = "/"+testName+"_bp"
- val testbasepath2 = "/"+testName+"_bp2"
- val testrelpath = "/path2"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName+" API Name"
- val actionName = testName+"_action"
- val newEndpoint = "/newEndpoint"
- try {
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiCreateExperimental(basepath = Some(testbasepath2), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
-
- // Update both APIs - each with a new endpoint
- rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(newEndpoint), operation = Some(testurlop), action = Some(actionName))
- rr.stdout should include("ok: created API")
- rr = apiCreateExperimental(basepath = Some(testbasepath2), relpath = Some(newEndpoint), operation = Some(testurlop), action = Some(actionName))
- rr.stdout should include("ok: created API")
-
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath))
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath + testrelpath)
- rr.stdout should include(testbasepath + newEndpoint)
-
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath2))
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath2 + testrelpath)
- rr.stdout should include(testbasepath2 + newEndpoint)
- }
- finally {
- var deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath2, expectedExitCode = DONTCARE_EXIT)
- }
- }
-
- it should "verify successful creation of a new API using an action name using all allowed characters" in {
- // Be aware: full action name is close to being truncated by the 'list' command
- // e.g. /lime@us.ibm.com/CLI_APIGWTEST9a-c@t ion is currently at the 40 char 'list' display max
- val testName = "CLI_APIGWTEST9"
- val testbasepath = "/" + testName + "_bp"
- val testrelpath = "/path"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName+" API Name"
- val actionName = testName+"a-c@t ion"
- try {
- println("cli namespace: "+clinamespace)
+ it should "reject an api commands with an invalid verb parameter" in {
+ val badverb = "badverb"
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath + testrelpath)
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath)
- deleteresult.stdout should include("ok: deleted API")
- }
- finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
- }
+ var rr = apiCreate(basepath = Some("/basepath"), relpath = Some("/path"), operation = Some(badverb), action = Some("action"), expectedExitCode = ANY_ERROR_EXIT)
+ rr.stderr should include(s"'${badverb}' is not a valid API verb. Valid values are:")
- it should "verify failed creation with invalid swagger doc as input" in {
- val testName = "CLI_APIGWTEST10"
- val testbasepath = "/" + testName + "_bp"
- val testrelpath = "/path"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName + " API Name"
- val actionName = testName + "_action"
- val swaggerPath = TestUtils.getTestApiGwFilename(s"testswaggerdocinvalid")
- try {
- var rr = apiCreateExperimental(swagger = Some(swaggerPath), expectedExitCode = ANY_ERROR_EXIT)
- println("api create stdout: " + rr.stdout)
- println("api create stderr: " + rr.stderr)
- rr.stderr should include(s"Swagger file is invalid")
- } finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
- }
+ rr = apiDelete(basepathOrApiName = "/basepath", relpath = Some("/path"), operation = Some(badverb), expectedExitCode = ANY_ERROR_EXIT)
+ rr.stderr should include(s"'${badverb}' is not a valid API verb. Valid values are:")
- it should "verify delete basepath/path " in {
- val testName = "CLI_APIGWTEST11"
- val testbasepath = "/" + testName + "_bp"
- val testrelpath = "/path"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName + " API Name"
- val actionName = testName + "_action"
- try {
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- var rr2 = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testnewrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr2.stdout should include("ok: created API")
- rr = apiDeleteExperimental(basepathOrApiName = testbasepath, relpath = Some(testrelpath))
- rr.stdout should include("ok: deleted " + testrelpath +" from "+ testbasepath)
- rr2 = apiListExperimental(basepathOrApiName = Some(testbasepath), relpath = Some(testnewrelpath))
- rr2.stdout should include("ok: APIs")
- rr2.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr2.stdout should include(testbasepath + testnewrelpath)
- } finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
+ rr = apiList(basepathOrApiName = Some("/basepath"), relpath = Some("/path"), operation = Some(badverb), expectedExitCode = ANY_ERROR_EXIT)
+ rr.stderr should include(s"'${badverb}' is not a valid API verb. Valid values are:")
}
- it should "verify delete single operation from existing API basepath/path/operation(s) " in {
- val testName = "CLI_APIGWTEST12"
- val testbasepath = "/" + testName + "_bp"
- val testrelpath = "/path2"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testurlop2 = "post"
- val testapiname = testName + " API Name"
- val actionName = testName + "_action"
- try {
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop2), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath))
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath + testrelpath)
- rr = apiDeleteExperimental(basepathOrApiName = testbasepath,relpath = Some(testrelpath), operation = Some(testurlop2))
- rr.stdout should include("ok: deleted " + testrelpath + " " + "POST" +" from "+ testbasepath)
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath))
- rr.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- } finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
- }
+ it should "reject an api create command that specifies a nonexistent configuration file" in {
+ val configfile = "/nonexistent/file"
- it should "verify successful creation with complex swagger doc as input" in {
- val testName = "CLI_APIGWTEST13"
- val testbasepath = "/test1/v1"
- val testrelpath = "/whisk.system/utils/echo"
- val testrelpath2 = "/whisk.system/utils/split"
- val testurlop = "get"
- val testapiname = "/test1/v1"
- val actionName = "test1a"
- val swaggerPath = TestUtils.getTestApiGwFilename(s"testswaggerdoc2")
- try {
- var rr = apiCreateExperimental(swagger = Some(swaggerPath))
- println("api create stdout: " + rr.stdout)
- println("api create stderror: " + rr.stderr)
- rr.stdout should include("ok: created API")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath))
- rr.stdout should include("ok: APIs")
- // Actual CLI namespace will vary from local dev to automated test environments, so don't check
- rr.stdout should include regex (s"/[@\\w._\\-]+/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath + testrelpath)
- rr.stdout should include(testbasepath + testrelpath2)
- } finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- }
+ var rr = apiCreate(swagger = Some(configfile), expectedExitCode = ANY_ERROR_EXIT)
+ rr.stderr should include(s"Error reading swagger file '${configfile}':")
}
- it should "verify successful creation and deletion with multiple base paths" in {
- val testName = "CLI_APIGWTEST14"
- val testbasepath = "/" + testName + "_bp"
- val testbasepath2 = "/" + testName + "_bp2"
- val testrelpath = "/path"
- val testnewrelpath = "/path_new"
- val testurlop = "get"
- val testapiname = testName + " API Name"
- val actionName = testName + "_action"
- try {
- var rr = apiCreateExperimental(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath + testrelpath)
- rr = apiCreateExperimental(basepath = Some(testbasepath2), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
- rr.stdout should include("ok: created API")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath2), relpath = Some(testrelpath), operation = Some(testurlop))
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath2 + testrelpath)
- rr = apiDeleteExperimental(basepathOrApiName = testbasepath2)
- rr.stdout should include("ok: deleted API")
- rr = apiListExperimental(basepathOrApiName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
- rr.stdout should include("ok: APIs")
- rr.stdout should include regex (s"/${clinamespace}/${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
- rr.stdout should include(testbasepath + testrelpath)
- rr = apiDeleteExperimental(basepathOrApiName = testbasepath)
- rr.stdout should include("ok: deleted API")
- } finally {
- var deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
- deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath2, expectedExitCode = DONTCARE_EXIT)
- }
- }
+ it should "reject an api create command specifying a non-JSON configuration file" in {
+ val file = File.createTempFile("api.json", ".txt")
+ file.deleteOnExit()
+ val filename = file.getAbsolutePath()
- it should "reject deletion of a non-existent api" in {
- val nonexistentApi = "/not-there"
+ val bw = new BufferedWriter(new FileWriter(file))
+ bw.write("a=A")
+ bw.close()
- var rr = apiDeleteExperimental(basepathOrApiName = nonexistentApi, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include (s"API '${nonexistentApi}' does not exist")
+ var rr = apiCreate(swagger = Some(filename), expectedExitCode = ANY_ERROR_EXIT)
+ rr.stderr should include(s"Error parsing swagger file '${filename}':")
}
- behavior of "Wsk api"
+ it should "reject an api create command specifying a non-swagger JSON configuration file" in {
+ val file = File.createTempFile("api.json", ".txt")
+ file.deleteOnExit()
+ val filename = file.getAbsolutePath()
- it should "reject an api commands with an invalid path parameter" in {
- val badpath = "badpath"
+ val bw = new BufferedWriter(new FileWriter(file))
+ bw.write("""|{
+ | "swagger": "2.0",
+ | "info": {
+ | "title": "My API",
+ | "version": "1.0.0"
+ | },
+ | "BADbasePath": "/bp",
+ | "paths": {
+ | "/rp": {
+ | "get":{}
+ | }
+ | }
+ |}""".stripMargin)
+ bw.close()
- var rr = apiCreate(basepath = Some("/basepath"), relpath = Some(badpath), operation = Some("GET"), action = Some("action"), expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include (s"'${badpath}' must begin with '/'")
-
- rr = apiDelete(basepathOrApiName = "/basepath", relpath = Some(badpath), operation = Some("GET"), expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include (s"'${badpath}' must begin with '/'")
-
- rr = apiList(basepathOrApiName = Some("/basepath"), relpath = Some(badpath), operation = Some("GET"), expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include (s"'${badpath}' must begin with '/'")
+ var rr = apiCreate(swagger = Some(filename), expectedExitCode = ANY_ERROR_EXIT)
+ rr.stderr should include(s"Swagger file is invalid (missing basePath, info, paths, or swagger fields")
}
it should "verify full list output" in {
@@ -781,7 +412,7 @@ class ApiGwTests
val testurlop = "get"
val testapiname = testName+" API Name"
val actionName = testName+"_action"
- val swaggerPath = TestUtils.getTestApiGwFilename("testswaggerdoc1V2")
+ val swaggerPath = TestUtils.getTestApiGwFilename("testswaggerdoc1")
try {
var rr = apiCreate(swagger = Some(swaggerPath))
rr.stdout should include("ok: created API")
@@ -963,7 +594,7 @@ class ApiGwTests
val testurlop = "get"
val testapiname = testName + " API Name"
val actionName = "test1a"
- val swaggerPath = TestUtils.getTestApiGwFilename(s"testswaggerdoc2V2")
+ val swaggerPath = TestUtils.getTestApiGwFilename(s"testswaggerdoc2")
try {
var rr = apiCreate(swagger = Some(swaggerPath))
println("api create stdout: " + rr.stdout)
@@ -1035,7 +666,7 @@ class ApiGwTests
rr.stderr should include("does not exist")
}
finally {
- val deleteresult = apiDeleteExperimental(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
+ val deleteresult = apiDelete(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
}
}
diff --git a/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala b/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
index af1297b..2d3b847 100644
--- a/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
@@ -17,9 +17,6 @@
package whisk.core.cli.test
-import java.io.File
-import java.io.BufferedWriter
-import java.io.FileWriter
import java.time.Instant
import java.net.URLEncoder
import java.nio.charset.StandardCharsets
@@ -844,84 +841,6 @@ class WskBasicUsageTests
}
}
- behavior of "Wsk api"
-
- it should "reject an api commands with an invalid path parameter" in {
- val badpath = "badpath"
-
- var rr = wsk.cli(Seq("api-experimental", "create", "/basepath", badpath, "GET", "action", "--auth", wskprops.authKey) ++ wskprops.overrides, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include(s"'${badpath}' must begin with '/'")
-
- rr = wsk.cli(Seq("api-experimental", "delete", "/basepath", badpath, "GET", "--auth", wskprops.authKey) ++ wskprops.overrides, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include(s"'${badpath}' must begin with '/'")
-
- rr = wsk.cli(Seq("api-experimental", "list", "/basepath", badpath, "GET", "--auth", wskprops.authKey) ++ wskprops.overrides, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include(s"'${badpath}' must begin with '/'")
- }
-
- it should "reject an api commands with an invalid verb parameter" in {
- val badverb = "badverb"
-
- var rr = wsk.cli(Seq("api-experimental", "create", "/basepath", "/path", badverb, "action", "--auth", wskprops.authKey) ++ wskprops.overrides, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include(s"'${badverb}' is not a valid API verb. Valid values are:")
-
- rr = wsk.cli(Seq("api-experimental", "delete", "/basepath", "/path", badverb, "--auth", wskprops.authKey) ++ wskprops.overrides, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include(s"'${badverb}' is not a valid API verb. Valid values are:")
-
- rr = wsk.cli(Seq("api-experimental", "list", "/basepath", "/path", badverb, "--auth", wskprops.authKey) ++ wskprops.overrides, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include(s"'${badverb}' is not a valid API verb. Valid values are:")
- }
-
- it should "reject an api create command with an API name argument and an API name option" in {
- val apiName = "An API Name"
- val rr = wsk.cli(Seq("api-experimental", "create", apiName, "/path", "GET", "action", "-n", apiName, "--auth", wskprops.authKey) ++ wskprops.overrides, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include(s"An API name can only be specified once.")
- }
-
- it should "reject an api create command that specifies a nonexistent configuration file" in {
- val configfile = "/nonexistent/file"
- val rr = wsk.cli(Seq("api-experimental", "create", "-c", configfile, "--auth", wskprops.authKey) ++ wskprops.overrides, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include(s"Error reading swagger file '${configfile}':")
- }
-
- it should "reject an api create command specifying a non-JSON configuration file" in {
- val file = File.createTempFile("api.json", ".txt")
- file.deleteOnExit()
- val filename = file.getAbsolutePath()
-
- val bw = new BufferedWriter(new FileWriter(file))
- bw.write("a=A")
- bw.close()
-
- val rr = wsk.cli(Seq("api-experimental", "create", "-c", filename, "--auth", wskprops.authKey) ++ wskprops.overrides, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include(s"Error parsing swagger file '${filename}':")
- }
-
- it should "reject an api create command specifying a non-swagger JSON configuration file" in {
- val file = File.createTempFile("api.json", ".txt")
- file.deleteOnExit()
- val filename = file.getAbsolutePath()
-
- val bw = new BufferedWriter(new FileWriter(file))
- bw.write("""|{
- | "swagger": "2.0",
- | "info": {
- | "title": "My API",
- | "version": "1.0.0"
- | },
- | "BADbasePath": "/bp",
- | "paths": {
- | "/rp": {
- | "get":{}
- | }
- | }
- |}""".stripMargin)
- bw.close()
-
- val rr = wsk.cli(Seq("api-experimental", "create", "-c", filename, "--auth", wskprops.authKey) ++ wskprops.overrides, expectedExitCode = ANY_ERROR_EXIT)
- rr.stderr should include(s"Swagger file is invalid (missing basePath, info, paths, or swagger fields")
- }
-
behavior of "Wsk entity list formatting"
it should "create, and list a package with a long name" in withAssetCleaner(wskprops) {
@@ -1186,13 +1105,13 @@ class WskBasicUsageTests
val invalidShared = s"Cannot use value '$invalidArg' for shared"
val entityNameMsg = s"An entity name, '$invalidArg', was provided instead of a namespace. Valid namespaces are of the following format: /NAMESPACE."
val invalidArgs = Seq(
- (Seq("api-experimental", "create"), s"${tooFewArgsMsg} ${apiCreateReqMsg}"),
- (Seq("api-experimental", "create", "/basepath", "/path", "GET", "action", invalidArg), s"${tooManyArgsMsg}${invalidArg}. ${apiCreateReqMsg}"),
- (Seq("api-experimental", "get"), s"${tooFewArgsMsg} ${apiGetReqMsg}"),
- (Seq("api-experimental", "get", "/basepath", invalidArg), s"${tooManyArgsMsg}${invalidArg}. ${apiGetReqMsg}"),
- (Seq("api-experimental", "delete"), s"${tooFewArgsMsg} ${apiDeleteReqMsg}"),
- (Seq("api-experimental", "delete", "/basepath", "/path", "GET", invalidArg), s"${tooManyArgsMsg}${invalidArg}. ${apiDeleteReqMsg}"),
- (Seq("api-experimental", "list", "/basepath", "/path", "GET", invalidArg), s"${tooManyArgsMsg}${invalidArg}. ${apiListReqMsg}"),
+ (Seq("api", "create"), s"${tooFewArgsMsg} ${apiCreateReqMsg}"),
+ (Seq("api", "create", "/basepath", "/path", "GET", "action", invalidArg), s"${tooManyArgsMsg}${invalidArg}. ${apiCreateReqMsg}"),
+ (Seq("api", "get"), s"${tooFewArgsMsg} ${apiGetReqMsg}"),
+ (Seq("api", "get", "/basepath", invalidArg), s"${tooManyArgsMsg}${invalidArg}. ${apiGetReqMsg}"),
+ (Seq("api", "delete"), s"${tooFewArgsMsg} ${apiDeleteReqMsg}"),
+ (Seq("api", "delete", "/basepath", "/path", "GET", invalidArg), s"${tooManyArgsMsg}${invalidArg}. ${apiDeleteReqMsg}"),
+ (Seq("api", "list", "/basepath", "/path", "GET", invalidArg), s"${tooManyArgsMsg}${invalidArg}. ${apiListReqMsg}"),
(Seq("action", "create"), s"${tooFewArgsMsg} ${actionNameActionReqMsg}"),
(Seq("action", "create", "someAction"), s"${tooFewArgsMsg} ${actionNameActionReqMsg}"),
(Seq("action", "create", "actionName", "artifactName", invalidArg), s"${tooManyArgsMsg}${invalidArg}."),
diff --git a/tools/cli/go-whisk-cli/commands/api.go b/tools/cli/go-whisk-cli/commands/api.go
index f4d0c37..6659e9c 100644
--- a/tools/cli/go-whisk-cli/commands/api.go
+++ b/tools/cli/go-whisk-cli/commands/api.go
@@ -43,664 +43,12 @@ const (
formatOptionJson = "json"
)
-//////////////
-// Commands //
-//////////////
-
-var apiExperimentalCmd = &cobra.Command{
- Use: "api-experimental",
- Short: wski18n.T("work with APIs (experimental)"),
-}
-
-var apiCmd = &cobra.Command{
- Use: "api",
- Short: wski18n.T("work with APIs"),
-}
-
-var apiCreateCmd = &cobra.Command{
- Use: "create ([BASE_PATH] API_PATH API_VERB ACTION] | --config-file CFG_FILE) ",
- Short: wski18n.T("create a new API"),
- SilenceUsage: true,
- SilenceErrors: true,
- PreRunE: setupClientConfig,
- RunE: func(cmd *cobra.Command, args []string) error {
-
- var api *whisk.Api
- var err error
-
- if (len(args) == 0 && flags.api.configfile == "") {
- whisk.Debug(whisk.DbgError, "No swagger file and no arguments\n")
- errMsg := wski18n.T("Invalid argument(s). Specify a swagger file or specify an API base path with an API path, an API verb, and an action name.")
- whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXITCODE_ERR_GENERAL,
- whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
- return whiskErr
- } else if (len(args) == 0 && flags.api.configfile != "") {
- api, err = parseSwaggerApi()
- if err != nil {
- whisk.Debug(whisk.DbgError, "parseSwaggerApi() error: %s\n", err)
- errMsg := wski18n.T("Unable to parse swagger file: {{.err}}", map[string]interface{}{"err": err})
- whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXITCODE_ERR_GENERAL,
- whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
- return whiskErr
- }
- } else {
- if whiskErr := checkArgs(args, 3, 4, "Api create",
- wski18n.T("Specify a swagger file or specify an API base path with an API path, an API verb, and an action name.")); whiskErr != nil {
- return whiskErr
- }
- api, err = parseApi(cmd, args)
- if err != nil {
- whisk.Debug(whisk.DbgError, "parseApi(%s, %s) error: %s\n", cmd, args, err)
- errMsg := wski18n.T("Unable to parse api command arguments: {{.err}}",
- map[string]interface{}{"err": err})
- whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXITCODE_ERR_GENERAL,
- whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
- return whiskErr
- }
- }
-
- apiCreateReq := new(whisk.ApiCreateRequest)
- apiCreateReq.ApiDoc = api
- apiCreateReqOptions := new(whisk.ApiCreateRequestOptions)
- retApi, _, err := client.Apis.Insert(apiCreateReq, apiCreateReqOptions, whisk.DoNotOverwrite)
- if err != nil {
- whisk.Debug(whisk.DbgError, "client.Apis.Insert(%#v, false) error: %s\n", api, err)
- errMsg := wski18n.T("Unable to create API: {{.err}}", map[string]interface{}{"err": err})
- whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXITCODE_ERR_NETWORK,
- whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
- return whiskErr
- }
-
- if (api.Swagger == "") {
- baseUrl := retApi.BaseUrl
- fmt.Fprintf(color.Output,
- wski18n.T("{{.ok}} created API {{.path}} {{.verb}} for action {{.name}}\n{{.fullpath}}\n",
- map[string]interface{}{
- "ok": color.GreenString("ok:"),
- "path": strings.TrimSuffix(api.GatewayBasePath, "/")+api.GatewayRelPath,
- "verb": api.GatewayMethod,
- "name": boldString("/"+api.Action.Namespace+"/"+api.Action.Name),
- "fullpath": strings.TrimSuffix(baseUrl, "/")+api.GatewayRelPath,
- }))
- } else {
- whisk.Debug(whisk.DbgInfo, "Processing swagger based create API response\n")
- baseUrl := retApi.BaseUrl
- for path, _ := range retApi.Swagger.Paths {
- managedUrl := strings.TrimSuffix(baseUrl, "/")+path
- whisk.Debug(whisk.DbgInfo, "Managed path: %s\n",managedUrl)
- for op, opv := range retApi.Swagger.Paths[path] {
- whisk.Debug(whisk.DbgInfo, "Path operation: %s\n", op)
- fmt.Fprintf(color.Output,
- wski18n.T("{{.ok}} created API {{.path}} {{.verb}} for action {{.name}}\n{{.fullpath}}\n",
- map[string]interface{}{
- "ok": color.GreenString("ok:"),
- "path": path,
- "verb": op,
- "name": boldString(opv.XOpenWhisk.ActionName),
- "fullpath": managedUrl,
- }))
- }
- }
- }
-
-
- return nil
- },
-}
-
-//var apiUpdateCmd = &cobra.Command{
-// Use: "update API_PATH API_VERB ACTION",
-// Short: wski18n.T("update an existing API"),
-// SilenceUsage: true,
-// SilenceErrors: true,
-// PreRunE: setupClientConfig,
-// RunE: func(cmd *cobra.Command, args []string) error {
-//
-// if whiskErr := checkArgs(args, 3, 3, "Api update",
-// wski18n.T("An API path, an API verb, and an action name are required.")); whiskErr != nil {
-// return whiskErr
-// }
-//
-// api, err := parseApi(cmd, args)
-// if err != nil {
-// whisk.Debug(whisk.DbgError, "parseApi(%s, %s) error: %s\n", cmd, args, err)
-// errMsg := wski18n.T("Unable to parse API command arguments: {{.err}}", map[string]interface{}{"err": err})
-// whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXITCODE_ERR_GENERAL,
-// whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
-// return whiskErr
-// }
-// sendApi := new(whisk.ApiCreateRequest)
-// sendApi.ApiDoc = api
-//
-// retApi, _, err := client.Apis.Insert(sendApi, true)
-// if err != nil {
-// whisk.Debug(whisk.DbgError, "client.Apis.Insert(%#v, %t, false) error: %s\n", api, err)
-// errMsg := wski18n.T("Unable to update API: {{.err}}", map[string]interface{}{"err": err})
-// whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXITCODE_ERR_NETWORK,
-// whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
-// return whiskErr
-// }
-//
-// fmt.Fprintf(color.Output,
-// wski18n.T("{{.ok}} updated API {{.path}} {{.verb}} for action {{.name}}\n{{.fullpath}}\n",
-// map[string]interface{}{
-// "ok": color.GreenString("ok:"),
-// "path": api.GatewayRelPath,
-// "verb": api.GatewayMethod,
-// "name": boldString("/"+api.Action.Name),
-// "fullpath": getManagedUrl(retApi, api.GatewayRelPath, api.GatewayMethod),
-// }))
-// return nil
-// },
-//}
-
-var apiGetCmd = &cobra.Command{
- Use: "get BASE_PATH | API_NAME",
- Short: wski18n.T("get API details"),
- SilenceUsage: true,
- SilenceErrors: true,
- PreRunE: setupClientConfig,
- RunE: func(cmd *cobra.Command, args []string) error {
- var err error
- var isBasePathArg bool = true
-
- if whiskErr := checkArgs(args, 1, 1, "Api get",
- wski18n.T("An API base path or API name is required.")); whiskErr != nil {
- return whiskErr
- }
-
- apiGetReq := new(whisk.ApiGetRequest)
- apiGetReqOptions := new(whisk.ApiGetRequestOptions)
- apiGetReqOptions.ApiBasePath = args[0]
- retApi, _, err := client.Apis.Get(apiGetReq, apiGetReqOptions)
- if err != nil {
- whisk.Debug(whisk.DbgError, "client.Apis.Get(%#v, %#v) error: %s\n", apiGetReq, apiGetReqOptions, err)
- errMsg := wski18n.T("Unable to get API '{{.name}}': {{.err}}", map[string]interface{}{"name": args[0], "err": err})
- whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXITCODE_ERR_GENERAL,
- whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
- return whiskErr
- }
- whisk.Debug(whisk.DbgInfo, "client.Apis.Get returned: %#v\n", retApi)
-
- var displayResult interface{} = nil
- if (flags.common.detail) {
- if (retApi.Apis != nil && len(retApi.Apis) > 0 &&
- retApi.Apis[0].ApiValue != nil) {
- displayResult = retApi.Apis[0].ApiValue
- } else {
- whisk.Debug(whisk.DbgError, "No result object returned\n")
- }
- } else {
- if (retApi.Apis != nil && len(retApi.Apis) > 0 &&
- retApi.Apis[0].ApiValue != nil &&
- retApi.Apis[0].ApiValue.Swagger != nil) {
- displayResult = retApi.Apis[0].ApiValue.Swagger
- } else {
- whisk.Debug(whisk.DbgError, "No swagger returned\n")
- }
- }
- if (displayResult == nil) {
- var errMsg string
- if (isBasePathArg) {
- errMsg = wski18n.T("API does not exist for basepath {{.basepath}}",
- map[string]interface{}{"basepath": args[0]})
- } else {
- errMsg = wski18n.T("API does not exist for API name {{.apiname}}",
- map[string]interface{}{"apiname": args[0]})
- }
-
- whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXITCODE_ERR_GENERAL,
- whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
- return whiskErr
- }
- printJSON(displayResult)
-
- return nil
- },
-}
-
-var apiDeleteCmd = &cobra.Command{
- Use: "delete BASE_PATH | API_NAME [API_PATH [API_VERB]]",
- Short: wski18n.T("delete an API"),
- SilenceUsage: true,
- SilenceErrors: true,
- PreRunE: setupClientConfig,
- RunE: func(cmd *cobra.Command, args []string) error {
- if whiskErr := checkArgs(args, 1, 3, "Api delete",
- wski18n.T("An API base path or API name is required. An optional API relative path and operation may also be provided.")); whiskErr != nil {
- return whiskErr
- }
-
- apiDeleteReq := new(whisk.ApiDeleteRequest)
- apiDeleteReqOptions := new(whisk.ApiDeleteRequestOptions)
- // Is the argument a basepath (must start with /) or an API name
- if _, ok := isValidBasepath(args[0]); !ok {
- whisk.Debug(whisk.DbgInfo, "Treating '%s' as an API name; as it does not begin with '/'\n", args[0])
- apiDeleteReqOptions.ApiBasePath = args[0]
- } else {
- apiDeleteReqOptions.ApiBasePath = args[0]
- }
-
- if (len(args) > 1) {
- // Is the API path valid?
- if whiskErr, ok := isValidRelpath(args[1]); !ok {
- return whiskErr
- }
- apiDeleteReqOptions.ApiRelPath = args[1]
- }
- if (len(args) > 2) {
- // Is the API verb valid?
- if whiskErr, ok := IsValidApiVerb(args[2]); !ok {
- return whiskErr
- }
- apiDeleteReqOptions.ApiVerb = strings.ToUpper(args[2])
- }
-
- _, err := client.Apis.Delete(apiDeleteReq, apiDeleteReqOptions)
- if err != nil {
- whisk.Debug(whisk.DbgError, "client.Apis.Delete(%#v, %#v) error: %s\n", apiDeleteReq, apiDeleteReqOptions, err)
- errMsg := wski18n.T("Unable to delete API: {{.err}}", map[string]interface{}{"err": err})
- whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXITCODE_ERR_GENERAL,
- whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
- return whiskErr
- }
-
- if (len(args) == 1) {
- fmt.Fprintf(color.Output,
- wski18n.T("{{.ok}} deleted API {{.basepath}}\n",
- map[string]interface{}{
- "ok": color.GreenString("ok:"),
- "basepath": apiDeleteReqOptions.ApiBasePath,
- }))
- } else if (len(args) == 2 ) {
- fmt.Fprintf(color.Output,
- wski18n.T("{{.ok}} deleted {{.path}} from {{.basepath}}\n",
- map[string]interface{}{
- "ok": color.GreenString("ok:"),
- "path": apiDeleteReqOptions.ApiRelPath,
- "basepath": apiDeleteReqOptions.ApiBasePath,
- }))
- } else {
- fmt.Fprintf(color.Output,
- wski18n.T("{{.ok}} deleted {{.path}} {{.verb}} from {{.basepath}}\n",
- map[string]interface{}{
- "ok": color.GreenString("ok:"),
- "path": apiDeleteReqOptions.ApiRelPath,
- "verb": apiDeleteReqOptions.ApiVerb,
- "basepath": apiDeleteReqOptions.ApiBasePath,
- }))
- }
-
- return nil
- },
-}
-
-var fmtString = "%-30s %7s %20s %s\n"
-var apiListCmd = &cobra.Command{
- Use: "list [[BASE_PATH | API_NAME] [API_PATH [API_VERB]]",
- Short: wski18n.T("list APIs"),
- SilenceUsage: true,
- SilenceErrors: true,
- PreRunE: setupClientConfig,
- RunE: func(cmd *cobra.Command, args []string) error {
- var err error
- var retApiList *whisk.ApiListResponse
- var retApi *whisk.ApiGetResponse
- var retApiArray *whisk.RetApiArray
-
- if whiskErr := checkArgs(args, 0, 3, "Api list",
- wski18n.T("Optional parameters are: API base path (or API name), API relative path and operation.")); whiskErr != nil {
- return whiskErr
- }
-
- // Get API request body
- apiGetReq := new(whisk.ApiGetRequest)
- apiGetReq.Namespace = client.Config.Namespace
-
- // Get API request options
- apiGetReqOptions := new(whisk.ApiGetRequestOptions)
-
- // List API request query parameters
- apiListReqOptions := new(whisk.ApiListRequestOptions)
- apiListReqOptions.Limit = flags.common.limit
- apiListReqOptions.Skip = flags.common.skip
-
- if (len(args) == 0) {
- retApiList, _, err = client.Apis.List(apiListReqOptions)
- if err != nil {
- whisk.Debug(whisk.DbgError, "client.Apis.List(%#v) error: %s\n", apiListReqOptions, err)
- errMsg := wski18n.T("Unable to obtain the API list: {{.err}}", map[string]interface{}{"err": err})
- whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXITCODE_ERR_GENERAL,
- whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
- return whiskErr
- }
- whisk.Debug(whisk.DbgInfo, "client.Apis.List returned: %#v (%+v)\n", retApiList, retApiList)
- // Cast to a common type to allow for code to print out apilist response or apiget response
- retApiArray = (*whisk.RetApiArray)(retApiList)
- } else {
- // The first argument is either a basepath (must start with /) or an API name
- apiGetReqOptions.ApiBasePath = args[0]
- if (len(args) > 1) {
- // Is the API path valid?
- if whiskErr, ok := isValidRelpath(args[1]); !ok {
- return whiskErr
- }
- apiGetReqOptions.ApiRelPath = args[1]
- }
- if (len(args) > 2) {
- // Is the API verb valid?
- if whiskErr, ok := IsValidApiVerb(args[2]); !ok {
- return whiskErr
- }
- apiGetReqOptions.ApiVerb = strings.ToUpper(args[2])
- }
-
- retApi, _, err = client.Apis.Get(apiGetReq, apiGetReqOptions)
- if err != nil {
- whisk.Debug(whisk.DbgError, "client.Apis.Get(%#v, %#v) error: %s\n", apiGetReq, apiGetReqOptions, err)
- errMsg := wski18n.T("Unable to obtain the API list: {{.err}}", map[string]interface{}{"err": err})
- whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXITCODE_ERR_GENERAL,
- whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
- return whiskErr
- }
- whisk.Debug(whisk.DbgInfo, "client.Apis.Get returned: %#v\n", retApi)
- // Cast to a common type to allow for code to print out apilist response or apiget response
- retApiArray = (*whisk.RetApiArray)(retApi)
- }
-
- // Display the APIs - applying any specified filtering
- if (flags.common.full) {
- fmt.Fprintf(color.Output,
- wski18n.T("{{.ok}} APIs\n",
- map[string]interface{}{
- "ok": color.GreenString("ok:"),
- }))
-
- for i:=0; i<len(retApiArray.Apis); i++ {
- printFilteredListApi(retApiArray.Apis[i].ApiValue, (*whisk.ApiOptions)(apiGetReqOptions))
- }
- } else {
- // Dynamically create the output format string based on the maximum size of the
- // fully qualified action name and the API Name.
- maxActionNameSize := min(40, max(len("Action"), getLargestActionNameSize(retApiArray, (*whisk.ApiOptions)(apiGetReqOptions))))
- maxApiNameSize := min(30, max(len("API Name"), getLargestApiNameSize(retApiArray, (*whisk.ApiOptions)(apiGetReqOptions))))
- fmtString = "%-"+strconv.Itoa(maxActionNameSize)+"s %7s %"+strconv.Itoa(maxApiNameSize+1)+"s %s\n"
-
- fmt.Fprintf(color.Output,
- wski18n.T("{{.ok}} APIs\n",
- map[string]interface{}{
- "ok": color.GreenString("ok:"),
- }))
- fmt.Printf(fmtString, "Action", "Verb", "API Name", "URL")
-
- for i:=0; i<len(retApiArray.Apis); i++ {
- printFilteredListRow(retApiArray.Apis[i].ApiValue, (*whisk.ApiOptions)(apiGetReqOptions), maxActionNameSize, maxApiNameSize)
- }
- }
-
- return nil
- },
-}
-
-/*
- * Takes an API object (containing one more more single basepath/relpath/operation triplets)
- * and some filtering configuration. For each API endpoint matching the filtering criteria, display
- * each endpoint's configuration - one line per configuration property (action name, verb, api name, api gw url)
- */
-func printFilteredListApi(resultApi *whisk.RetApi, api *whisk.ApiOptions) {
- baseUrl := strings.TrimSuffix(resultApi.BaseUrl, "/")
- apiName := resultApi.Swagger.Info.Title
- basePath := resultApi.Swagger.BasePath
- if (resultApi.Swagger != nil && resultApi.Swagger.Paths != nil) {
- for path, _ := range resultApi.Swagger.Paths {
- whisk.Debug(whisk.DbgInfo, "apiGetCmd: comparing api relpath: %s\n", path)
- if ( len(api.ApiRelPath) == 0 || path == api.ApiRelPath) {
- whisk.Debug(whisk.DbgInfo, "apiGetCmd: relpath matches\n")
- for op, opv := range resultApi.Swagger.Paths[path] {
- whisk.Debug(whisk.DbgInfo, "apiGetCmd: comparing operation: '%s'\n", op)
- if ( len(api.ApiVerb) == 0 || strings.ToLower(op) == strings.ToLower(api.ApiVerb)) {
- whisk.Debug(whisk.DbgInfo, "apiGetCmd: operation matches: %#v\n", opv)
- var actionName = "/"+opv.XOpenWhisk.Namespace+"/"+opv.XOpenWhisk.ActionName
- fmt.Printf("%s: %s\n", wski18n.T("Action"), actionName)
- fmt.Printf(" %s: %s\n", wski18n.T("API Name"), apiName)
- fmt.Printf(" %s: %s\n", wski18n.T("Base path"), basePath)
- fmt.Printf(" %s: %s\n", wski18n.T("Path"), path)
- fmt.Printf(" %s: %s\n", wski18n.T("Verb"), op)
- fmt.Printf(" %s: %s\n", wski18n.T("URL"), baseUrl+path)
- }
- }
- }
- }
- }
-}
-
-/*
- * Takes an API object (containing one more more single basepath/relpath/operation triplets)
- * and some filtering configuration. For each API matching the filtering criteria, display the API
- * on a single line (action name, verb, api name, api gw url).
- *
- * NOTE: Large action name and api name value will be truncated by their associated max size parameters.
- */
-func printFilteredListRow(resultApi *whisk.RetApi, api *whisk.ApiOptions, maxActionNameSize int, maxApiNameSize int) {
- baseUrl := strings.TrimSuffix(resultApi.BaseUrl, "/")
- apiName := resultApi.Swagger.Info.Title
- if (resultApi.Swagger != nil && resultApi.Swagger.Paths != nil) {
- for path, _ := range resultApi.Swagger.Paths {
- whisk.Debug(whisk.DbgInfo, "apiGetCmd: comparing api relpath: %s\n", path)
- if ( len(api.ApiRelPath) == 0 || path == api.ApiRelPath) {
- whisk.Debug(whisk.DbgInfo, "apiGetCmd: relpath matches\n")
- for op, opv := range resultApi.Swagger.Paths[path] {
- whisk.Debug(whisk.DbgInfo, "apiGetCmd: comparing operation: '%s'\n", op)
- if ( len(api.ApiVerb) == 0 || strings.ToLower(op) == strings.ToLower(api.ApiVerb)) {
- whisk.Debug(whisk.DbgInfo, "apiGetCmd: operation matches: %#v\n", opv)
- var actionName = "/"+opv.XOpenWhisk.Namespace+"/"+opv.XOpenWhisk.ActionName
- fmt.Printf(fmtString,
- actionName[0 : min(len(actionName), maxActionNameSize)],
- op,
- apiName[0 : min(len(apiName), maxApiNameSize)],
- baseUrl+path)
- }
- }
- }
- }
- }
-}
-
-func getLargestActionNameSize(retApiArray *whisk.RetApiArray, api *whisk.ApiOptions) int {
- var maxNameSize = 0
- for i:=0; i<len(retApiArray.Apis); i++ {
- var resultApi = retApiArray.Apis[i].ApiValue
- if (resultApi.Swagger != nil && resultApi.Swagger.Paths != nil) {
- for path, _ := range resultApi.Swagger.Paths {
- whisk.Debug(whisk.DbgInfo, "getLargestActionNameSize: comparing api relpath: %s\n", path)
- if ( len(api.ApiRelPath) == 0 || path == api.ApiRelPath) {
- whisk.Debug(whisk.DbgInfo, "getLargestActionNameSize: relpath matches\n")
- for op, opv := range resultApi.Swagger.Paths[path] {
- whisk.Debug(whisk.DbgInfo, "getLargestActionNameSize: comparing operation: '%s'\n", op)
- if ( len(api.ApiVerb) == 0 || strings.ToLower(op) == strings.ToLower(api.ApiVerb)) {
- whisk.Debug(whisk.DbgInfo, "getLargestActionNameSize: operation matches: %#v\n", opv)
- var fullActionName = "/"+opv.XOpenWhisk.Namespace+"/"+opv.XOpenWhisk.ActionName
- if (len(fullActionName) > maxNameSize) {
- maxNameSize = len(fullActionName)
- }
- }
- }
- }
- }
- }
- }
- return maxNameSize
-}
-
-func getLargestApiNameSize(retApiArray *whisk.RetApiArray, api *whisk.ApiOptions) int {
- var maxNameSize = 0
- for i:=0; i<len(retApiArray.Apis); i++ {
- var resultApi = retApiArray.Apis[i].ApiValue
- apiName := resultApi.Swagger.Info.Title
- if (resultApi.Swagger != nil && resultApi.Swagger.Paths != nil) {
- for path, _ := range resultApi.Swagger.Paths {
- whisk.Debug(whisk.DbgInfo, "getLargestActionNameSize: comparing api relpath: %s\n", path)
- if ( len(api.ApiRelPath) == 0 || path == api.ApiRelPath) {
- whisk.Debug(whisk.DbgInfo, "getLargestActionNameSize: relpath matches\n")
- for op, opv := range resultApi.Swagger.Paths[path] {
- whisk.Debug(whisk.DbgInfo, "getLargestActionNameSize: comparing operation: '%s'\n", op)
- if ( len(api.ApiVerb) == 0 || strings.ToLower(op) == strings.ToLower(api.ApiVerb)) {
- whisk.Debug(whisk.DbgInfo, "getLargestActionNameSize: operation matches: %#v\n", opv)
- if (len(apiName) > maxNameSize) {
- maxNameSize = len(apiName)
- }
- }
- }
- }
- }
- }
- }
- return maxNameSize
-}
-
-/*
- * if # args = 4
- * args[0] = API base path
- * args[0] = API relative path
- * args[1] = API verb
- * args[2] = Optional. Action name (may or may not be qualified with namespace and package name)
- *
- * if # args = 3
- * args[0] = API relative path
- * args[1] = API verb
- * args[2] = Optional. Action name (may or may not be qualified with namespace and package name)
- */
-func parseApi(cmd *cobra.Command, args []string) (*whisk.Api, error) {
- var err error
- var basepath string = "/"
- var apiname string
- var basepathArgIsApiName = false;
-
- api := new(whisk.Api)
-
- if (len(args) > 3) {
- // Is the argument a basepath (must start with /) or an API name
- if _, ok := isValidBasepath(args[0]); !ok {
- whisk.Debug(whisk.DbgInfo, "Treating '%s' as an API name; as it does not begin with '/'\n", args[0])
- basepathArgIsApiName = true;
- }
- basepath = args[0]
-
- // Shift the args so the remaining code works with or without the explicit base path arg
- args = args[1:]
- }
-
- // Is the API path valid?
- if (len(args) > 0) {
- if whiskErr, ok := isValidRelpath(args[0]); !ok {
- return nil, whiskErr
- }
- api.GatewayRelPath = args[0] // Maintain case as URLs may be case-sensitive
- }
-
- // Is the API verb valid?
- if (len(args) > 1) {
- if whiskErr, ok := IsValidApiVerb(args[1]); !ok {
- return nil, whiskErr
- }
- api.GatewayMethod = strings.ToUpper(args[1])
- }
-
- // Is the specified action name valid?
- var qualifiedName QualifiedName
- if (len(args) == 3) {
- if qualifiedName, err = parseQualifiedName(args[2]); err != nil {
- return nil, parseQualifiedNameError(args[2], err)
- }
-
- if (qualifiedName.entityName == "") {
- whisk.Debug(whisk.DbgError, "Action name '%s' is invalid\n", args[2])
- errMsg := wski18n.T("'{{.name}}' is not a valid action name.", map[string]interface{}{"name": args[2]})
- whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXITCODE_ERR_GENERAL,
- whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
- return nil, whiskErr
- }
- }
-
- if ( len(flags.api.apiname) > 0 ) {
- if (basepathArgIsApiName) {
- // Specifying API name as argument AND as a --apiname option value is invalid
- whisk.Debug(whisk.DbgError, "API is specified as an argument '%s' and as a flag '%s'\n", basepath, flags.api.apiname)
- errMsg := wski18n.T("An API name can only be specified once.")
- whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXITCODE_ERR_GENERAL,
- whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
- return nil, whiskErr
- }
- apiname = flags.api.apiname
- }
-
- api.Namespace = client.Config.Namespace
- api.Action = new(whisk.ApiAction)
- api.Action.BackendUrl = "https://" + client.Config.Host + "/api/v1/namespaces/" + qualifiedName.namespace + "/actions/" + qualifiedName.entityName
- api.Action.BackendMethod = "POST"
- api.Action.Name = qualifiedName.entityName
- api.Action.Namespace = qualifiedName.namespace
- api.Action.Auth = client.Config.AuthToken
- api.ApiName = apiname
- api.GatewayBasePath = basepath
- if (!basepathArgIsApiName) { api.Id = "API:"+api.Namespace+":"+api.GatewayBasePath }
-
- whisk.Debug(whisk.DbgInfo, "Parsed api struct: %#v\n", api)
- return api, nil
+var apiCmd = &cobra.Command{
+ Use: "api",
+ Short: wski18n.T("work with APIs"),
}
-func parseSwaggerApi() (*whisk.Api, error) {
- // Test is for completeness, but this situation should only arise due to an internal error
- if ( len(flags.api.configfile) == 0 ) {
- whisk.Debug(whisk.DbgError, "No swagger file is specified\n")
- errMsg := wski18n.T("A configuration file was not specified.")
- whiskErr := whisk.MakeWskError(errors.New(errMsg),whisk.EXITCODE_ERR_GENERAL,
- whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
- return nil, whiskErr
- }
-
- swagger, err:= readFile(flags.api.configfile)
- if ( err != nil ) {
- whisk.Debug(whisk.DbgError, "readFile(%s) error: %s\n", flags.api.configfile, err)
- errMsg := wski18n.T("Error reading swagger file '{{.name}}': {{.err}}",
- map[string]interface{}{"name": flags.api.configfile, "err": err})
- whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXITCODE_ERR_GENERAL,
- whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
- return nil, whiskErr
- }
-
- // Parse the JSON into a swagger object
- swaggerObj := new(whisk.ApiSwagger)
- err = json.Unmarshal([]byte(swagger), swaggerObj)
- if ( err != nil ) {
- whisk.Debug(whisk.DbgError, "JSON parse of `%s' error: %s\n", flags.api.configfile, err)
- errMsg := wski18n.T("Error parsing swagger file '{{.name}}': {{.err}}",
- map[string]interface{}{"name": flags.api.configfile, "err": err})
- whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXITCODE_ERR_GENERAL,
- whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
- return nil, whiskErr
- }
- if (swaggerObj.BasePath == "" || swaggerObj.SwaggerName == "" || swaggerObj.Info == nil || swaggerObj.Paths == nil) {
- whisk.Debug(whisk.DbgError, "Swagger file is invalid.\n", flags.api.configfile, err)
- errMsg := wski18n.T("Swagger file is invalid (missing basePath, info, paths, or swagger fields)")
- whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXITCODE_ERR_GENERAL,
- whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
- return nil, whiskErr
- }
- if _, ok := isValidBasepath(swaggerObj.BasePath); !ok {
- whisk.Debug(whisk.DbgError, "Swagger file basePath is invalid.\n", flags.api.configfile, err)
- errMsg := wski18n.T("Swagger file basePath must start with a leading slash (/)")
- whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXITCODE_ERR_GENERAL,
- whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
- return nil, whiskErr
- }
-
- api := new(whisk.Api)
- api.Namespace = client.Config.Namespace
- api.Swagger = swagger
-
- return api, nil
-}
+var fmtString = "%-30s %7s %20s %s\n"
func IsValidApiVerb(verb string) (error, bool) {
// Is the API verb valid?
@@ -768,10 +116,10 @@ func getManagedUrl(api *whisk.RetApi, relpath string, operation string) (url str
return url
}
-/////////////
-// V2 Cmds //
-/////////////
-var apiCreateCmdV2 = &cobra.Command{
+//////////////
+// Commands //
+//////////////
+var apiCreateCmd = &cobra.Command{
Use: "create ([BASE_PATH] API_PATH API_VERB ACTION] | --config-file CFG_FILE) ",
Short: wski18n.T("create a new API"),
SilenceUsage: true,
@@ -789,7 +137,7 @@ var apiCreateCmdV2 = &cobra.Command{
whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
return whiskErr
} else if (len(args) == 0 && flags.api.configfile != "") {
- api, err = parseSwaggerApiV2()
+ api, err = parseSwaggerApi()
if err != nil {
whisk.Debug(whisk.DbgError, "parseSwaggerApi() error: %s\n", err)
errMsg := wski18n.T("Unable to parse swagger file: {{.err}}", map[string]interface{}{"err": err})
@@ -802,9 +150,9 @@ var apiCreateCmdV2 = &cobra.Command{
wski18n.T("Specify a swagger file or specify an API base path with an API path, an API verb, and an action name.")); whiskErr != nil {
return whiskErr
}
- api, qname, err = parseApiV2(cmd, args)
+ api, qname, err = parseApi(cmd, args)
if err != nil {
- whisk.Debug(whisk.DbgError, "parseApiV2(%s, %s) error: %s\n", cmd, args, err)
+ whisk.Debug(whisk.DbgError, "parseApi(%s, %s) error: %s\n", cmd, args, err)
errMsg := wski18n.T("Unable to parse api command arguments: {{.err}}",
map[string]interface{}{"err": err})
whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXITCODE_ERR_GENERAL,
@@ -835,9 +183,9 @@ var apiCreateCmdV2 = &cobra.Command{
whisk.Debug(whisk.DbgInfo, "AccessToken: %s\nSpaceGuid: %s\nResponsType: %s",
apiCreateReqOptions.AccessToken, apiCreateReqOptions.SpaceGuid, apiCreateReqOptions.ResponseType)
- retApi, _, err := client.Apis.InsertV2(apiCreateReq, apiCreateReqOptions, whisk.DoNotOverwrite)
+ retApi, _, err := client.Apis.Insert(apiCreateReq, apiCreateReqOptions, whisk.DoNotOverwrite)
if err != nil {
- whisk.Debug(whisk.DbgError, "client.Apis.InsertV2(%#v, false) error: %s\n", api, err)
+ whisk.Debug(whisk.DbgError, "client.Apis.Insert(%#v, false) error: %s\n", api, err)
errMsg := wski18n.T("Unable to create API: {{.err}}", map[string]interface{}{"err": err})
whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXITCODE_ERR_GENERAL,
whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
@@ -901,7 +249,7 @@ var apiCreateCmdV2 = &cobra.Command{
},
}
-var apiGetCmdV2 = &cobra.Command{
+var apiGetCmd = &cobra.Command{
Use: "get BASE_PATH | API_NAME",
Short: wski18n.T("get API details"),
SilenceUsage: true,
@@ -935,15 +283,15 @@ var apiGetCmdV2 = &cobra.Command{
return err
}
- retApi, _, err := client.Apis.GetV2(apiGetReq, apiGetReqOptions)
+ retApi, _, err := client.Apis.Get(apiGetReq, apiGetReqOptions)
if err != nil {
- whisk.Debug(whisk.DbgError, "client.Apis.GetV2(%#v, %#v) error: %s\n", apiGetReq, apiGetReqOptions, err)
+ whisk.Debug(whisk.DbgError, "client.Apis.Get(%#v, %#v) error: %s\n", apiGetReq, apiGetReqOptions, err)
errMsg := wski18n.T("Unable to get API '{{.name}}': {{.err}}", map[string]interface{}{"name": args[0], "err": err})
whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXITCODE_ERR_GENERAL,
whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
return whiskErr
}
- whisk.Debug(whisk.DbgInfo, "client.Apis.GetV2 returned: %#v\n", retApi)
+ whisk.Debug(whisk.DbgInfo, "client.Apis.Get returned: %#v\n", retApi)
var displayResult interface{} = nil
if (flags.common.detail) {
@@ -999,7 +347,7 @@ var apiGetCmdV2 = &cobra.Command{
},
}
-var apiDeleteCmdV2 = &cobra.Command{
+var apiDeleteCmd = &cobra.Command{
Use: "delete BASE_PATH | API_NAME [API_PATH [API_VERB]]",
Short: wski18n.T("delete an API"),
SilenceUsage: true,
@@ -1045,9 +393,9 @@ var apiDeleteCmdV2 = &cobra.Command{
apiDeleteReqOptions.ApiVerb = strings.ToUpper(args[2])
}
- _, err = client.Apis.DeleteV2(apiDeleteReq, apiDeleteReqOptions)
+ _, err = client.Apis.Delete(apiDeleteReq, apiDeleteReqOptions)
if err != nil {
- whisk.Debug(whisk.DbgError, "client.Apis.DeleteV2(%#v, %#v) error: %s\n", apiDeleteReq, apiDeleteReqOptions, err)
+ whisk.Debug(whisk.DbgError, "client.Apis.Delete(%#v, %#v) error: %s\n", apiDeleteReq, apiDeleteReqOptions, err)
errMsg := wski18n.T("Unable to delete API: {{.err}}", map[string]interface{}{"err": err})
whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXITCODE_ERR_GENERAL,
whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
@@ -1084,7 +432,7 @@ var apiDeleteCmdV2 = &cobra.Command{
},
}
-var apiListCmdV2 = &cobra.Command{
+var apiListCmd = &cobra.Command{
Use: "list [[BASE_PATH | API_NAME] [API_PATH [API_VERB]]",
Short: wski18n.T("list APIs"),
SilenceUsage: true,
@@ -1092,9 +440,9 @@ var apiListCmdV2 = &cobra.Command{
PreRunE: setupClientConfig,
RunE: func(cmd *cobra.Command, args []string) error {
var err error
- var retApiList *whisk.ApiListResponseV2
- var retApi *whisk.ApiGetResponseV2
- var retApiArray *whisk.RetApiArrayV2
+ var retApiList *whisk.ApiListResponse
+ var retApi *whisk.ApiGetResponse
+ var retApiArray *whisk.RetApiArray
var apiPath string
var apiVerb string
@@ -1115,17 +463,17 @@ var apiListCmdV2 = &cobra.Command{
return err
}
- retApiList, _, err = client.Apis.ListV2(apiListReqOptions)
+ retApiList, _, err = client.Apis.List(apiListReqOptions)
if err != nil {
- whisk.Debug(whisk.DbgError, "client.Apis.ListV2(%#v) error: %s\n", apiListReqOptions, err)
+ whisk.Debug(whisk.DbgError, "client.Apis.List(%#v) error: %s\n", apiListReqOptions, err)
errMsg := wski18n.T("Unable to obtain the API list: {{.err}}", map[string]interface{}{"err": err})
whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXITCODE_ERR_GENERAL,
whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
return whiskErr
}
- whisk.Debug(whisk.DbgInfo, "client.Apis.ListV2 returned: %#v (%+v)\n", retApiList, retApiList)
+ whisk.Debug(whisk.DbgInfo, "client.Apis.List returned: %#v (%+v)\n", retApiList, retApiList)
// Cast to a common type to allow for code to print out apilist response or apiget response
- retApiArray = (*whisk.RetApiArrayV2)(retApiList)
+ retApiArray = (*whisk.RetApiArray)(retApiList)
} else {
// Get API request body
apiGetReq := new(whisk.ApiGetRequest)
@@ -1158,17 +506,17 @@ var apiListCmdV2 = &cobra.Command{
apiGetReqOptions.ApiVerb = apiVerb
}
- retApi, _, err = client.Apis.GetV2(apiGetReq, apiGetReqOptions)
+ retApi, _, err = client.Apis.Get(apiGetReq, apiGetReqOptions)
if err != nil {
- whisk.Debug(whisk.DbgError, "client.Apis.GetV2(%#v, %#v) error: %s\n", apiGetReq, apiGetReqOptions, err)
+ whisk.Debug(whisk.DbgError, "client.Apis.Get(%#v, %#v) error: %s\n", apiGetReq, apiGetReqOptions, err)
errMsg := wski18n.T("Unable to obtain the API list: {{.err}}", map[string]interface{}{"err": err})
whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXITCODE_ERR_GENERAL,
whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
return whiskErr
}
- whisk.Debug(whisk.DbgInfo, "client.Apis.GetV2 returned: %#v\n", retApi)
+ whisk.Debug(whisk.DbgInfo, "client.Apis.Get returned: %#v\n", retApi)
// Cast to a common type to allow for code to print out apilist response or apiget response
- retApiArray = (*whisk.RetApiArrayV2)(retApi)
+ retApiArray = (*whisk.RetApiArray)(retApi)
}
// Display the APIs - applying any specified filtering
@@ -1180,14 +528,14 @@ var apiListCmdV2 = &cobra.Command{
}))
for i:=0; i<len(retApiArray.Apis); i++ {
- printFilteredListApiV2(retApiArray.Apis[i].ApiValue, apiPath, apiVerb)
+ printFilteredListApi(retApiArray.Apis[i].ApiValue, apiPath, apiVerb)
}
} else {
if (len(retApiArray.Apis) > 0) {
// Dynamically create the output format string based on the maximum size of the
// fully qualified action name and the API Name.
- maxActionNameSize := min(40, max(len("Action"), getLargestActionNameSizeV2(retApiArray, apiPath, apiVerb)))
- maxApiNameSize := min(30, max(len("API Name"), getLargestApiNameSizeV2(retApiArray, apiPath, apiVerb)))
+ maxActionNameSize := min(40, max(len("Action"), getLargestActionNameSize(retApiArray, apiPath, apiVerb)))
+ maxApiNameSize := min(30, max(len("API Name"), getLargestApiNameSize(retApiArray, apiPath, apiVerb)))
fmtString = "%-"+strconv.Itoa(maxActionNameSize)+"s %7s %"+strconv.Itoa(maxApiNameSize+1)+"s %s\n"
fmt.Fprintf(color.Output,
wski18n.T("{{.ok}} APIs\n",
@@ -1196,7 +544,7 @@ var apiListCmdV2 = &cobra.Command{
}))
fmt.Printf(fmtString, "Action", "Verb", "API Name", "URL")
for i:=0; i<len(retApiArray.Apis); i++ {
- printFilteredListRowV2(retApiArray.Apis[i].ApiValue, apiPath, apiVerb, maxActionNameSize, maxApiNameSize)
+ printFilteredListRow(retApiArray.Apis[i].ApiValue, apiPath, apiVerb, maxActionNameSize, maxApiNameSize)
}
} else {
fmt.Fprintf(color.Output,
@@ -1217,19 +565,19 @@ var apiListCmdV2 = &cobra.Command{
* and some filtering configuration. For each API endpoint matching the filtering criteria, display
* each endpoint's configuration - one line per configuration property (action name, verb, api name, api gw url)
*/
-func printFilteredListApiV2(resultApi *whisk.RetApiV2, apiPath string, apiVerb string) {
+func printFilteredListApi(resultApi *whisk.RetApi, apiPath string, apiVerb string) {
baseUrl := strings.TrimSuffix(resultApi.BaseUrl, "/")
apiName := resultApi.Swagger.Info.Title
basePath := resultApi.Swagger.BasePath
if (resultApi.Swagger != nil && resultApi.Swagger.Paths != nil) {
for path, _ := range resultApi.Swagger.Paths {
- whisk.Debug(whisk.DbgInfo, "printFilteredListApiV2: comparing api relpath: %s\n", path)
+ whisk.Debug(whisk.DbgInfo, "printFilteredListApi: comparing api relpath: %s\n", path)
if ( len(apiPath) == 0 || path == apiPath) {
- whisk.Debug(whisk.DbgInfo, "printFilteredListApiV2: relpath matches\n")
+ whisk.Debug(whisk.DbgInfo, "printFilteredListApi: relpath matches\n")
for op, opv := range resultApi.Swagger.Paths[path] {
- whisk.Debug(whisk.DbgInfo, "printFilteredListApiV2: comparing operation: '%s'\n", op)
+ whisk.Debug(whisk.DbgInfo, "printFilteredListApi: comparing operation: '%s'\n", op)
if ( len(apiVerb) == 0 || strings.ToLower(op) == strings.ToLower(apiVerb)) {
- whisk.Debug(whisk.DbgInfo, "printFilteredListApiV2: operation matches: %#v\n", opv)
+ whisk.Debug(whisk.DbgInfo, "printFilteredListApi: operation matches: %#v\n", opv)
var actionName string
if (opv.XOpenWhisk == nil) {
actionName = ""
@@ -1258,18 +606,18 @@ func printFilteredListApiV2(resultApi *whisk.RetApiV2, apiPath string, apiVerb s
*
* NOTE: Large action name and api name value will be truncated by their associated max size parameters.
*/
-func printFilteredListRowV2(resultApi *whisk.RetApiV2, apiPath string, apiVerb string, maxActionNameSize int, maxApiNameSize int) {
+func printFilteredListRow(resultApi *whisk.RetApi, apiPath string, apiVerb string, maxActionNameSize int, maxApiNameSize int) {
baseUrl := strings.TrimSuffix(resultApi.BaseUrl, "/")
apiName := resultApi.Swagger.Info.Title
if (resultApi.Swagger != nil && resultApi.Swagger.Paths != nil) {
for path, _ := range resultApi.Swagger.Paths {
- whisk.Debug(whisk.DbgInfo, "printFilteredListRowV2: comparing api relpath: %s\n", path)
+ whisk.Debug(whisk.DbgInfo, "printFilteredListRow: comparing api relpath: %s\n", path)
if ( len(apiPath) == 0 || path == apiPath) {
- whisk.Debug(whisk.DbgInfo, "printFilteredListRowV2: relpath matches\n")
+ whisk.Debug(whisk.DbgInfo, "printFilteredListRow: relpath matches\n")
for op, opv := range resultApi.Swagger.Paths[path] {
- whisk.Debug(whisk.DbgInfo, "printFilteredListRowV2: comparing operation: '%s'\n", op)
+ whisk.Debug(whisk.DbgInfo, "printFilteredListRow: comparing operation: '%s'\n", op)
if ( len(apiVerb) == 0 || strings.ToLower(op) == strings.ToLower(apiVerb)) {
- whisk.Debug(whisk.DbgInfo, "printFilteredListRowV2: operation matches: %#v\n", opv)
+ whisk.Debug(whisk.DbgInfo, "printFilteredListRow: operation matches: %#v\n", opv)
var actionName string
if (opv.XOpenWhisk == nil) {
actionName = ""
@@ -1290,7 +638,7 @@ func printFilteredListRowV2(resultApi *whisk.RetApiV2, apiPath string, apiVerb s
}
}
-func getLargestActionNameSizeV2(retApiArray *whisk.RetApiArrayV2, apiPath string, apiVerb string) int {
+func getLargestActionNameSize(retApiArray *whisk.RetApiArray, apiPath string, apiVerb string) int {
var maxNameSize = 0
for i:=0; i<len(retApiArray.Apis); i++ {
var resultApi = retApiArray.Apis[i].ApiValue
@@ -1323,7 +671,7 @@ func getLargestActionNameSizeV2(retApiArray *whisk.RetApiArrayV2, apiPath string
return maxNameSize
}
-func getLargestApiNameSizeV2(retApiArray *whisk.RetApiArrayV2, apiPath string, apiVerb string) int {
+func getLargestApiNameSize(retApiArray *whisk.RetApiArray, apiPath string, apiVerb string) int {
var maxNameSize = 0
for i:=0; i<len(retApiArray.Apis); i++ {
var resultApi = retApiArray.Apis[i].ApiValue
@@ -1361,7 +709,7 @@ func getLargestApiNameSizeV2(retApiArray *whisk.RetApiArrayV2, apiPath string, a
* args[1] = API verb
* args[2] = Optional. Action name (may or may not be qualified with namespace and package name)
*/
-func parseApiV2(cmd *cobra.Command, args []string) (*whisk.Api, *QualifiedName, error) {
+func parseApi(cmd *cobra.Command, args []string) (*whisk.Api, *QualifiedName, error) {
var err error
var basepath string = "/"
var apiname string
@@ -1452,7 +800,7 @@ func parseApiV2(cmd *cobra.Command, args []string) (*whisk.Api, *QualifiedName,
return api, &qName, nil
}
-func parseSwaggerApiV2() (*whisk.Api, error) {
+func parseSwaggerApi() (*whisk.Api, error) {
// Test is for completeness, but this situation should only arise due to an internal error
if ( len(flags.api.configfile) == 0 ) {
whisk.Debug(whisk.DbgError, "No swagger file is specified\n")
@@ -1488,7 +836,7 @@ func parseSwaggerApiV2() (*whisk.Api, error) {
}
// Parse the JSON into a swagger object
- swaggerObj := new(whisk.ApiSwaggerV2)
+ swaggerObj := new(whisk.ApiSwagger)
err = json.Unmarshal([]byte(swagger), swaggerObj)
if ( err != nil ) {
whisk.Debug(whisk.DbgError, "JSON parse of `%s' error: %s\n", flags.api.configfile, err)
@@ -1565,35 +913,19 @@ func getUserContextId() (string, error) {
///////////
func init() {
+
apiCreateCmd.Flags().StringVarP(&flags.api.apiname, "apiname", "n", "", wski18n.T("Friendly name of the API; ignored when CFG_FILE is specified (default BASE_PATH)"))
apiCreateCmd.Flags().StringVarP(&flags.api.configfile, "config-file", "c", "", wski18n.T("`CFG_FILE` containing API configuration in swagger JSON format"))
- //apiUpdateCmd.Flags().StringVarP(&flags.api.action, "action", "a", "", wski18n.T("`ACTION` to invoke when API is called"))
- //apiUpdateCmd.Flags().StringVarP(&flags.api.path, "path", "p", "", wski18n.T("relative `PATH` of API"))
- //apiUpdateCmd.Flags().StringVarP(&flags.api.verb, "method", "m", "", wski18n.T("API `VERB`"))
+ apiCreateCmd.Flags().StringVar(&flags.api.resptype, "response-type", "json", wski18n.T("Set the web action response `TYPE`. Possible values are html, http, json, text, svg"))
apiGetCmd.Flags().BoolVarP(&flags.common.detail, "full", "f", false, wski18n.T("display full API configuration details"))
+ apiGetCmd.Flags().StringVarP(&flags.common.format, "format", "", formatOptionJson, wski18n.T("Specify the API output `TYPE`, either json or yaml"))
apiListCmd.Flags().IntVarP(&flags.common.skip, "skip", "s", 0, wski18n.T("exclude the first `SKIP` number of actions from the result"))
apiListCmd.Flags().IntVarP(&flags.common.limit, "limit", "l", 30, wski18n.T("only return `LIMIT` number of actions from the collection"))
apiListCmd.Flags().BoolVarP(&flags.common.full, "full", "f", false, wski18n.T("display full description of each API"))
- apiExperimentalCmd.AddCommand(
+ apiCmd.AddCommand(
apiCreateCmd,
- //apiUpdateCmd,
apiGetCmd,
apiDeleteCmd,
apiListCmd,
)
-
- apiCreateCmdV2.Flags().StringVarP(&flags.api.apiname, "apiname", "n", "", wski18n.T("Friendly name of the API; ignored when CFG_FILE is specified (default BASE_PATH)"))
- apiCreateCmdV2.Flags().StringVarP(&flags.api.configfile, "config-file", "c", "", wski18n.T("`CFG_FILE` containing API configuration in swagger JSON format"))
- apiCreateCmdV2.Flags().StringVar(&flags.api.resptype, "response-type", "json", wski18n.T("Set the web action response `TYPE`. Possible values are html, http, json, text, svg"))
- apiGetCmdV2.Flags().BoolVarP(&flags.common.detail, "full", "f", false, wski18n.T("display full API configuration details"))
- apiGetCmdV2.Flags().StringVarP(&flags.common.format, "format", "", formatOptionJson, wski18n.T("Specify the API output `TYPE`, either json or yaml"))
- apiListCmdV2.Flags().IntVarP(&flags.common.skip, "skip", "s", 0, wski18n.T("exclude the first `SKIP` number of actions from the result"))
- apiListCmdV2.Flags().IntVarP(&flags.common.limit, "limit", "l", 30, wski18n.T("only return `LIMIT` number of actions from the collection"))
- apiListCmdV2.Flags().BoolVarP(&flags.common.full, "full", "f", false, wski18n.T("display full description of each API"))
- apiCmd.AddCommand(
- apiCreateCmdV2,
- apiGetCmdV2,
- apiDeleteCmdV2,
- apiListCmdV2,
- )
}
diff --git a/tools/cli/go-whisk-cli/commands/wsk.go b/tools/cli/go-whisk-cli/commands/wsk.go
index e18b978..b4bbc5b 100644
--- a/tools/cli/go-whisk-cli/commands/wsk.go
+++ b/tools/cli/go-whisk-cli/commands/wsk.go
@@ -54,7 +54,6 @@ func init() {
propertyCmd,
namespaceCmd,
listCmd,
- apiExperimentalCmd,
apiCmd,
)
diff --git a/tools/cli/go-whisk-cli/wski18n/resources/en_US.all.json b/tools/cli/go-whisk-cli/wski18n/resources/en_US.all.json
index 5608728..2140b9e 100644
--- a/tools/cli/go-whisk-cli/wski18n/resources/en_US.all.json
+++ b/tools/cli/go-whisk-cli/wski18n/resources/en_US.all.json
@@ -1300,18 +1300,6 @@
"translation": "'{{.verb}}' is not a valid API verb. Valid values are: {{.verbs}}"
},
{
- "id": "`ACTION` to invoke when API is called",
- "translation": "`ACTION` to invoke when API is called"
- },
- {
- "id": "relative `API_PATH` of API",
- "translation": "relative `API_PATH` of API"
- },
- {
- "id": "API `API_VERB`",
- "translation": "API `API_VERB`"
- },
- {
"id": "API collection `NAME` (default NAMESPACE)",
"translation": "API collection `NAME` (default NAMESPACE)"
},
diff --git a/tools/cli/go-whisk/whisk/api.go b/tools/cli/go-whisk/whisk/api.go
index 6b9d4a6..31e5cb9 100644
--- a/tools/cli/go-whisk/whisk/api.go
+++ b/tools/cli/go-whisk/whisk/api.go
@@ -33,7 +33,6 @@ type ApiCreateRequest struct {
}
type ApiCreateRequestOptions ApiOptions
type ApiCreateResponse RetApi
-type ApiCreateResponseV2 RetApiV2
// wsk api list : Request, Response
type ApiListRequest struct {
@@ -44,8 +43,8 @@ type ApiListRequestOptions struct {
Skip int `url:"skip"`
Docs bool `url:"docs,omitempty"`
}
+//type ApiListResponse RetApiArray
type ApiListResponse RetApiArray
-type ApiListResponseV2 RetApiArrayV2
// wsk api get : Request, Response
type ApiGetRequest struct {
@@ -53,7 +52,6 @@ type ApiGetRequest struct {
}
type ApiGetRequestOptions ApiOptions
type ApiGetResponse RetApiArray
-type ApiGetResponseV2 RetApiArrayV2
// wsk api delete : Request, Response
type ApiDeleteRequest struct {
@@ -105,7 +103,7 @@ type RetApiArray struct {
type ApiItem struct {
ApiId string `json:"id,omitempty"`
QueryKey string `json:"key,omitempty"`
- ApiValue *RetApi `json:"value,omitempty"`
+ ApiValue *RetApi `json:"value,omitempty"`
}
type RetApi struct {
@@ -120,33 +118,7 @@ type ApiSwagger struct {
SwaggerName string `json:"swagger,omitempty"`
BasePath string `json:"basePath,omitempty"`
Info *ApiSwaggerInfo `json:"info,omitempty"`
- Paths map[string]map[string]*ApiSwaggerOperationV1 `json:"paths,omitempty"`
- XConfig map[string]map[string][]map[string]map[string]interface{} `json:"x-ibm-configuration,omitempty"`
-}
-
-type RetApiArrayV2 struct {
- Apis []ApiItemV2 `json:"apis,omitempty"`
-}
-
-type ApiItemV2 struct {
- ApiId string `json:"id,omitempty"`
- QueryKey string `json:"key,omitempty"`
- ApiValue *RetApiV2 `json:"value,omitempty"`
-}
-
-type RetApiV2 struct {
- Namespace string `json:"namespace"`
- BaseUrl string `json:"gwApiUrl"`
- Activated bool `json:"gwApiActivated"`
- TenantId string `json:"tenantId"`
- Swagger *ApiSwaggerV2 `json:"apidoc,omitempty"`
-}
-
-type ApiSwaggerV2 struct {
- SwaggerName string `json:"swagger,omitempty"`
- BasePath string `json:"basePath,omitempty"`
- Info *ApiSwaggerInfo `json:"info,omitempty"`
- Paths map[string]map[string]*ApiSwaggerOperationV2 `json:"paths,omitempty"` // Paths["/a/path"]["get"] -> a generic object
+ Paths map[string]map[string]*ApiSwaggerOperation `json:"paths,omitempty"` // Paths["/a/path"]["get"] -> a generic object
SecurityDef interface{} `json:"securityDefinitions,omitempty"`
Security interface{} `json:"security,omitempty"`
XConfig interface{} `json:"x-ibm-configuration,omitempty"`
@@ -158,26 +130,13 @@ type ApiSwaggerInfo struct {
Version string `json:"version,omitempty"`
}
-type ApiSwaggerOperationV1 struct {
- Responses interface{} `json:"responses"`
- XOpenWhisk *ApiSwaggerOpXOpenWhiskV1 `json:"x-ibm-op-ext,omitempty"`
-}
-
-type ApiSwaggerOperationV2 struct {
+type ApiSwaggerOperation struct {
OperationId string `json:"operationId"`
Responses interface{} `json:"responses"`
- XOpenWhisk *ApiSwaggerOpXOpenWhiskV2 `json:"x-openwhisk,omitempty"`
+ XOpenWhisk *ApiSwaggerOpXOpenWhisk `json:"x-openwhisk,omitempty"`
}
-type ApiSwaggerOpXOpenWhiskV1 struct {
- ActionName string `json:"actionName"`
- Namespace string `json:"actionNamespace"`
- ActionUrlVerb string `json:"backendMethod"`
- ActionUrl string `json:"backendUrl"`
- Policies interface{} `json:"policies"`
-}
-
-type ApiSwaggerOpXOpenWhiskV2 struct {
+type ApiSwaggerOpXOpenWhisk struct {
ActionName string `json:"action"`
Namespace string `json:"namespace"`
Package string `json:"package"`
@@ -199,154 +158,11 @@ const (
DoNotOverwrite = false
)
-////////////////////
+/////////////////
// Api Methods //
-////////////////////
+/////////////////
func (s *ApiService) List(apiListOptions *ApiListRequestOptions) (*ApiListResponse, *http.Response, error) {
- route := "web/whisk.system/routemgmt/getApi.http"
- Debug(DbgInfo, "Api GET/list route: %s\n", route)
-
- routeUrl, err := addRouteOptions(route, apiListOptions)
- if err != nil {
- Debug(DbgError, "addRouteOptions(%s, %#v) error: '%s'\n", route, apiListOptions, err)
- errMsg := wski18n.T("Unable to add route options '{{.options}}'",
- map[string]interface{}{"options": apiListOptions})
- whiskErr := MakeWskErrorFromWskError(errors.New(errMsg), err, EXITCODE_ERR_GENERAL, DISPLAY_MSG,
- NO_DISPLAY_USAGE)
- return nil, nil, whiskErr
- }
- Debug(DbgInfo, "Api GET/list route with api options: %s\n", routeUrl)
-
- req, err := s.client.NewRequestUrl("GET", routeUrl, nil, DoNotIncludeNamespaceInUrl, AppendOpenWhiskPathPrefix, EncodeBodyAsJson, AuthRequired)
- if err != nil {
- Debug(DbgError, "http.NewRequestUrl(GET, %s, nil, DoNotIncludeNamespaceInUrl, AppendOpenWhiskPathPrefix, EncodeBodyAsJson, AuthRequired) error: '%s'\n", routeUrl, err)
- errMsg := wski18n.T("Unable to create HTTP request for GET '{{.route}}': {{.err}}",
- map[string]interface{}{"route": routeUrl, "err": err})
- whiskErr := MakeWskErrorFromWskError(errors.New(errMsg), err, EXITCODE_ERR_NETWORK, DISPLAY_MSG,
- NO_DISPLAY_USAGE)
- return nil, nil, whiskErr
- }
-
- apiArray := new(ApiListResponse)
- resp, err := s.client.Do(req, &apiArray, ExitWithErrorOnTimeout)
- if err != nil {
- Debug(DbgError, "s.client.Do() error - HTTP req %s; error '%s'\n", req.URL.String(), err)
- return nil, resp, err
- }
-
- return apiArray, resp, err
-}
-
-func (s *ApiService) Insert(api *ApiCreateRequest, options *ApiCreateRequestOptions, overwrite bool) (*ApiCreateResponse, *http.Response, error) {
- route := "web/whisk.system/routemgmt/createApi.http"
- Debug(DbgInfo, "Api PUT route: %s\n", route)
-
- routeUrl, err := addRouteOptions(route, options)
- if err != nil {
- Debug(DbgError, "addRouteOptions(%s, %#v) error: '%s'\n", route, options, err)
- errMsg := wski18n.T("Unable to add route options '{{.options}}'",
- map[string]interface{}{"options": options})
- whiskErr := MakeWskErrorFromWskError(errors.New(errMsg), err, EXITCODE_ERR_GENERAL, DISPLAY_MSG,
- NO_DISPLAY_USAGE)
- return nil, nil, whiskErr
- }
- Debug(DbgError, "Api create route with options: %s\n", routeUrl)
-
- req, err := s.client.NewRequestUrl("POST", routeUrl, api, DoNotIncludeNamespaceInUrl, AppendOpenWhiskPathPrefix, EncodeBodyAsJson, AuthRequired)
- if err != nil {
- Debug(DbgError, "http.NewRequestUrl(POST, %s, nil, DoNotIncludeNamespaceInUrl, AppendOpenWhiskPathPrefix, EncodeBodyAsJson) error: '%s'\n", route, err)
- errMsg := wski18n.T("Unable to create HTTP request for POST '{{.route}}': {{.err}}",
- map[string]interface{}{"route": route, "err": err})
- whiskErr := MakeWskErrorFromWskError(errors.New(errMsg), err, EXITCODE_ERR_NETWORK, DISPLAY_MSG,
- NO_DISPLAY_USAGE)
- return nil, nil, whiskErr
- }
-
- retApi := new(ApiCreateResponse)
- resp, err := s.client.Do(req, &retApi, ExitWithErrorOnTimeout)
- if err != nil {
- Debug(DbgError, "s.client.Do() error - HTTP req %s; error '%s'\n", req.URL.String(), err)
- return nil, resp, err
- }
-
- return retApi, resp, nil
-}
-
-func (s *ApiService) Get(api *ApiGetRequest, options *ApiGetRequestOptions) (*ApiGetResponse, *http.Response, error) {
- route := "web/whisk.system/routemgmt/getApi.http"
- Debug(DbgInfo, "Api GET route: %s\n", route)
-
- routeUrl, err := addRouteOptions(route, options)
- if err != nil {
- Debug(DbgError, "addRouteOptions(%s, %#v) error: '%s'\n", route, options, err)
- errMsg := wski18n.T("Unable to add route options '{{.options}}'",
- map[string]interface{}{"options": options})
- whiskErr := MakeWskErrorFromWskError(errors.New(errMsg), err, EXITCODE_ERR_GENERAL, DISPLAY_MSG,
- NO_DISPLAY_USAGE)
- return nil, nil, whiskErr
- }
- Debug(DbgError, "Api get route with options: %s\n", routeUrl)
-
- req, err := s.client.NewRequestUrl("GET", routeUrl, nil, DoNotIncludeNamespaceInUrl, AppendOpenWhiskPathPrefix, EncodeBodyAsJson, AuthRequired)
- if err != nil {
- Debug(DbgError, "http.NewRequestUrl(GET, %s, nil, DoNotIncludeNamespaceInUrl, AppendOpenWhiskPathPrefix, EncodeBodyAsJson, AuthRequired) error: '%s'\n", route, err)
- errMsg := wski18n.T("Unable to create HTTP request for GET '{{.route}}': {{.err}}",
- map[string]interface{}{"route": route, "err": err})
- whiskErr := MakeWskErrorFromWskError(errors.New(errMsg), err, EXITCODE_ERR_NETWORK, DISPLAY_MSG,
- NO_DISPLAY_USAGE)
- return nil, nil, whiskErr
- }
-
- retApi := new(ApiGetResponse)
- resp, err := s.client.Do(req, &retApi, ExitWithErrorOnTimeout)
- if err != nil {
- Debug(DbgError, "s.client.Do() error - HTTP req %s; error '%s'\n", req.URL.String(), err)
- return nil, resp, err
- }
-
- return retApi, resp, nil
-}
-
-func (s *ApiService) Delete(api *ApiDeleteRequest, options *ApiDeleteRequestOptions) (*http.Response, error) {
- route := "web/whisk.system/routemgmt/deleteApi.http"
- Debug(DbgInfo, "Api DELETE route: %s\n", route)
-
- routeUrl, err := addRouteOptions(route, options)
- if err != nil {
- Debug(DbgError, "addRouteOptions(%s, %#v) error: '%s'\n", route, options, err)
- errMsg := wski18n.T("Unable to add route options '{{.options}}'",
- map[string]interface{}{"options": options})
- whiskErr := MakeWskErrorFromWskError(errors.New(errMsg), err, EXITCODE_ERR_GENERAL, DISPLAY_MSG,
- NO_DISPLAY_USAGE)
- return nil, whiskErr
- }
- Debug(DbgError, "Api DELETE route with options: %s\n", routeUrl)
-
- req, err := s.client.NewRequestUrl("DELETE", routeUrl, nil, DoNotIncludeNamespaceInUrl, AppendOpenWhiskPathPrefix, EncodeBodyAsJson, AuthRequired)
- if err != nil {
- Debug(DbgError, "http.NewRequestUrl(DELETE, %s, nil, DoNotIncludeNamespaceInUrl, AppendOpenWhiskPathPrefix, EncodeBodyAsJson, AuthRequired) error: '%s'\n", route, err)
- errMsg := wski18n.T("Unable to create HTTP request for DELETE '{{.route}}': {{.err}}",
- map[string]interface{}{"route": route, "err": err})
- whiskErr := MakeWskErrorFromWskError(errors.New(errMsg), err, EXITCODE_ERR_NETWORK, DISPLAY_MSG,
- NO_DISPLAY_USAGE)
- return nil, whiskErr
- }
-
- retApi := new(ApiDeleteResponse)
- resp, err := s.client.Do(req, &retApi, ExitWithErrorOnTimeout)
- if err != nil {
- Debug(DbgError, "s.client.Do() error - HTTP req %s; error '%s'\n", req.URL.String(), err)
- return resp, err
- }
-
- return nil, nil
-}
-
-/////////////
-// V2 Cmds //
-/////////////
-func (s *ApiService) ListV2(apiListOptions *ApiListRequestOptions) (*ApiListResponseV2, *http.Response, error) {
route := "web/whisk.system/apimgmt/getApi.http"
routeUrl, err := addRouteOptions(route, apiListOptions)
@@ -370,7 +186,7 @@ func (s *ApiService) ListV2(apiListOptions *ApiListRequestOptions) (*ApiListResp
return nil, nil, whiskErr
}
- apiArray := new(ApiListResponseV2)
+ apiArray := new(ApiListResponse)
resp, err := s.client.Do(req, &apiArray, ExitWithErrorOnTimeout)
if err != nil {
Debug(DbgError, "s.client.Do() error - HTTP req %s; error '%s'\n", req.URL.String(), err)
@@ -386,7 +202,7 @@ func (s *ApiService) ListV2(apiListOptions *ApiListRequestOptions) (*ApiListResp
return apiArray, resp, err
}
-func (s *ApiService) InsertV2(api *ApiCreateRequest, options *ApiCreateRequestOptions, overwrite bool) (*ApiCreateResponseV2, *http.Response, error) {
+func (s *ApiService) Insert(api *ApiCreateRequest, options *ApiCreateRequestOptions, overwrite bool) (*ApiCreateResponse, *http.Response, error) {
route := "web/whisk.system/apimgmt/createApi.http"
Debug(DbgInfo, "Api PUT route: %s\n", route)
@@ -411,7 +227,7 @@ func (s *ApiService) InsertV2(api *ApiCreateRequest, options *ApiCreateRequestOp
return nil, nil, whiskErr
}
- retApi := new(ApiCreateResponseV2)
+ retApi := new(ApiCreateResponse)
resp, err := s.client.Do(req, &retApi, ExitWithErrorOnTimeout)
if err != nil {
Debug(DbgError, "s.client.Do() error - HTTP req %s; error '%s'\n", req.URL.String(), err)
@@ -427,7 +243,7 @@ func (s *ApiService) InsertV2(api *ApiCreateRequest, options *ApiCreateRequestOp
return retApi, resp, nil
}
-func (s *ApiService) GetV2(api *ApiGetRequest, options *ApiGetRequestOptions) (*ApiGetResponseV2, *http.Response, error) {
+func (s *ApiService) Get(api *ApiGetRequest, options *ApiGetRequestOptions) (*ApiGetResponse, *http.Response, error) {
route := "web/whisk.system/apimgmt/getApi.http"
Debug(DbgInfo, "Api GET route: %s\n", route)
@@ -452,7 +268,7 @@ func (s *ApiService) GetV2(api *ApiGetRequest, options *ApiGetRequestOptions) (*
return nil, nil, whiskErr
}
- retApi := new(ApiGetResponseV2)
+ retApi := new(ApiGetResponse)
resp, err := s.client.Do(req, &retApi, ExitWithErrorOnTimeout)
if err != nil {
Debug(DbgError, "s.client.Do() error - HTTP req %s; error '%s'\n", req.URL.String(), err)
@@ -462,7 +278,7 @@ func (s *ApiService) GetV2(api *ApiGetRequest, options *ApiGetRequestOptions) (*
return retApi, resp, nil
}
-func (s *ApiService) DeleteV2(api *ApiDeleteRequest, options *ApiDeleteRequestOptions) (*http.Response, error) {
+func (s *ApiService) Delete(api *ApiDeleteRequest, options *ApiDeleteRequestOptions) (*http.Response, error) {
route := "web/whisk.system/apimgmt/deleteApi.http"
Debug(DbgInfo, "Api DELETE route: %s\n", route)
@@ -498,7 +314,7 @@ func (s *ApiService) DeleteV2(api *ApiDeleteRequest, options *ApiDeleteRequestOp
}
-func validateApiListResponse(apiList *ApiListResponseV2) error {
+func validateApiListResponse(apiList *ApiListResponse) error {
for i:=0; i<len(apiList.Apis); i++ {
if apiList.Apis[i].ApiValue == nil {
Debug(DbgError, "validateApiResponse: No value stanza in api %v\n", apiList.Apis[i])
@@ -515,7 +331,7 @@ func validateApiListResponse(apiList *ApiListResponseV2) error {
return nil
}
-func validateApiSwaggerResponse(swagger *ApiSwaggerV2) error {
+func validateApiSwaggerResponse(swagger *ApiSwagger) error {
if swagger == nil {
Debug(DbgError, "validateApiSwaggerResponse: No apidoc stanza in api\n")
errMsg := wski18n.T("Internal error. Missing apidoc stanza in API configuration")
@@ -533,7 +349,7 @@ func validateApiSwaggerResponse(swagger *ApiSwaggerV2) error {
return nil
}
-func validateApiPath(path map[string]*ApiSwaggerOperationV2) error {
+func validateApiPath(path map[string]*ApiSwaggerOperation) error {
for op, opv := range path {
err := validateApiOperation(op, opv)
if err != nil {
@@ -544,7 +360,7 @@ func validateApiPath(path map[string]*ApiSwaggerOperationV2) error {
return nil
}
-func validateApiOperation(opName string, op *ApiSwaggerOperationV2) error {
+func validateApiOperation(opName string, op *ApiSwaggerOperation) error {
if (op.XOpenWhisk != nil && len(op.OperationId) == 0) {
Debug(DbgError, "validateApiOperation: No operationId field in operation %v\n", op)
errMsg := wski18n.T("Missing operationId field in API configuration for operation {{.op}}",
--
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].