Skip to content

Commit

Permalink
Linter fixes and enable Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
Javy de Koning committed Apr 6, 2024
1 parent 3cc590f commit 16f3e28
Show file tree
Hide file tree
Showing 27 changed files with 133 additions and 172 deletions.
1 change: 1 addition & 0 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ENABLE_LINTERS:
- MARKDOWN_MARKDOWN_LINK_CHECK
- MARKDOWN_MARKDOWNLINT
- MARKDOWN_MARKDOWN_TABLE_FORMATTER
- PYTHON_RUFF
- SPELL_CSPELL
- TERRAFORM_TFLINT
- YAML_YAMLLINT
Expand Down
2 changes: 1 addition & 1 deletion samples/sample-ec2-java-app-codedeploy/scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

cd /home/ec2-user/server
sudo /usr/bin/java -jar -Dserver.port=80 \
*.jar > /dev/null 2> /dev/null < /dev/null &
*.jar >/dev/null 2>/dev/null </dev/null &
2 changes: 1 addition & 1 deletion samples/sample-ec2-java-app-codedeploy/scripts/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ echo "Waiting for 15 seconds before checking health.."
sleep 15

status_code=$(curl --write-out %{http_code} --silent --output /dev/null http://localhost:80)
if [[ "$status_code" -ne 200 ]] ; then
if [[ "$status_code" -ne 200 ]]; then
echo "App is not healthy - $status_code"
exit 1
else
Expand Down
33 changes: 16 additions & 17 deletions samples/sample-ec2-with-codedeploy/scripts/install-codedeploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ set -xe

## Code Deploy Agent Bootstrap Script ##

exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
exec > >(tee /var/log/user-data.log | logger -t user-data -s 2>/dev/console) 2>&1
AUTOUPDATE=false

function installdep(){
function installdep() {
if [ ${PLAT} = "ubuntu" ]; then
apt-get -y update
# Satisfying even Ubuntu older versions.
Expand All @@ -18,7 +18,7 @@ function installdep(){
fi
}

function platformize(){
function platformize() {
# Linux OS detection
if hash lsb_release; then
echo "Ubuntu server OS detected"
Expand All @@ -32,21 +32,20 @@ function platformize(){
fi
}


function execute(){
function execute() {
if [ ${PLAT} = "ubuntu" ]; then
cd /tmp/
wget https://aws-codedeploy-${REGION}.s3.${REGION}.amazonaws.com/latest/install
chmod +x ./install

if ./install auto; then
echo "Installation completed"
if ! ${AUTOUPDATE}; then
echo "Disabling Auto Update"
sed -i '/@reboot/d' /etc/cron.d/codedeploy-agent-update
chattr +i /etc/cron.d/codedeploy-agent-update
rm -f /tmp/install
fi
if ! ${AUTOUPDATE}; then
echo "Disabling Auto Update"
sed -i '/@reboot/d' /etc/cron.d/codedeploy-agent-update
chattr +i /etc/cron.d/codedeploy-agent-update
rm -f /tmp/install
fi
exit 0
else
echo "Installation script failed, please investigate"
Expand All @@ -61,12 +60,12 @@ function execute(){

if ./install auto; then
echo "Installation completed"
if ! ${AUTOUPDATE}; then
echo "Disabling auto update"
sed -i '/@reboot/d' /etc/cron.d/codedeploy-agent-update
chattr +i /etc/cron.d/codedeploy-agent-update
rm -f /tmp/install
fi
if ! ${AUTOUPDATE}; then
echo "Disabling auto update"
sed -i '/@reboot/d' /etc/cron.d/codedeploy-agent-update
chattr +i /etc/cron.d/codedeploy-agent-update
rm -f /tmp/install
fi
exit 0
else
echo "Installation script failed, please investigate"
Expand Down
2 changes: 1 addition & 1 deletion samples/sample-ec2-with-codedeploy/scripts/install-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ echo "<VirtualHost *:80>
ProxyRequests Off
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>" >> sudo /etc/httpd/conf/httpd.conf
</VirtualHost>" /etc/httpd/conf/httpd.conf >>sudo

# start the httpd service now and stop it until userdata
sudo service httpd start
Expand Down
3 changes: 2 additions & 1 deletion samples/sample-fargate-node-app/build/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG
docker push $REPOSITORY_URI:latest
docker push $REPOSITORY_URI:$IMAGE_TAG

tmp=$(mktemp); jq --arg REPOSITORY_URI "$REPOSITORY_URI" --arg IMAGE_TAG "$IMAGE_TAG" '.Parameters.Image = $REPOSITORY_URI+":"+$IMAGE_TAG' params/global.json > "$tmp" && mv "$tmp" params/global.json
tmp=$(mktemp)
jq --arg REPOSITORY_URI "$REPOSITORY_URI" --arg IMAGE_TAG "$IMAGE_TAG" '.Parameters.Image = $REPOSITORY_URI+":"+$IMAGE_TAG' params/global.json >"$tmp" && mv "$tmp" params/global.json
1 change: 0 additions & 1 deletion samples/sample-serverless-app/handler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json

def lambda_handler(event, context):
print(event)
Expand Down
1 change: 0 additions & 1 deletion src/lambda_codebase/account/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import boto3
from botocore.exceptions import ClientError
from cfn_custom_resource import ( # pylint: disable=unused-import
lambda_handler,
create,
update,
delete,
Expand Down
1 change: 0 additions & 1 deletion src/lambda_codebase/cross_region_bucket/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# ^ https://www.logilab.org/ticket/2481
import boto3
from cfn_custom_resource import ( # pylint: disable=unused-import
lambda_handler,
create,
update,
delete,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from dataclasses import dataclass
import boto3
from cfn_custom_resource import ( # pylint: disable=unused-import
lambda_handler,
create,
update,
delete,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import boto3
import jinja2
from cfn_custom_resource import ( # pylint: disable=unused-import
lambda_handler,
create,
update,
delete,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,3 @@
"""__init__
"""

from .configparser import read_config_files
from .vpc import delete_default_vpc
from .account import Account
from .support import Support, SupportLevel
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ def test_generates_without_input_and_output_artifacts(input_mock, output_mock, a
category='Build',
provider='CodeBuild',
)
assert not 'input_artifacts' in action.config
assert not 'output_artifacts' in action.config
assert 'input_artifacts' not in action.config
assert 'output_artifacts' not in action.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# pylint: skip-file

from mock import patch
from copy import deepcopy
from cdk_constructs.adf_codepipeline import Action
from aws_cdk import ( aws_codepipeline )
from adf_codepipeline_test_constants import BASE_MAP_PARAMS
Expand All @@ -20,7 +19,7 @@ def test_get_output_artifacts_no_base_output(base_output_name_mock, action_decl_
category='Build',
provider='CodeBuild',
)
assert not 'output_artifacts' in action.config
assert 'output_artifacts' not in action.config


@patch('cdk_constructs.adf_codepipeline._codepipeline.CfnPipeline.ActionDeclarationProperty')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# pylint: skip-file

import pytest
import os

from mock import patch
from aws_cdk import App
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ set -e
SKIP_BUILD=0

# Walk through the options passed to this script
for i in "$@"
do
for i in "$@"; do
case $i in
--no-build)
SKIP_BUILD=1
;;
*)
echo "Unknown option: $i"
exit 1
;;
--no-build)
SKIP_BUILD=1
;;
*)
echo "Unknown option: $i"
exit 1
;;
esac
done

Expand All @@ -34,16 +33,15 @@ fi

# Get list of regions supported by this application
echo "Determine which regions need to be prepared"
app_regions=`aws ssm get-parameters --names /adf/deployment/$ADF_DEPLOYMENT_MAP_SOURCE/$ADF_PROJECT_NAME/regions --with-decryption --output=text --query='Parameters[0].Value'`
app_regions=$(aws ssm get-parameters --names /adf/deployment/$ADF_DEPLOYMENT_MAP_SOURCE/$ADF_PROJECT_NAME/regions --with-decryption --output=text --query='Parameters[0].Value')
# Convert json list to bash list (space delimited regions)
regions="`echo $app_regions | sed -e 's/\[\([^]]*\)\]/\1/g' | sed 's/,/ /g' | sed "s/'//g"`"
regions="$(echo $app_regions | sed -e 's/\[\([^]]*\)\]/\1/g' | sed 's/,/ /g' | sed "s/'//g")"

for region in $regions
do
for region in $regions; do
if [ $CONTAINS_TRANSFORM ]; then
echo "Packaging templates for region $region"
ssm_bucket_name="/adf/cross_region/s3_regional_bucket/$region"
bucket=`aws ssm get-parameters --names $ssm_bucket_name --with-decryption --output=text --query='Parameters[0].Value'`
bucket=$(aws ssm get-parameters --names $ssm_bucket_name --with-decryption --output=text --query='Parameters[0].Value')
sam package --s3-bucket $bucket --output-template-file $CODEBUILD_SRC_DIR/template_$region.yml --region $region
else
# If package is not needed, just copy the file for each region
Expand Down
Loading

0 comments on commit 16f3e28

Please sign in to comment.