1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
import json
from urllib.parse import unquote
from moto.core.responses import BaseResponse
from .models import VPCLatticeBackend, vpclattice_backends
class VPCLatticeResponse(BaseResponse):
def __init__(self) -> None:
super().__init__(service_name="vpc-lattice")
@property
def backend(self) -> VPCLatticeBackend:
return vpclattice_backends[self.current_account][self.region]
def create_service(self) -> str:
service = self.backend.create_service(
auth_type=self._get_param("authType"),
certificate_arn=self._get_param("certificateArn"),
client_token=self._get_param("clientToken"),
custom_domain_name=self._get_param("customDomainName"),
name=self._get_param("name"),
tags=self._get_param("tags"),
)
return json.dumps(service.to_dict())
def get_service(self) -> str:
path = unquote(self.path)
service = self.backend.get_service(service_identifier=path.split("/")[-1])
return json.dumps(service.to_dict())
def list_services(self) -> str:
max_results = self._get_param("MaxResults")
next_token = self._get_param("NextToken")
services, next_token = self.backend.list_services(
max_results=max_results, next_token=next_token
)
response = {
"items": [service.to_dict() for service in services],
"nextToken": next_token,
}
return json.dumps(response)
def create_service_network(self) -> str:
sn = self.backend.create_service_network(
auth_type=self._get_param("authType"),
client_token=self._get_param("clientToken"),
name=self._get_param("name"),
sharing_config=self._get_param("sharingConfig"),
tags=self._get_param("tags"),
)
return json.dumps(sn.to_dict())
def get_service_network(self) -> str:
path = unquote(self.path)
service_network = self.backend.get_service_network(
service_network_identifier=path.split("/")[-1]
)
return json.dumps(service_network.to_dict())
def list_service_networks(self) -> str:
max_results = self._get_param("MaxResults")
next_token = self._get_param("NextToken")
service_networks, next_token = self.backend.list_service_networks(
max_results=max_results, next_token=next_token
)
response = {
"items": [
service_network.to_dict() for service_network in service_networks
],
"nextToken": next_token,
}
return json.dumps(response)
def create_service_network_vpc_association(self) -> str:
assoc = self.backend.create_service_network_vpc_association(
client_token=self._get_param("clientToken"),
security_group_ids=self._get_param("securityGroupIds"),
service_network_identifier=self._get_param("serviceNetworkIdentifier"),
tags=self._get_param("tags"),
vpc_identifier=self._get_param("vpcIdentifier"),
)
return json.dumps(assoc.to_dict())
def create_rule(self) -> str:
rule = self.backend.create_rule(
action=self._get_param("action"),
client_token=self._get_param("clientToken"),
listener_identifier=self._get_param("listenerIdentifier"),
match=self._get_param("match"),
name=self._get_param("name"),
priority=self._get_param("priority"),
service_identifier=self._get_param("serviceIdentifier"),
tags=self._get_param("tags"),
)
return json.dumps(rule.to_dict())
def list_tags_for_resource(self) -> str:
resource_arn = unquote(self._get_param("resourceArn"))
tags = self.backend.list_tags_for_resource(resource_arn)
return json.dumps({"tags": tags})
def tag_resource(self) -> str:
resource_arn = unquote(self._get_param("resourceArn"))
tags = self._get_param("tags")
self.backend.tag_resource(resource_arn, tags)
return json.dumps({})
def untag_resource(self) -> str:
resource_arn = unquote(self._get_param("resourceArn"))
tag_keys = self._get_param("tagKeys")
self.backend.untag_resource(resource_arn=resource_arn, tag_keys=tag_keys)
return json.dumps({})
def create_access_log_subscription(self) -> str:
sub = self.backend.create_access_log_subscription(
resourceIdentifier=self._get_param("resourceIdentifier"),
destinationArn=self._get_param("destinationArn"),
client_token=self._get_param("clientToken"),
serviceNetworkLogType=self._get_param("serviceNetworkLogType"),
tags=self._get_param("tags"),
)
return json.dumps(sub.to_dict())
def get_access_log_subscription(self) -> str:
path = unquote(self.path)
sub = self.backend.get_access_log_subscription(
accessLogSubscriptionIdentifier=path.split("/")[-1]
)
return json.dumps(sub.to_dict())
def list_access_log_subscriptions(self) -> str:
subs = self.backend.list_access_log_subscriptions(
resourceIdentifier=self._get_param("resourceIdentifier"),
maxResults=self._get_int_param("maxResults"),
nextToken=self._get_param("nextToken"),
)
return json.dumps({"items": [s.to_dict() for s in subs], "nextToken": ""})
def update_access_log_subscription(self) -> str:
path = unquote(self.path)
sub = self.backend.update_access_log_subscription(
accessLogSubscriptionIdentifier=path.split("/")[-1],
destinationArn=self._get_param("destinationArn"),
)
return json.dumps(sub.to_dict())
def delete_access_log_subscription(self) -> str:
path = unquote(self.path)
self.backend.delete_access_log_subscription(
accessLogSubscriptionIdentifier=path.split("/")[-1]
)
return json.dumps({})
|