Skip to content

Commit

Permalink
Fixing few minor formatting issues (#703)
Browse files Browse the repository at this point in the history
* Added more unit tests
* fixing few formatting issues
  • Loading branch information
devsatishm authored Dec 26, 2018
1 parent 2930e19 commit 659c4c6
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 134 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ language: node_js
node_js:
- "node"
env:
- PLATFORM_SERVICE=core/jazz_admin
- PLATFORM_SERVICE=core/jazz_asset-event-handler
- PLATFORM_SERVICE=core/jazz_assets
- PLATFORM_SERVICE=core/jazz_codeq
- PLATFORM_SERVICE=core/jazz_create-serverless-service
- PLATFORM_SERVICE=core/jazz_delete-serverless-service
- PLATFORM_SERVICE=core/jazz_deployments
- PLATFORM_SERVICE=core/jazz_deployments-event-handler
- PLATFORM_SERVICE=core/jazz_environments
- PLATFORM_SERVICE=core/jazz_email
- PLATFORM_SERVICE=core/jazz_environment-event-handler
- PLATFORM_SERVICE=core/jazz_environments
- PLATFORM_SERVICE=core/jazz_events
- PLATFORM_SERVICE=core/jazz_events-handler
- PLATFORM_SERVICE=core/jazz_is-service-available
- PLATFORM_SERVICE=core/jazz_is-slack-channel-available
- PLATFORM_SERVICE=core/jazz_login
Expand All @@ -24,6 +27,7 @@ env:
- PLATFORM_SERVICE=core/jazz_slack-channel
- PLATFORM_SERVICE=core/jazz_slack-event-handler
- PLATFORM_SERVICE=core/jazz_test-lambda
- PLATFORM_SERVICE=core/jazz_usermanagement

before_script:
- npm prune
Expand Down
66 changes: 33 additions & 33 deletions builds/delete-serverless-service-build-pack/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,10 @@ def unDeployService(stage) {
]) {
try {
def randomString = utilModule.generateRequestId();
def cloudApi = "jazz-${randomString}";
sh "aws configure set profile.${cloudApi}.region ${configLoader.AWS.REGION}"
sh "aws configure set profile.${cloudApi}.aws_access_key_id $AWS_ACCESS_KEY_ID"
sh "aws configure set profile.${cloudApi}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY"
def credsId = "jazz-${randomString}";
sh "aws configure set profile.${credsId}.region ${configLoader.AWS.REGION}"
sh "aws configure set profile.${credsId}.aws_access_key_id $AWS_ACCESS_KEY_ID"
sh "aws configure set profile.${credsId}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY"

def env_key
if (stage.endsWith("-dev")) {
Expand All @@ -353,7 +353,7 @@ def unDeployService(stage) {

echo "Service undeployed"

resetCredentials(cloudApi)
resetCredentials(credsId)
} catch (ex) {
handleFailureEvent(ex.getMessage())
}
Expand Down Expand Up @@ -499,10 +499,10 @@ def cleanUpApiGatewayResources(stage, path) {
]) {
try {
def randomString = utilModule.generateRequestId();
def cloudApi = "jazz-${randomString}";
sh "aws configure set profile.${cloudApi}.region ${configLoader.AWS.REGION}"
sh "aws configure set profile.${cloudApi}.aws_access_key_id $AWS_ACCESS_KEY_ID"
sh "aws configure set profile.${cloudApi}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY"
def credsId = "jazz-${randomString}";
sh "aws configure set profile.${credsId}.region ${configLoader.AWS.REGION}"
sh "aws configure set profile.${credsId}.aws_access_key_id $AWS_ACCESS_KEY_ID"
sh "aws configure set profile.${credsId}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY"

def resource_id = null
def resource_search_key
Expand Down Expand Up @@ -548,7 +548,7 @@ def cleanUpApiGatewayResources(stage, path) {
} else {
echo "Resource Id does not exist in API gateway."
}
resetCredentials(cloudApi)
resetCredentials(credsId)
} catch (ex) {
handleFailureEvent(ex.getMessage())
}
Expand Down Expand Up @@ -610,13 +610,13 @@ def cleanUpApiDocs(stage) {
]) {
try {
def randomString = utilModule.generateRequestId();
def cloudApi = "jazz-${randomString}";
sh "aws configure set profile.${cloudApi}.region ${configLoader.AWS.REGION}"
sh "aws configure set profile.${cloudApi}.aws_access_key_id $AWS_ACCESS_KEY_ID"
sh "aws configure set profile.${cloudApi}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY"
def credsId = "jazz-${randomString}";
sh "aws configure set profile.${credsId}.region ${configLoader.AWS.REGION}"
sh "aws configure set profile.${credsId}.aws_access_key_id $AWS_ACCESS_KEY_ID"
sh "aws configure set profile.${credsId}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY"
def apiRootFolder = getApiDocsFolder(stage)
sh "aws s3 rm s3://${apiRootFolder}/${service_config['domain']}/${service_config['service']}/${stage} --recursive"
resetCredentials(cloudApi)
resetCredentials(credsId)
} catch (ex) {
handleFailureEvent(ex.getMessage())
}
Expand Down Expand Up @@ -717,10 +717,10 @@ def unDeployWebsite(stage) {
]) {
try {
def randomString = utilModule.generateRequestId();
def cloudApi = "jazz-${randomString}";
sh "aws configure set profile.${cloudApi}.region ${configLoader.AWS.REGION}"
sh "aws configure set profile.${cloudApi}.aws_access_key_id $AWS_ACCESS_KEY_ID"
sh "aws configure set profile.${cloudApi}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY"
def credsId = "jazz-${randomString}";
sh "aws configure set profile.${credsId}.region ${configLoader.AWS.REGION}"
sh "aws configure set profile.${credsId}.aws_access_key_id $AWS_ACCESS_KEY_ID"
sh "aws configure set profile.${credsId}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY"
sh "aws configure set preview.cloudfront true"

def assetInfo = generateAssetInfo(stage)
Expand All @@ -746,7 +746,7 @@ def unDeployWebsite(stage) {
sh "aws s3 rm s3://${assetInfo['folder_name']} --recursive"
}
}
resetCredentials(cloudApi)
resetCredentials(credsId)
} catch (ex) {
handleFailureEvent(ex.getMessage())
}
Expand Down Expand Up @@ -806,10 +806,10 @@ def cleanupS3BucketPolicy(stage, assetInfo) {
]) {
try {
def randomString = utilModule.generateRequestId();
def cloudApi = "jazz-${randomString}";
sh "aws configure set profile.${cloudApi}.region ${configLoader.AWS.REGION}"
sh "aws configure set profile.${cloudApi}.aws_access_key_id $AWS_ACCESS_KEY_ID"
sh "aws configure set profile.${cloudApi}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY"
def credsId = "jazz-${randomString}";
sh "aws configure set profile.${credsId}.region ${configLoader.AWS.REGION}"
sh "aws configure set profile.${credsId}.aws_access_key_id $AWS_ACCESS_KEY_ID"
sh "aws configure set profile.${credsId}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY"
sh "aws configure set preview.cloudfront true"
def bucketPolicy = sh(
script: "aws s3api get-bucket-policy --bucket ${assetInfo['s3Bucket']} --output json",
Expand All @@ -834,7 +834,7 @@ def cleanupS3BucketPolicy(stage, assetInfo) {
def policy_json = JsonOutput.toJson(policyObjectUpdated)
updateBucketPolicy(policy_json, assetInfo['s3Bucket'])
}
resetCredentials(cloudApi)
resetCredentials(credsId)
} catch (ex) {
resetCredentials()
if (ex.getMessage().indexOf("groovy.json.internal.LazyMap") < 0) {
Expand All @@ -846,10 +846,10 @@ def cleanupS3BucketPolicy(stage, assetInfo) {

/** Reset credentials
*/
def resetCredentials(cloudApi) {
def resetCredentials(credsId) {
echo "resetting AWS credentials"
sh "aws configure set profile.${cloudApi}.aws_access_key_id XXXXXXXXXXXXXXXXXXXXXXXXXX"
sh "aws configure set profile.${cloudApi}.aws_secret_access_key XXXXXXXXXXXXXXXXXXXXXX"
sh "aws configure set profile.${credsId}.aws_access_key_id XXXXXXXXXXXXXXXXXXXXXXXXXX"
sh "aws configure set profile.${credsId}.aws_secret_access_key XXXXXXXXXXXXXXXXXXXXXX"
}
@NonCPS
def updateBucketPolicy(policy_json, bucketName){
Expand All @@ -875,10 +875,10 @@ def cleanupCloudFrontDistribution(stage) {
]) {
try {
def randomString = utilModule.generateRequestId();
def cloudApi = "jazz-${randomString}";
sh "aws configure set profile.${cloudApi}.region ${configLoader.AWS.REGION}"
sh "aws configure set profile.${cloudApi}.aws_access_key_id $AWS_ACCESS_KEY_ID"
sh "aws configure set profile.${cloudApi}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY"
def credsId = "jazz-${randomString}";
sh "aws configure set profile.${credsId}.region ${configLoader.AWS.REGION}"
sh "aws configure set profile.${credsId}.aws_access_key_id $AWS_ACCESS_KEY_ID"
sh "aws configure set profile.${credsId}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY"
sh "aws configure set preview.cloudfront true"

def distributionID
Expand All @@ -891,7 +891,7 @@ def cleanupCloudFrontDistribution(stage) {
_Etag = generateDistributionConfigForDisable(distributionConfig)
_Etag = disableCloudFrontDistribution(distributionID, _Etag, "disable-cf-distribution-config.json", stage)
}
resetCredentials(cloudApi)
resetCredentials(credsId)
} catch (ex) {
if ((ex.getMessage()).indexOf("getDistributionId Failed") > -1) {
echo "Could not find a CloudFront distribution Id for service: ${service_config['service']} and environment $stage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ def loadServiceConfigurationData() {
sh "sed -i -- 's/{conf-region}/${region}/g' ./config/local-config.json"
}


if (service_name.trim() == "jazz_is-service-available") {
sh "sed -i -- 's/{inst_stack_prefix}/${config_loader.INSTANCE_PREFIX}/g' ./config/dev-config.json"
sh "sed -i -- 's/{inst_stack_prefix}/${config_loader.INSTANCE_PREFIX}/g' ./config/stg-config.json"
Expand Down
72 changes: 31 additions & 41 deletions builds/jenkins-build-pack-api/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ node() {

def internalAccess = config['require_internal_access']

// @TODO: the below statement will be replaced with regular expression in very near future;
def roleId = config['iamRoleARN'].substring(config['iamRoleARN'].indexOf("::") + 2, config['iamRoleARN'].lastIndexOf(":"))

sonarModule.initialize(configLoader, config, branch)
Expand Down Expand Up @@ -219,12 +218,11 @@ node() {
environmentDeploymentMetadata.setEnvironmentEndpoint(endpointUrl)
events.sendStartedEvent('UPDATE_ENVIRONMENT', "Environment status update event for ${env_key} deployment", environmentDeploymentMetadata.generateEnvironmentMap("deployment_started", environment_logical_id, null), environment_logical_id)
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: configLoader.AWS_CREDENTIAL_ID, secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
echo "AWS Configure ......."
def randomString = utilModule.generateRequestId();
def cloudApi = "jazz-${randomString}";
sh "aws configure set profile.${cloudApi}.region ${configLoader.AWS.REGION}"
sh "aws configure set profile.${cloudApi}.aws_access_key_id $AWS_ACCESS_KEY_ID"
sh "aws configure set profile.${cloudApi}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY"
def credsId = "jazz-${randomString}";
sh "aws configure set profile.${credsId}.region ${configLoader.AWS.REGION}"
sh "aws configure set profile.${credsId}.aws_access_key_id $AWS_ACCESS_KEY_ID"
sh "aws configure set profile.${credsId}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY"

// Generate serverless yml file with domain added in function name
echo "Generate deployment env with domain for ${env_key}"
Expand All @@ -237,7 +235,7 @@ node() {
def envBucketKey = "${env_key}${configLoader.JAZZ.S3_BUCKET_NAME_SUFFIX}"
sh "serverless deploy --stage ${environment_logical_id} -v --bucket ${configLoader.AWS.S3[envBucketKey]}"

def lambdaARN = getLambdaARN(stackName, cloudApi);
def lambdaARN = getLambdaARN(stackName, credsId);
events.sendCompletedEvent('CREATE_ASSET', null, utilModule.generateAssetMap("aws", lambdaARN, "lambda", config), environment_logical_id);

if (fileExists('swagger/swagger.json')) {
Expand All @@ -257,9 +255,9 @@ node() {
sh "cat swagger/swagger.json "

echo "Deploying to API Gateway environment.."
sh "aws apigateway put-rest-api --rest-api-id ${aws_api_id} --mode merge --parameters basepath=prepend --body 'file://swagger/swagger.json'" + " --profile ${cloudApi}"
sh "aws apigateway create-deployment --rest-api-id ${aws_api_id} --stage-name ${current_environment} --profile ${cloudApi}"
sh "aws apigateway tag-resource --resource-arn arn:aws:apigateway:${configLoader.AWS.REGION}::/restapis/${aws_api_id}/stages/${current_environment} --tags Application=Jazz,JazzInstance=${configLoader.INSTANCE_PREFIX} --profile ${cloudApi}"
sh "aws apigateway put-rest-api --rest-api-id ${aws_api_id} --mode merge --parameters basepath=prepend --body 'file://swagger/swagger.json'" + " --profile ${credsId}"
sh "aws apigateway create-deployment --rest-api-id ${aws_api_id} --stage-name ${current_environment} --profile ${credsId}"
sh "aws apigateway tag-resource --resource-arn arn:aws:apigateway:${configLoader.AWS.REGION}::/restapis/${aws_api_id}/stages/${current_environment} --tags Application=Jazz,JazzInstance=${configLoader.INSTANCE_PREFIX} --profile ${credsId}"

if("${configLoader.JAZZ.API_DETAILED_MONITORING}" == "true") {
sh "aws apigateway update-stage --rest-api-id ${aws_api_id} --stage-name ${current_environment} --patch-operations op=replace,path=/*/*/metrics/enabled,value=true --region ${configLoader.AWS.REGION}"
Expand Down Expand Up @@ -292,13 +290,12 @@ node() {
events.sendCompletedEvent('CREATE_ASSET', null, utilModule.generateAssetMap("aws", swaggerDocUrl, "swagger_url", config), environment_logical_id);

def svc_status = "Your service endpoint for ${current_environment} environment: ${endpointUrl} \n\nView and test your API here: ${configLoader.JAZZ.SWAGGER.EDITOR_URL}${swaggerDocUrl}"
send_status_email(config, 'COMPLETED', svc_status)
send_status_email(config, 'COMPLETED', svc_status)
}
resetCredentials(cloudApi)
resetCredentials(credsId)

if (domain && domain == "jazz") {
serviceConfigdata.setLogStreamPermission(config)

}
}
} catch (ex) {
Expand All @@ -321,11 +318,11 @@ node() {
}//dir ends here
}

def getLambdaARN(String stackName, cloudApi) {
def getLambdaARN(stackName, credsId) {
def ARN = "";
try {
def cloudformation_resources = "";
cloudformation_resources = sh(returnStdout: true, script: "aws cloudformation describe-stacks --output json --stack-name ${stackName} --profile ${cloudApi}")
cloudformation_resources = sh(returnStdout: true, script: "aws cloudformation describe-stacks --output json --stack-name ${stackName} --profile ${credsId}")

def parsedObject = parseJson(cloudformation_resources);
def outputs = parsedObject.Stacks[0].Outputs;
Expand Down Expand Up @@ -494,17 +491,16 @@ def buildLambda(String runtime, String repo_name) {
. venv/bin/activate
pip install pytest
"""
} else if (runtime.indexOf("go") > -1 ) {
// Installing dependencies using dep ensure
// golang build scripts
withEnv(["GOPATH=${env.WORKSPACE}"]) {
sh "mkdir -p $GOPATH/src"
sh "rsync -a --exclude='.*' $GOPATH/" + repo_name + " $GOPATH/src"
sh "cd $GOPATH/src/" + repo_name + " && dep ensure"
sh "env GOOS=linux GOARCH=amd64 go build -o main $GOPATH/src/" + repo_name + "/main.go"
}
}
else if (runtime.indexOf("go") > -1 ){
//Installing dependencies using dep ensure
//golang build scripts
withEnv(["GOPATH=${env.WORKSPACE}"]) {
sh "mkdir -p $GOPATH/src"
sh "rsync -a --exclude='.*' $GOPATH/"+ repo_name+" $GOPATH/src"
sh "cd $GOPATH/src/"+ repo_name+" && dep ensure"
sh "env GOOS=linux GOARCH=amd64 go build -o main $GOPATH/src/"+ repo_name+"/main.go"
}
}
}


Expand Down Expand Up @@ -563,10 +559,10 @@ def setLambdaExecutionRole(role) {
/**
Reset credentials
*/
def resetCredentials(cloudApi) {
echo "resetting AWS credentials"
sh "aws configure set profile.${cloudApi}.aws_access_key_id XXXXXXXXXXXXXXXXXXXXXXXXXX"
sh "aws configure set profile.${cloudApi}.aws_secret_access_key XXXXXXXXXXXXXXXXXXXXXX"
def resetCredentials(credsId) {
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"
}

/**
Expand Down Expand Up @@ -667,15 +663,10 @@ def loadServerlessConfig(config) {
} else if (config['providerRuntime'].indexOf("python") > -1) {
sh "cp _config/serverless-python.yml ./serverless.yml"
} else if (config['providerRuntime'].indexOf("go") > -1) {
sh "cp _config/serverless-go.yml ./serverless.yml"
}

if ((config['service'] == 'cloud-logs-streamer' || config['service'] == 'logs') && config['domain'] == 'jazz') {
//addVpcDetails()
sh "cp _config/serverless-go.yml ./serverless.yml"
}

removeEventResources()


removeEventResources()
echoServerlessFile()
}

Expand Down Expand Up @@ -846,16 +837,15 @@ def send_status_email(config, build_status, email_content) {
/** Run validation based on runtime
*/
def runValidation(String runtime) {
echo "running validations for $runtime"
if (runtime.indexOf("nodejs") > -1) {
echo "running validations for $runtime"
sh "jshint *.js"
} else if (runtime.indexOf("java") > -1) {
echo "running validations for $runtime"
sh "java -cp ${configLoader.CODE_QUALITY.SONAR.CHECKSTYLE_LIB} com.puppycrawl.tools.checkstyle.Main -c sun_checks.xml src"
} else if (runtime.indexOf("python") > -1) {
echo "running validations for $runtime"
// placeholder for adding runtime specific validations
} else if (runtime.indexOf("go") > -1) {
echo "running validations for $runtime"
// placeholder for adding runtime specific validations
}
}

Expand Down
Loading

0 comments on commit 659c4c6

Please sign in to comment.