Skip to content

Commit 7dc0838

Browse files
authored
APIGateway: add get_tags support for stages (getmoto#10162)
1 parent f01d050 commit 7dc0838

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

moto/apigateway/responses.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,13 @@ def update_stage(self) -> str:
425425
)
426426
return json.dumps(stage_response.to_json())
427427

428+
def get_tags(self) -> str:
429+
url_path_parts = unquote(self.path.split("/tags/")[1]).split("/")
430+
function_id = url_path_parts[-3]
431+
stage_name = url_path_parts[-1]
432+
stage = self.backend.get_stage(function_id, stage_name)
433+
return json.dumps({"tags": stage.tags or {}})
434+
428435
def tag_resource(self) -> str:
429436
url_path_parts = unquote(self.path.split("/tags/")[1]).split("/")
430437
function_id = url_path_parts[-3]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import boto3
2+
3+
from moto import mock_aws
4+
5+
6+
@mock_aws
7+
def test_get_tags_returns_stage_tags():
8+
client = boto3.client("apigateway", region_name="us-east-1")
9+
api_id = client.create_rest_api(name="my-api")["id"]
10+
root_id = client.get_resources(restApiId=api_id)["items"][0]["id"]
11+
client.put_method(
12+
restApiId=api_id, resourceId=root_id, httpMethod="GET", authorizationType="NONE"
13+
)
14+
client.put_integration(
15+
restApiId=api_id, resourceId=root_id, httpMethod="GET", type="MOCK"
16+
)
17+
client.create_deployment(restApiId=api_id, stageName="dev")
18+
deployment_id = client.get_deployments(restApiId=api_id)["items"][0]["id"]
19+
client.create_stage(
20+
restApiId=api_id,
21+
stageName="test",
22+
deploymentId=deployment_id,
23+
tags={"env": "prod", "team": "backend"},
24+
)
25+
arn = f"arn:aws:apigateway:us-east-1::/restapis/{api_id}/stages/test"
26+
resp = client.get_tags(resourceArn=arn)
27+
assert resp["tags"] == {"env": "prod", "team": "backend"}

0 commit comments

Comments
 (0)