Skip to content

Commit

Permalink
Merge pull request #711 from tmobile/develop
Browse files Browse the repository at this point in the history
Release - v1.12
  • Loading branch information
suryajak authored Jan 10, 2019
2 parents b70451d + 7066988 commit 5afa9bf
Show file tree
Hide file tree
Showing 26 changed files with 178 additions and 113 deletions.
28 changes: 12 additions & 16 deletions builds/delete-serverless-service-build-pack/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ node {
}


auth_token = setCredentials()
auth_token = getAuthToken()

stage("Initialization") {

Expand Down Expand Up @@ -847,9 +847,9 @@ def cleanupS3BucketPolicy(stage, assetInfo) {
/** Reset credentials
*/
def resetCredentials(credsId) {
echo "resetting AWS credentials"
echo "resetting AWS credentials"
sh "aws configure set profile.${credsId}.aws_access_key_id XXXXXXXXXXXXXXXXXXXXXXXXXX"
sh "aws configure set profile.${credsId}.aws_secret_access_key XXXXXXXXXXXXXXXXXXXXXX"
sh "aws configure set profile.${credsId}.aws_secret_access_key XXXXXXXXXXXXXXXXXXXXXX"
}
@NonCPS
def updateBucketPolicy(policy_json, bucketName){
Expand Down Expand Up @@ -1091,32 +1091,28 @@ def removeEventResources() {
* For getting token to access catalog APIs.
* Must be a service account which has access to all services
*/
def setCredentials() {
def url = g_base_url + '/jazz/login'
def getAuthToken() {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: g_svc_admin_cred_ID, passwordVariable: 'PWD', usernameVariable: 'UNAME']]) {
echo "user name is $UNAME"
def login_json = []
login_json = [
def loginUrl = g_base_url + "/jazz/login"
def login_json = [
'username': UNAME,
'password': PWD
]
def tokenJson_token = null
def payload = JsonOutput.toJson(login_json)
try {
def token = sh(script: "curl --silent -X POST -k -v \
-H \"Content-Type: application/json\" \
$url \
-d \'${payload}\'", returnStdout: true).trim()
$loginUrl \
-d \'${payload}\'", returnStdout:true).trim()

def tokenJson = jsonParse(token)
tokenJson_token = tokenJson.data.token

return tokenJson_token
return tokenJson.data.token
}
catch (e) {
echo "Failed to fetch authentication details."
error "Failed while getting auth token for user: $UNAME, error: " + e.getMessage()
}
}

}

/**
Expand Down Expand Up @@ -1160,7 +1156,7 @@ def send_status_email(build_status) {
try {
def sendMail = sh(script: "curl -X POST \
${g_base_url}/jazz/email \
-k -v -H \"Authorization: $g_login_token\" \
-k -v -H \"Authorization: $auth_token\" \
-H \"Content-Type: application/json\" \
-d \'${body}\'", returnStdout: true).trim()
def responseJSON = parseJsonMap(sendMail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def setEventSourceMapping(eventSourceArn, config) {
).trim()
echo "$event_source_list"
if (event_source_list == "[]") {
sh "aws lambda create-event-source-mapping --event-source-arn ${eventSourceArn} --function-name arn:aws:lambda:$region:$role_id:function:$function_name --starting-position LATEST --region $region"
sh "aws lambda create-event-source-mapping --event-source-arn ${eventSourceArn} --function-name arn:aws:lambda:$region:$role_id:function:$function_name --enabled --starting-position LATEST --region $region"
}
}

Expand Down
41 changes: 27 additions & 14 deletions builds/jenkins-build-pack-api/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ node() {
endpointUrl = "https://${apiHostName}/${current_environment}/${environment_logical_id}/${config['domain']}/${config['service']}"
}

def apiArns = getAPIGatewayResourceARNs(aws_api_id, environment_logical_id)
def apiArns = getAPIGatewayResourceARNs(aws_api_id, current_environment)
if(apiArns) {
for (arn in apiArns) {
events.sendCompletedEvent('CREATE_ASSET', null, utilModule.generateAssetMap("aws", arn, "apigateway", config), environment_logical_id);
Expand Down Expand Up @@ -480,17 +480,31 @@ def buildLambda(String runtime, String repo_name) {
} else if (runtime.indexOf("java") > -1) {
sh "mvn package"
} else if (runtime.indexOf("python") > -1) {
// install requirements.txt in library folder, these python modules
// will be a part of deployment package
sh "pip install -r requirements.txt -t library"

// create virtual environment and install dev-requirements
sh """
pip install virtualenv
virtualenv venv
. venv/bin/activate
pip install pytest
"""
// install requirements.txt in library folder, these python modules will be a part of deployment package
sh "rm -rf library"
sh "mkdir library"
sh "touch library/__init__.py"
if (runtime == 'python3.6') {
//Installing dependencies
sh "pip3 install -r requirements.txt -t library"
// create virtual environment and install pytest
sh """
python3 -m venv virtualenv
. virtualenv/bin/activate
pip3 install pytest
pytest test
"""
} else {
//Installing dependencies
sh "pip install -r requirements.txt -t library"
// create virtual environment and install pytest
sh """
pip install virtualenv
virtualenv venv
. venv/bin/activate
pip install pytest
"""
}
} else if (runtime.indexOf("go") > -1 ) {
// Installing dependencies using dep ensure
// golang build scripts
Expand All @@ -503,7 +517,6 @@ def buildLambda(String runtime, String repo_name) {
}
}


/**
Generate the swagger file specific to each environment
*/
Expand Down Expand Up @@ -586,7 +599,7 @@ def validateDeploymentConfigurations(def prop) {
error "Wrong configuration. Value for Key 'providerRuntime' is missing in the configuration"

} else {
def validRuntimes = ["nodejs4.3", "nodejs6.10", "nodejs8.10", "python2.7", "java8", "go1.x"]
def validRuntimes = ["nodejs4.3", "nodejs6.10", "nodejs8.10", "python2.7", "python3.6", "java8", "go1.x"]
def flag = false
for (int i = 0; i < validRuntimes.size(); i++) {
if (_runtime == validRuntimes[i]) {
Expand Down
34 changes: 24 additions & 10 deletions builds/jenkins-build-pack-lambda/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -530,18 +530,32 @@ def buildLambda(String runtime, String repo_name) {
} else if (runtime.indexOf("java") > -1) {
sh "mvn package"
} else if (runtime.indexOf("python") > -1) {
// install requirements.txt in library folder, these python modules will be a part of deployment package
// install requirements.txt in library folder, these python modules will be a part of deployment package
sh "rm -rf library"
sh "mkdir library"
sh "pip install -r requirements.txt -t library"
sh "touch library/__init__.py"
// create virtual environment and install pytest
sh """
pip install virtualenv
virtualenv venv
. venv/bin/activate
pip install pytest
"""

if (runtime == 'python3.6'){
// Installing dependencies
sh "pip3 install -r requirements.txt -t library"
// create virtual environment and install pytest
sh """
python3 -m venv virtualenv
. virtualenv/bin/activate
pip3 install pytest
pytest test
"""
} else {
// Installing dependencies
sh "pip install -r requirements.txt -t library"
// create virtual environment and install pytest
sh """
pip install virtualenv
virtualenv venv
. venv/bin/activate
pip install pytest
"""
}
} else if (runtime.indexOf("go") > -1 ) {
// Installing dependencies using dep ensure
// golang build scripts
Expand Down Expand Up @@ -578,7 +592,7 @@ def validateDeploymentConfigurations(def prop) {
if (_runtime == "") {
error "Wrong configuration. Value for Key 'providerRuntime' is missing in the configuration"
} else {
def validRuntimes = ["nodejs4.3", "nodejs6.10", "nodejs8.10", "python2.7", "java8", "go1.x"]
def validRuntimes = ["nodejs4.3", "nodejs6.10", "nodejs8.10", "python2.7", "python3.6", "java8", "go1.x"]
def flag = false

for (int i = 0; i < validRuntimes.size(); i++) {
Expand Down
42 changes: 17 additions & 25 deletions builds/service-onboarding-build-pack/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,51 +66,47 @@ node {

events.sendStartedEvent("VALIDATE_INPUT", 'input validation starts', context_map)
if (service_config['type'] == "api" || service_config['type'] == "function" || service_config['type'] == "website") {
if (service_config['runtime'] == "nodejs" || service_config['runtime'] == "python" || service_config['runtime'] == "java" || service_config['runtime'] == "go1.x" || service_config['runtime'] == "n/a") {

if (service_config['runtime'].startsWith("nodejs") || service_config['runtime'].startsWith("python") || service_config['runtime'].startsWith("java") || service_config['runtime'].startsWith("go") || service_config['runtime'] == "n/a") {
switch (service_config['type']) {
case "api":
if (service_config['runtime'] == "nodejs") {
if (service_config['runtime'].startsWith("nodejs")) {
service_template = "api-template-nodejs"
}
else if (service_config['runtime'] == "python") {
service_template = 'api-template-python'
else if (service_config['runtime'].startsWith("python")){
service_template = 'api-template-python'
}
else if (service_config['runtime'] == "java") {
else if (service_config['runtime'].startsWith("java")) {
service_template = 'api-template-java'
}
else if (service_config['runtime'] == "go1.x") {
else if (service_config['runtime'].startsWith("go")) {
service_template = 'api-template-go'
}
break

case "function":
if (service_config['runtime'] == "nodejs") {
if (service_config['runtime'].startsWith("nodejs")) {
service_template = "lambda-template-nodejs"
}
else if (service_config['runtime'] == "python") {
service_template = 'lambda-template-python'
else if (service_config['runtime'].startsWith("python")){
service_template = 'lambda-template-python'
}
else if (service_config['runtime'] == "java") {
else if (service_config['runtime'].startsWith("java")) {
service_template = 'lambda-template-java'
}
else if (service_config['runtime'] == "go1.x") {
else if (service_config['runtime'].startsWith("go")) {
service_template = 'lambda-template-go'
}
break

case "website":
service_template = 'static-website-template'
break

}

} else {
send_status_email("FAILED")
events.sendFailureEvent('VALIDATE_INPUT', "Invalid runtime: ${service_config['runtime']}", context_map)
error "Invalid runtime: ${service_config['runtime']}"
}

} else {
send_status_email("FAILED")
events.sendFailureEvent('VALIDATE_INPUT', "Invalid service type", context_map)
Expand Down Expand Up @@ -282,6 +278,7 @@ node {
}
}
}

/**
* For getting token to access catalog APIs.
* Must be a service account which has access to all services
Expand All @@ -291,28 +288,23 @@ def getAuthToken() {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: g_svc_admin_cred_ID, passwordVariable: 'PWD', usernameVariable: 'UNAME']]) {

def loginUrl = g_base_url + "/jazz/login"
def login_json = []

login_json = [
def login_json = [
'username': UNAME,
'password': PWD
]
def tokenJson_token = null
def payload = JsonOutput.toJson(login_json)

try {
def token = sh(script: "curl --silent -X POST -k -v \
-H \"Content-Type: application/json\" \
$loginUrl \
-d \'${payload}\'", returnStdout:true).trim()

def tokenJson = jsonParse(token)
tokenJson_token = tokenJson.data.token

return tokenJson_token
return tokenJson.data.token
}
catch (e) {
error "error occured: " + e.getMessage()
error "Failed while getting auth token for user: $UNAME, error: " + e.getMessage()
}
}

Expand Down Expand Up @@ -395,7 +387,7 @@ def send_status_email (build_status) {
try {
def sendMail = sh(script: "curl -X POST \
${g_base_url}/jazz/email \
-k -v -H \"Authorization: $g_login_token\" \
-k -v -H \"Authorization: $auth_token\" \
-H \"Content-Type: application/json\" \
-d \'${body}\'", returnStdout: true).trim()
def responseJSON = parseJson(sendMail)
Expand Down
7 changes: 7 additions & 0 deletions core/jazz_create-serverless-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ var getServiceData = (service_creation_data, authToken, configData) => {
serviceMetadataObj.require_internal_access = service_creation_data.require_internal_access;
}

//Adding providerRuntime key in service catalog
if (service_creation_data.service_type === "api" || service_creation_data.service_type === "function") {
serviceMetadataObj.providerRuntime = service_creation_data.runtime;
}

// Pass the flag to enable authentication on API
if (service_creation_data.service_type === "api") {
serviceMetadataObj.enable_api_security = service_creation_data.enable_api_security || false;
Expand All @@ -244,6 +249,8 @@ var getServiceData = (service_creation_data, authToken, configData) => {
}
}



// Disabling require_internal_access and enable_api_security when is_public_endpoint is true
if (service_creation_data.service_type === "api" && service_creation_data.is_public_endpoint) {
serviceMetadataObj.require_internal_access = false;
Expand Down
9 changes: 5 additions & 4 deletions core/jazz_create-serverless-service/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,10 @@
"type": "string",
"description": "The runtime framework for executing your code",
"enum": [
"nodejs",
"java",
"python",
"nodejs8.10",
"java8",
"python2.7",
"python3.6",
"go1.x"
]
},
Expand All @@ -302,7 +303,7 @@
},
"username": {
"type": "string",
"description": "Username/NT ID for the service creator. This will be used for the bitbucket access"
"description": "Username of the service creator"
},
"slack_channel": {
"type": "string",
Expand Down
8 changes: 4 additions & 4 deletions core/jazz_metrics/components/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ function updateLambdaAsset(newAssetObj, relativeId, arnString) {
}

function updateApigatewayAsset(newAssetObj, relativeId, assetEnvironment) {

var parts = relativeId.split("/");

var apiId = parts[0];
Expand All @@ -216,10 +217,9 @@ function updateApigatewayAsset(newAssetObj, relativeId, assetEnvironment) {
var methodValue = parts[2];
newAssetObj.asset_name.Method = methodValue;

var resourceValue = "/" + parts[3];
if (parts[4]) {
resourceValue += "/" + parts[4];
}
// rest of the parts belong to the actual resource
resourceValue = "/" + parts.slice(3, parts.length).join("/")

newAssetObj.asset_name.Resource = resourceValue;
return newAssetObj;
}
Expand Down
2 changes: 1 addition & 1 deletion core/jazz_services/config/global-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"active",
"inactive"
],
"SERVICE_RUNTIMES": ["nodejs", "python", "java", "c#", "go1.x"],
"SERVICE_RUNTIMES": ["nodejs8.10", "python2.7", "python3.6", "java8", "go1.x"],
"TYPE_FIELD_KEY": "type",
"SERVICE_INTER_DEPENDENT_FIELDS_MAP": [
{
Expand Down
2 changes: 1 addition & 1 deletion core/jazz_services/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('platform_services', function() {
"domain" : "k!ngd0m",
"region" : "mewni",
"type" : "api",
"runtime" : "nodejs",
"runtime" : "nodejs8.10",
"created_by" : "g10$saryck",
"status" : "active"
},
Expand Down
Loading

0 comments on commit 5afa9bf

Please sign in to comment.