Skip to content

Commit

Permalink
Merge pull request #14 from ramgrandhi/feat/show-published-api-endpoints
Browse files Browse the repository at this point in the history
invokable API Endpoint URLs are available now
  • Loading branch information
ramgrandhi authored Aug 5, 2020
2 parents ab4f396 + 7d12c67 commit 305f0dc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
27 changes: 24 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,32 @@ class ServerlessPlugin {
});

// Compare apples-to-apples (configured-to-deployed) and record deployment status
if (this.cache.deployedAPIs.some(deployedAPI => deployedAPI.apiClob === apiDefClob)) {
if (this.cache.deployedAPIs.some(deployedAPI => deployedAPI.apiClob == apiDefClob)) {
const apiStatus = this.cache.deployedAPIs.find(deployedAPI => deployedAPI.apiClob == apiDefClob).apiStatus;
const apiId = this.cache.deployedAPIs.find(deployedAPI => deployedAPI.apiClob == apiDefClob).apiId;
var invokableAPIURL = null;

// Check for PUBLISHED state, if PUBLISHED then retrieve Invokable API URL
try {
if (apiStatus == 'PUBLISHED') {
const data = await wso2apim.listInvokableAPIUrl(
"https://" + this.wso2APIM.host + ":" + this.wso2APIM.port + "/api/am/store/" + this.wso2APIM.versionSlug + "/apis",
this.cache.accessToken,
apiId);
invokableAPIURL = data.endpointURLs.filter((Url) => { return Url.environmentName == this.wso2APIM.gatewayEnv })[0].environmentURLs.https;
}
}
catch (err) {
this.serverless.cli.log("An error occurred while retrieving Invokable API URL for " + `${this.apiDefs[i].name}` + ", proceeding further.");
}

this.cache.deploymentStatus.push({
apiName: apiDef.name,
apiVersion: apiDef.version,
apiContext: apiDef.rootContext,
apiStatus: this.cache.deployedAPIs.find(deployedAPI => deployedAPI.apiClob === apiDefClob).apiStatus,
apiId: this.cache.deployedAPIs.find(deployedAPI => deployedAPI.apiClob === apiDefClob).apiId,
apiStatus: apiStatus,
apiId, apiId,
invokableAPIURL: invokableAPIURL + " 🚀",
});
}
else {
Expand All @@ -238,6 +257,8 @@ class ServerlessPlugin {
apiVersion: apiDef.version,
apiContext: apiDef.rootContext,
apiStatus: "TO BE CREATED",
apiId: null,
invokableAPIURL: "TO BE CREATED",
})
}
}
Expand Down
34 changes: 33 additions & 1 deletion src/2.6.0/wso2apim.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,37 @@ async function publishAPIDef(url, accessToken, apiId) {
}
};


// Retrieves invokable API endpoint
async function listInvokableAPIUrl(url, accessToken, apiId) {
try {
url = url + "/" + apiId;
var config = {
headers: {
'Authorization': 'Bearer ' + accessToken
},
httpsAgent: new https.Agent({
rejectUnauthorized: false
})
};

return new Promise((resolve, reject) => {
axios.get(url, config)
.then((res) => {
resolve(res.data);
})
.catch((err) => {
utils.renderError(err);
reject(err);
});
});
}
catch (err) {
utils.renderError(err);
}
};


// Uploads backend certificate
async function uploadCert(url, accessToken, certAlias, certFile, backendUrl) {
try {
Expand Down Expand Up @@ -419,5 +450,6 @@ module.exports = {
uploadCert,
updateAPIDef,
removeAPIDef,
removeCert
removeCert,
listInvokableAPIUrl,
};

0 comments on commit 305f0dc

Please sign in to comment.