kpavel closed pull request #918: Adds support for api export URL: https://github.com/apache/incubator-openwhisk-wskdeploy/pull/918
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/cmd/export.go b/cmd/export.go index 746854c0..0a085e5a 100644 --- a/cmd/export.go +++ b/cmd/export.go @@ -273,6 +273,68 @@ func exportProject(projectName string, targetManifest string) error { } + // List API request query parameters + apiListReqOptions := new(whisk.ApiListRequestOptions) + apiListReqOptions.SpaceGuid = strings.Split(client.Config.AuthToken, ":")[0] + apiListReqOptions.AccessToken = client.Config.ApigwAccessToken + + // Get list of APIs from OW + retApiList, _, err := client.Apis.List(apiListReqOptions) + if err != nil { + return err + } + + // iterate over the list of APIs to determine whether any of them part of the managed project + retApiArray := (*whisk.RetApiArray)(retApiList) + for _, api := range retApiArray.Apis { + + apiName := api.ApiValue.Swagger.Info.Title + apiBasePath := strings.TrimPrefix(api.ApiValue.Swagger.BasePath, "/") + + // run over api paths looking for one pointing to an action belonging to the given project + for path := range api.ApiValue.Swagger.Paths { + for op, opv := range api.ApiValue.Swagger.Paths[path].MakeOperationMap() { + if len(opv.XOpenWhisk.Package) > 0 { + pkgName := opv.XOpenWhisk.Package + + if pkg, ok := maniyaml.Packages[pkgName]; ok { + if pkg.Namespace == opv.XOpenWhisk.Namespace { + + // now adding the api to the maniyaml + if pkg.Apis == nil { + pkg.Apis = make(map[string]map[string]map[string]map[string]string) + } + + path = strings.TrimPrefix(path, "/") + + if pkgApi, ok := pkg.Apis[apiName]; ok { + if pkgApiBasePath, ok := pkgApi[apiBasePath]; ok { + if _, ok := pkgApiBasePath[path]; ok { + pkg.Apis[apiName][apiBasePath][path][opv.XOpenWhisk.ActionName] = op + } else { + pkg.Apis[apiName][apiBasePath][path] = map[string]string{} + pkg.Apis[apiName][apiBasePath][path][opv.XOpenWhisk.ActionName] = op + } + } else { + pkg.Apis[apiName][apiBasePath] = map[string]map[string]string{} + pkg.Apis[apiName][apiBasePath][path] = map[string]string{} + pkg.Apis[apiName][apiBasePath][path][opv.XOpenWhisk.ActionName] = op + } + } else { + pkg.Apis[apiName] = map[string]map[string]map[string]string{} + pkg.Apis[apiName][apiBasePath] = map[string]map[string]string{} + pkg.Apis[apiName][apiBasePath][path] = map[string]string{} + pkg.Apis[apiName][apiBasePath][path][opv.XOpenWhisk.ActionName] = op + } + + maniyaml.Packages[pkgName] = pkg + } + } + } + } + } + } + // adding dependencies to the first package for pkgName := range maniyaml.Packages { for bPkg, binding := range bindings { diff --git a/tests/src/integration/export/export_test.go b/tests/src/integration/export/export_test.go index 7e2a0bc3..7dd03244 100644 --- a/tests/src/integration/export/export_test.go +++ b/tests/src/integration/export/export_test.go @@ -108,6 +108,32 @@ func TestExport2Pack(t *testing.T) { assert.Equal(t, nil, err, "Failed to undeploy") } +func TestExportApi(t *testing.T) { + projectName := "ApiExp" + wskdeploy := common.NewWskdeploy() + + _, err := wskdeploy.ManagedDeploymentManifestAndProject(manifestApiExpPath, projectName) + assert.Equal(t, nil, err, "Failed to deploy the ApiExp manifest file.") + + _, err = wskdeploy.ExportProject(projectName, targetApiExpManifestPath) + assert.Equal(t, nil, err, "Failed to export project.") + + _, err = os.Stat(manifestApiExpPath) + assert.Equal(t, nil, err, "Missing exported manifest file") + + _, err = os.Stat(targetManifestFolder + "api-export-test/greeting.js") + assert.Equal(t, nil, err, "Missing exported api-export-test/greeting.js") + + _, err = wskdeploy.UndeployManifestPathOnly(manifestApiExpPath) + assert.Equal(t, nil, err, "Failed to undeploy") + + _, err = wskdeploy.ManagedDeploymentOnlyManifest(targetApiExpManifestPath) + assert.Equal(t, nil, err, "Failed to redeploy the exported manifest file.") + + _, err = wskdeploy.UndeployManifestPathOnly(targetApiExpManifestPath) + assert.Equal(t, nil, err, "Failed to undeploy the exported manifest file") +} + var ( manifestLib1Path = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/export/manifest_lib1.yaml" manifestLib2Path = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/export/manifest_lib2.yaml" @@ -116,8 +142,12 @@ var ( targetManifestFolder = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/export/tmp/" targetManifestPath = targetManifestFolder + "manifest.yaml" + manifest2PackPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/export/manifest_2pack.yaml" + target2PackManifestPath = targetManifestFolder + "exported2packmanifest.yaml" + + manifestApiExpPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/export/manifest_apiexp.yaml" + targetApiExpManifestPath = targetManifestFolder + "exportedapimanifest.yaml" + manifestHelloWorldPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/export/manifest_helloworld.yaml" targetManifestHelloWorldPath = targetManifestFolder + "manifest.yaml" - manifest2PackPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/export/manifest_2pack.yaml" - target2PackManifestPath = targetManifestFolder + "exported2packmanifest.yaml" ) diff --git a/tests/src/integration/export/manifest_apiexp.yaml b/tests/src/integration/export/manifest_apiexp.yaml new file mode 100644 index 00000000..39e32ff2 --- /dev/null +++ b/tests/src/integration/export/manifest_apiexp.yaml @@ -0,0 +1,40 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for additional +# information regarding copyright ownership. The ASF licenses this file to you +# under the Apache License, Version 2.0 (the # "License"); you may not use this +# file except in compliance with the License. You may obtain a copy of the License +# at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. +# + +packages: + api-export-test: + version: 1.0 + license: Apache-2.0 + actions: + greeting: + web-export: true + version: 1.0 + function: src/greeting.js + runtime: nodejs:6 + # new top-level key for defining groups of named APIs + apis: + h1: + hello1: + world1: + greeting: GET + h2: + hello2: + world2: + greeting: GET + h3: + hello3: + world3: + greeting: GET ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services