Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added kvm flag to retrieve target endpoint url from key value map #18

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/openapi2apigee
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ program
.option('-p, --password <password>', 'Apigee Edge Password to Deploy')
.option('-t, --token <token>', 'Apigee Edge Auth Token to Deploy')
.option('-U, --backendurl <backendurl>','Specify the target backend url')
.option('-K, --kvm <kvm>', 'Specify the kvm name to use inside target endpoint')
.option('-O, --oauth <oauth>','Apigee enable oauth')

.description('Generates Apigee API Bundle')
Expand Down
17 changes: 17 additions & 0 deletions lib/commands/generateApi/generatePolicies.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var validations = require('../../policy_templates/validations/valid.js')
var raiseFault = require('../../policy_templates/raise-fault/raise.js')
var verifyApiKey = require('../../policy_templates/security/apikey.js')
var oauth2 = require('../../policy_templates/security/verifyAccessToken.js')
var getKvmEntry = require('../../policy_templates/kvm/getKvmEntry')
var removeHeaderAuthorization = require('../../policy_templates/security/removeHeaderAuthorization.js')
var async = require('async')

Expand Down Expand Up @@ -64,6 +65,22 @@ module.exports = function generatePolicies (apiProxy, options, api, cb) {
})
})
}
if (options.kvm) {
var option = {
apiName: apiProxy,
kvm: options.kvm
}
var xmlString = getKvmEntry.getKvmGenEntry(option, "getKvmEntry")
fs.writeFile(rootDirectory + '/policies/getKvmEntry.xml', xmlString, function (err) {
if (err) {
throw new Error()
}
writeCnt++
if (writeCnt === xmlStrings.length) {
// cb(null, {})
}
})
}

async.each(services, function (service, callback) {
// Perform operation on file here.
Expand Down
4 changes: 4 additions & 0 deletions lib/commands/generateApi/generateProxyEndPoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ module.exports = function generateProxyEndPoint (apiProxy, options, api, cb) {
var step2 = requestPipe.ele('Step', {})
step2.ele('Name', {}, 'removeHeaderAuthorization')
}
if (options.kvm) {
requestPipe.ele('Step', {})
.ele('Name', {}, 'getKvmEntry')
}
services.forEach(function (serviceItem) {
if (serviceItem.provider === 'x-cors') {
useCors = serviceItem.name
Expand Down
4 changes: 3 additions & 1 deletion lib/commands/generateApi/generateTargetEndPoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ module.exports = function generateTargetEndPoint (apiProxy, options, api, cb) {

var httpTargetConn = root.ele('HTTPTargetConnection')

if (options.backendurl) {
if (options.kvm) {
httpTargetConn.ele('URL', {}, "{" + apiProxy + "}")
} else if (options.backendurl) {
httpTargetConn.ele('URL', {}, options.backendurl)
} else {
if (api.openapi) {
Expand Down
58 changes: 58 additions & 0 deletions lib/policy_templates/kvm/getKvmEntry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
Copyright 2022 Google LLC

Licensed 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

https://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.
*/

var builder = require('xmlbuilder')
var random = require('../../util/random.js')

module.exports = {
getKvmEntry: getKvmEntry,
getKvmGenEntry: getKvmGenEntry
}

function getKvmEntry (options) {
var name = options.name || 'getKvmEntry-' + random.randomText()
var aysnc = options.async || 'false'
var continueOnError = options.continueOnError || 'false'
var enabled = options.enabled || 'true'
var kvmName = options.kvm
var apiName = options.apiName



var keyValueMapOperations = builder.create('KeyValueMapOperations')
keyValueMapOperations.att('async', aysnc)
keyValueMapOperations.att('continueOnError', continueOnError)
keyValueMapOperations.att('enabled', enabled)
keyValueMapOperations.att('name', name)
keyValueMapOperations.att('mapIdentifier', kvmName)
keyValueMapOperations.ele('DisplayName', {}, 'Get Target Endpoint')
keyValueMapOperations.ele('ExclusiveCache', {}, false)
keyValueMapOperations.ele('ExpiryTimeInSecs', {}, 300)
keyValueMapOperations.ele('Get')
.att('assignTo', apiName)
.att('index', 1)
.ele("Key")
.ele("Parameter", {}, apiName)
keyValueMapOperations.ele('Scope', {}, "environment")
var xmlString = keyValueMapOperations.end({ pretty: true, indent: ' ', newline: '\n' })
return xmlString
}

function getKvmGenEntry (options, name) {
var templateOptions = options
templateOptions.name = name || 'getKvmEntry'
return getKvmEntry(templateOptions)
}