|
| 1 | +# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"). You |
| 4 | +# may not use this file except in compliance with the License. A copy of |
| 5 | +# the License is located at |
| 6 | +# |
| 7 | +# http://aws.amazon.com/apache2.0/ |
| 8 | +# |
| 9 | +# or in the "license" file accompanying this file. This file is |
| 10 | +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 11 | +# ANY KIND, either express or implied. See the License for the specific |
| 12 | +# language governing permissions and limitations under the License. |
| 13 | +"""This file contains code related to network configuration, including |
| 14 | +encryption, network isolation, and VPC configurations. |
| 15 | +""" |
| 16 | +from __future__ import absolute_import |
| 17 | + |
| 18 | + |
| 19 | +class NetworkConfig(object): |
| 20 | + """Accepts network configuration parameters and provides a method to turn these parameters |
| 21 | + into a dictionary.""" |
| 22 | + |
| 23 | + def __init__( |
| 24 | + self, |
| 25 | + enable_network_isolation=False, |
| 26 | + encrypt_inter_container_traffic=False, |
| 27 | + security_group_ids=None, |
| 28 | + subnets=None, |
| 29 | + ): |
| 30 | + """Initialize a ``NetworkConfig`` instance. NetworkConfig accepts network configuration |
| 31 | + parameters and provides a method to turn these parameters into a dictionary. |
| 32 | +
|
| 33 | + Args: |
| 34 | + enable_network_isolation (bool): Boolean that determines whether to enable |
| 35 | + network isolation. |
| 36 | + encrypt_inter_container_traffic (bool): Boolean that determines whether to |
| 37 | + encrypt inter-container traffic. |
| 38 | + security_group_ids ([str]): A list of strings representing security group IDs. |
| 39 | + subnets ([str]): A list of strings representing subnets. |
| 40 | + """ |
| 41 | + self.enable_network_isolation = enable_network_isolation |
| 42 | + self.encrypt_inter_container_traffic = encrypt_inter_container_traffic |
| 43 | + self.security_group_ids = security_group_ids |
| 44 | + self.subnets = subnets |
| 45 | + |
| 46 | + def to_request_dict(self): |
| 47 | + """Generates a request dictionary using the parameters provided to the class.""" |
| 48 | + network_config_request = { |
| 49 | + "EnableInterContainerTrafficEncryption": self.encrypt_inter_container_traffic, |
| 50 | + "EnableNetworkIsolation": self.enable_network_isolation, |
| 51 | + "VpcConfig": {"SecurityGroupIds": self.security_group_ids, "Subnets": self.subnets}, |
| 52 | + } |
| 53 | + |
| 54 | + return network_config_request |
0 commit comments