Skip to content

Commit

Permalink
Use named parameters for template strings
Browse files Browse the repository at this point in the history
This reduces the potential for errors and allows for a single value to
be used multiple times in a format string.
  • Loading branch information
samdoran committed May 3, 2024
1 parent 4d9208a commit 31b20b0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions nise/generators/aws/data_transfer_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@ class DataTransferGenerator(AWSGenerator):

DATA_TRANSFER = (
# (usage type, operation, transfer type)
("{}-{}-AWS-In-Bytes", "PublicIP-In", "InterRegion Inbound"),
("{}-{}-AWS-Out-Bytes", "PublicIP-Out", "InterRegion Outbound"),
("DataTransfer-Out-Bytes", "RunInstances", ""),
("DataTransfer-In-Bytes", "RunInstances", ""),
("{}-DataTransfer-Regional-Bytes", "PublicIP-In", ""),
("{}-DataTransfer-Regional-Bytes", "PublicIP-Out", ""),
("{}-DataTransfer-Regional-Bytes", "InterZone-In", ""),
("{region1}-{region2}-AWS-{direction}-Bytes", "PublicIP-{direction}", "InterRegion {direction}bound"),
("DataTransfer-{direction}-Bytes", "RunInstances", ""),
("{region1}-DataTransfer-Regional-Bytes", "PublicIP-{direction}", ""),
("{region1}-DataTransfer-Regional-Bytes", "InterZone-{direction}", ""),
)

def __init__(self, start_date, end_date, currency, payer_account, usage_accounts, attributes=None, tag_cols=None):
Expand All @@ -54,6 +51,9 @@ def _get_data_transfer(self, rate):
location2, _, _, storage_region2 = self._get_location()
trans_desc, operation, trans_type = choice(self.DATA_TRANSFER)
trans_desc = trans_desc.format(storage_region1, storage_region2)
trans_desc = trans_desc.format(region1=storage_region1, region2=storage_region2, direction=self.direction)
operation = operation.format(direction=self.direction)
trans_type = trans_type.format(direction=self.direction)
description = f"${rate} per GB - {location1} data transfer to {location2}"
return trans_desc, operation, description, location1, location2, trans_type, aws_region

Expand Down

0 comments on commit 31b20b0

Please sign in to comment.