-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #932 from tmobile/develop
Release v1.15 - Manage ACL for Jazz services
- Loading branch information
Showing
188 changed files
with
19,428 additions
and
11,215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!groovy? | ||
import groovy.json.JsonSlurperClassic | ||
import groovy.json.JsonOutput | ||
|
||
def updateServiceACL(serviceId, auth_token, aclUrl, user) { | ||
try { | ||
def categoryList = ['manage','code', 'deploy'] | ||
def policiesList = [] | ||
|
||
for (category in categoryList) { | ||
def permission = 'write'; | ||
if(category == 'manage') permission = 'admin' | ||
def eachPolicy = [ | ||
userId: user, | ||
permission: permission, | ||
category: category | ||
] | ||
policiesList.add(eachPolicy) | ||
} | ||
echo "policiesList: $policiesList" | ||
|
||
def body = JsonOutput.toJson([ | ||
serviceId: serviceId, | ||
policies: policiesList | ||
]); | ||
def updatePermission = sh(script: "curl POST \ | ||
${aclUrl} \ | ||
-k -v -H \"Authorization: $auth_token\" \ | ||
-H \"Jazz-Service-ID: ${serviceId}\" \ | ||
-H \"Content-Type: application/json\" \ | ||
-d \'${body}\'", returnStdout: true).trim() | ||
def responseJSON = parseJson(updatePermission) | ||
|
||
if (responseJSON && responseJSON.data && responseJSON.data instanceof Object && responseJSON.data.success == true) { | ||
echo "Successfully updated service policies." | ||
} else { | ||
echo "Something went wrong while updating service policies. Error: ${responseJSON.data}" | ||
error responseJSON.data | ||
} | ||
} catch (ex) { | ||
echo "ex: $ex" | ||
error ex.getMessage() | ||
} | ||
} | ||
|
||
|
||
def deletePolicies(serviceId, auth_token, aclUrl) { | ||
try { | ||
def body = JsonOutput.toJson([ | ||
serviceId: serviceId, | ||
policies: [] | ||
]); | ||
def updatePermission = sh(script: "curl POST \ | ||
${aclUrl} \ | ||
-k -v -H \"Authorization: $auth_token\" \ | ||
-H \"Jazz-Service-ID: ${serviceId}\" \ | ||
-H \"Content-Type: application/json\" \ | ||
-d \'${body}\'", returnStdout: true).trim() | ||
def responseJSON = parseJson(updatePermission) | ||
|
||
if (responseJSON && responseJSON.data && responseJSON.data instanceof Object && responseJSON.data.success == true) { | ||
echo "Successfully deleted service policies." | ||
} else { | ||
echo "Something went wrong while deleting service policies. Error: ${responseJSON.data}" | ||
error responseJSON.data | ||
} | ||
} catch(ex) { | ||
echo "ex: $ex" | ||
error ex.getMessage() | ||
} | ||
} | ||
|
||
@NonCPS | ||
def parseJson(jsonString) { | ||
def lazyMap = new groovy.json.JsonSlurperClassic().parseText(jsonString) | ||
def m = [:] | ||
m.putAll(lazyMap) | ||
return m | ||
} | ||
|
||
return this |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,78 @@ | ||
#!groovy | ||
import groovy.transform.Field | ||
import groovy.json.JsonSlurperClassic | ||
|
||
echo "aws-apigateway.groovy module loaded successfully" | ||
|
||
@Field def genericAmazonIntegration | ||
@Field def optionsAmazonIntegration | ||
|
||
def initialize() { | ||
genericAmazonIntegration = readFile("aws/apigateway-lambda-integration-specs/amazon-swagger-spec-generic.txt"); | ||
optionsAmazonIntegration = readFile("aws/apigateway-lambda-integration-specs/amazon-swagger-spec-options.txt"); | ||
genericAmazonIntegration = readFile("aws/apigateway-lambda-integration-specs/amazon-swagger-spec-generic.txt"); | ||
optionsAmazonIntegration = readFile("aws/apigateway-lambda-integration-specs/amazon-swagger-spec-options.txt"); | ||
} | ||
|
||
def writeTempFiles() { | ||
writeFile file: 'optionsSpecTemp.txt', text: optionsAmazonIntegration; | ||
writeFile file: 'genericSpecTemp.txt', text: genericAmazonIntegration; | ||
writeFile file: 'optionsSpecTemp.txt', text: optionsAmazonIntegration; | ||
writeFile file: 'genericSpecTemp.txt', text: genericAmazonIntegration; | ||
} | ||
|
||
def addApigatewayLambdaIntegration(filePath) { | ||
try { | ||
writeTempFiles(); | ||
def httpVerbs = ['get', 'post', 'delete', 'put', 'connect', 'head', 'options', 'patch', 'trace']; | ||
for (verb in httpVerbs) { | ||
injectLambdaIntegration(verb, filePath); | ||
} | ||
} catch (ex) { | ||
echo "error in lambda integration" | ||
error ex.getMessage(); | ||
} finally { | ||
if (fileExists('optionsSpecTemp.txt')) { | ||
sh "rm -rf optionsSpecTemp.txt" | ||
} | ||
if (fileExists('genericSpecTemp.txt')) { | ||
sh "rm -rf genericSpecTemp.txt" | ||
try { | ||
writeTempFiles(); | ||
FindUserDefinedIntegrationSpec(filePath) | ||
} catch (ex) { | ||
echo "error in lambda integration" | ||
error ex.getMessage(); | ||
} finally { | ||
if (fileExists('optionsSpecTemp.txt')) { | ||
sh "rm -rf optionsSpecTemp.txt" | ||
} | ||
if (fileExists('genericSpecTemp.txt')) { | ||
sh "rm -rf genericSpecTemp.txt" | ||
} | ||
} | ||
} | ||
|
||
// Find user defined 'x-amazon-apigateway-integration' for each method, if doesn't exist inject default one. | ||
def FindUserDefinedIntegrationSpec(filePath) { | ||
try { | ||
def swaggerStr = readFile(filePath).trim() | ||
def parsed_json = parseJson(swaggerStr) | ||
def keys = parsed_json.keySet() as String[]; | ||
def keys_of_paths = parsed_json.paths.keySet(); | ||
|
||
for (key_of_a_path in keys_of_paths) { | ||
def methods_of_each_path = parsed_json.paths[key_of_a_path].keySet() | ||
for (method in methods_of_each_path) { | ||
def temp = parsed_json.paths[key_of_a_path][method] | ||
if (!temp["x-amazon-apigateway-integration"]) { | ||
echo "x-amazon-apigateway-integration does not exist." | ||
injectLambdaIntegration(method, filePath); | ||
} | ||
} | ||
} | ||
} catch (ex) { | ||
echo " FindUserDefinedIntegrationSpec :::: Error occurred " + ex.getMessage() | ||
error " FindUserDefinedIntegrationSpec :::: Error occurred " + ex.getMessage() | ||
} | ||
} | ||
|
||
@NonCPS | ||
def parseJson(jsonString) { | ||
def lazyMap = new groovy.json.JsonSlurperClassic().parseText(jsonString) | ||
def m = [: ] | ||
m.putAll(lazyMap) | ||
return m | ||
} | ||
|
||
def injectLambdaIntegration(method, filePath) { | ||
|
||
echo "Injecting Amazon Api Gateway lambda integration spec" | ||
if (method == 'options') { | ||
sh "sed -i '/\"$method\":.*{/ r optionsSpecTemp.txt' $filePath" | ||
} else { | ||
sh "sed -i '/\"$method\":.*{/ r genericSpecTemp.txt' $filePath" | ||
} | ||
echo "Injecting Amazon Api Gateway lambda integration spec" | ||
if (method == 'options') { | ||
sh "sed -i '/\"$method\":.*{/ r optionsSpecTemp.txt' $filePath" | ||
} else { | ||
sh "sed -i '/\"$method\":.*{/ r genericSpecTemp.txt' $filePath" | ||
} | ||
} | ||
|
||
return this; | ||
return this; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.