You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2017/12/17 20:59:26 UTC

[GitHub] mhamann commented on a change in pull request #266: Move core/routemgmt from openwhisk repo to openwhisk-apigateway

mhamann commented on a change in pull request #266: Move core/routemgmt from openwhisk repo to openwhisk-apigateway
URL: https://github.com/apache/incubator-openwhisk-apigateway/pull/266#discussion_r157379541
 
 

 ##########
 File path: routemgmt/common/apigw-utils.js
 ##########
 @@ -0,0 +1,896 @@
+/*
+ * 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.
+ */
+
+/**
+ * Route management action common API GW utilities
+ */
+var request = require('request');
+var _ = require('lodash');
+
+const ApimgmtUserAgent = "OpenWhisk-apimgmt/1.0.0";
+var UserAgent = ApimgmtUserAgent;
+
+/**
+ * Configures an API route on the API Gateway.  This API will map to an OpenWhisk action that
+ * will be invoked by the API Gateway when the API route is accessed.
+ *
+ * @param gwInfo Required.
+ * @param    gwUrl     Required. The base URL gateway path (i.e.  'PROTOCOL://gw.host.domain:PORT/CONTEXT')
+ * @param    gwAuth    Required. The user bearer token used to access the API Gateway REST endpoints
+ * @param spaceGuid    Required. User's space guid.  APIs are stored under this context
+ * @param swaggerApi   Required. The API swagger object to send to the API gateway
+ * @param apiId        Required. API id. When specified, the API exists and will be updated; otherwise the API is created anew
+ * @return A promise for an object describing the result with fields error and response
+ */
+function addApiToGateway(gwInfo, spaceGuid, swaggerApi, apiId) {
+  var requestFcn = request.post;
+
+  console.log('addApiToGateway: ');
+  try {
+  var options = {
+    followAllRedirects: true,
+    url: gwInfo.gwUrl+'/'+encodeURIComponent(spaceGuid) + '/apis',
+    json: swaggerApi,  // Use of json automatically sets header: 'Content-Type': 'application/json'
+    headers: {
+      'User-Agent': UserAgent
+    }
+  };
+  if (gwInfo.gwAuth) {
+    _.set(options, "headers.Authorization", 'Bearer ' + gwInfo.gwAuth);
+  }
+
+  if (apiId) {
+    console.log("addApiToGateway: Updating existing API");
+    options.url = gwInfo.gwUrl + '/' + encodeURIComponent(spaceGuid) + '/apis/' + encodeURIComponent(apiId);
+    requestFcn = request.put;
+  }
+
+  console.log('addApiToGateway: request: '+JSON.stringify(options, " ", 2));
+  }
+  catch (e) {
+    console.error('addApiToGateway exception: '+e);
+  }
+  return new Promise(function(resolve, reject) {
 
 Review comment:
   Also, prefer async/await if using Node > 8

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


With regards,
Apache Git Services