diff --git a/.bumpversion.cfg b/.bumpversion.cfg index d2fb453..6991c78 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.3.0 +current_version = 0.4.0 commit = True tag = False tag_name = v{new_version} diff --git a/VERSION b/VERSION index c7f75a7..7ed95e7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -version=0.3.0 \ No newline at end of file +version=0.4.0 \ No newline at end of file diff --git a/ci/deploy_api_gateway_stage.py b/ci/deploy_api_gateway_stage.py index 4d835d0..da77b98 100644 --- a/ci/deploy_api_gateway_stage.py +++ b/ci/deploy_api_gateway_stage.py @@ -1,8 +1,16 @@ import click +import json from ci.external_cmd import ExternalCmd +def _get_output_from_stack_description(stack_description, output_key): + for output in stack_description["Outputs"]: + if output["OutputKey"] == output_key: + return output["OutputValue"] + raise KeyError(f"{output_key} not found") + + @click.command() @click.option("--stack-name", help="Name of the stack") @click.option("--stage-name", help="Name of the api stage") @@ -11,21 +19,45 @@ def deploy(stack_name, stage_name): stack_descriptions = ExternalCmd.run_and_parse_json( f"aws cloudformation describe-stacks --stack-name {stack_name}" ) - api_id = None - stack_description = stack_descriptions["Stacks"][0] - for output in stack_description["Outputs"]: - if output["OutputKey"] == "RestApiId": - api_id = output["OutputValue"] - break - if not api_id: - raise click.ClickException("RestApiId not found in stack outputs") + stack_description = stack_descriptions["Stacks"][0] + api_id = _get_output_from_stack_description(stack_description, "RestApiId") + log_group_arn = _get_output_from_stack_description(stack_description, "ApiGatewayAccessLogGroupArn") + log_group_arn = log_group_arn.rstrip(":*") click.echo(f"API id is {api_id}") click.echo(f"Deploying {stage_name} stage...") ExternalCmd.run( f"aws apigateway create-deployment --rest-api-id {api_id} --stage-name {stage_name}" ) + click.echo("Deployment done") + + click.echo("Enabling access logging...") + operations = [ + { + "op": "add", + "path": "/accessLogSettings/destinationArn", + "value": f"{log_group_arn}" + }, + { + "op": "add", + "path": "/accessLogSettings/format", + "value": "{ \"requestId\":\"$context.requestId\", \"ip\": \"$context.identity.sourceIp\", \"caller\":\"$context.identity.caller\", \"user\":\"$context.identity.user\",\"requestTime\":\"$context.requestTime\", \"httpMethod\":\"$context.httpMethod\",\"resourcePath\":\"$context.resourcePath\", \"status\":\"$context.status\",\"protocol\":\"$context.protocol\", \"responseLength\":\"$context.responseLength\" }" + }, + { + "op": "replace", + "path": "/*/*/logging/loglevel", + "value": "INFO" + }, + { + "op": "replace", + "path": "/*/*/logging/dataTrace", + "value": "true" + } + ] + ExternalCmd.run( + f"aws apigateway update-stage --rest-api-id {api_id} --stage-name {stage_name} --patch-operations '{json.dumps(operations)}'" + ) click.echo("Done") diff --git a/readme.md b/readme.md index 3647fa8..8f3e56c 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,5 @@ # Kyivmural API -version 0.3.0 +version 0.4.0 API component of kyivmural.com diff --git a/templates/api-specification.yml b/templates/api-specification.yml index b35ebad..52bf3c1 100644 --- a/templates/api-specification.yml +++ b/templates/api-specification.yml @@ -3,7 +3,7 @@ openapi: 3.0.1 info: title: Kyivmural API description: Kyivmural API - version: 0.3.0 + version: 0.4.0 tags: - name: mural description: Operations about murals diff --git a/templates/api.cfn b/templates/api.cfn index 34f0863..967bd78 100644 --- a/templates/api.cfn +++ b/templates/api.cfn @@ -1,6 +1,6 @@ --- AWSTemplateFormatVersion: 2010-09-09 -Description: Kyivmural API v0.3.0 - API +Description: Kyivmural API v0.4.0 - API Parameters: Branch: diff --git a/templates/backend.cfn b/templates/backend.cfn index c862195..764bfc9 100644 --- a/templates/backend.cfn +++ b/templates/backend.cfn @@ -1,6 +1,6 @@ --- AWSTemplateFormatVersion: 2010-09-09 -Description: Kyivmural API v0.3.0 - Backend +Description: Kyivmural API v0.4.0 - Backend Parameters: MuralsTableName: diff --git a/templates/database.cfn b/templates/database.cfn index fd9ecb0..b5d1c42 100644 --- a/templates/database.cfn +++ b/templates/database.cfn @@ -1,6 +1,6 @@ --- AWSTemplateFormatVersion: 2010-09-09 -Description: Kyivmural API v0.3.0 - Database +Description: Kyivmural API v0.4.0 - Database Parameters: Branch: diff --git a/templates/kyivmural-api.cfn b/templates/kyivmural-api.cfn index 96bb0a5..7114f2c 100644 --- a/templates/kyivmural-api.cfn +++ b/templates/kyivmural-api.cfn @@ -1,6 +1,6 @@ --- AWSTemplateFormatVersion: "2010-09-09" -Description: Kyivmural API v0.3.0 +Description: Kyivmural API v0.4.0 Parameters: Branch: