Techdebt: Replace string-format with f-strings (for o* dirs) (#5689)
This commit is contained in:
parent
8ebb8a7e17
commit
a092763ce5
@ -81,7 +81,7 @@ class OpsworkInstance(BaseModel):
|
|||||||
self.infrastructure_class = "ec2 (fixed)"
|
self.infrastructure_class = "ec2 (fixed)"
|
||||||
self.platform = "linux (fixed)"
|
self.platform = "linux (fixed)"
|
||||||
|
|
||||||
self.id = "{0}".format(random.uuid4())
|
self.id = str(random.uuid4())
|
||||||
self.created_at = datetime.datetime.utcnow()
|
self.created_at = datetime.datetime.utcnow()
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
@ -271,7 +271,7 @@ class Layer(BaseModel):
|
|||||||
self.install_updates_on_boot = install_updates_on_boot
|
self.install_updates_on_boot = install_updates_on_boot
|
||||||
self.use_ebs_optimized_instances = use_ebs_optimized_instances
|
self.use_ebs_optimized_instances = use_ebs_optimized_instances
|
||||||
|
|
||||||
self.id = "{0}".format(random.uuid4())
|
self.id = str(random.uuid4())
|
||||||
self.created_at = datetime.datetime.utcnow()
|
self.created_at = datetime.datetime.utcnow()
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
@ -367,7 +367,7 @@ class Stack(BaseModel):
|
|||||||
self.default_root_device_type = default_root_device_type
|
self.default_root_device_type = default_root_device_type
|
||||||
self.agent_version = agent_version
|
self.agent_version = agent_version
|
||||||
|
|
||||||
self.id = "{0}".format(random.uuid4())
|
self.id = str(random.uuid4())
|
||||||
self.layers = []
|
self.layers = []
|
||||||
self.apps = []
|
self.apps = []
|
||||||
self.account_number = account_id
|
self.account_number = account_id
|
||||||
@ -378,16 +378,11 @@ class Stack(BaseModel):
|
|||||||
|
|
||||||
def generate_hostname(self):
|
def generate_hostname(self):
|
||||||
# this doesn't match amazon's implementation
|
# this doesn't match amazon's implementation
|
||||||
return "{theme}-{rand}-(moto)".format(
|
return f"{self.hostname_theme}-{[random.choice('abcdefghijhk') for _ in range(4)]}-(moto)"
|
||||||
theme=self.hostname_theme,
|
|
||||||
rand=[random.choice("abcdefghijhk") for _ in range(4)],
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def arn(self):
|
def arn(self):
|
||||||
return "arn:aws:opsworks:{region}:{account_number}:stack/{id}".format(
|
return f"arn:aws:opsworks:{self.region}:{self.account_number}:stack/{self.id}"
|
||||||
region=self.region, account_number=self.account_number, id=self.id
|
|
||||||
)
|
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
response = {
|
response = {
|
||||||
@ -468,7 +463,7 @@ class App(BaseModel):
|
|||||||
if environment is None:
|
if environment is None:
|
||||||
self.environment = {}
|
self.environment = {}
|
||||||
|
|
||||||
self.id = "{0}".format(random.uuid4())
|
self.id = str(random.uuid4())
|
||||||
self.created_at = datetime.datetime.utcnow()
|
self.created_at = datetime.datetime.utcnow()
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
@ -516,12 +511,11 @@ class OpsWorksBackend(BaseBackend):
|
|||||||
raise ResourceNotFoundException(stackid)
|
raise ResourceNotFoundException(stackid)
|
||||||
if name in [layer.name for layer in self.stacks[stackid].layers]:
|
if name in [layer.name for layer in self.stacks[stackid].layers]:
|
||||||
raise ValidationException(
|
raise ValidationException(
|
||||||
'There is already a layer named "{0}" ' "for this stack".format(name)
|
f'There is already a layer named "{name}" for this stack'
|
||||||
)
|
)
|
||||||
if shortname in [layer.shortname for layer in self.stacks[stackid].layers]:
|
if shortname in [layer.shortname for layer in self.stacks[stackid].layers]:
|
||||||
raise ValidationException(
|
raise ValidationException(
|
||||||
'There is already a layer with shortname "{0}" '
|
f'There is already a layer with shortname "{shortname}" for this stack'
|
||||||
"for this stack".format(shortname)
|
|
||||||
)
|
)
|
||||||
layer = Layer(**kwargs)
|
layer = Layer(**kwargs)
|
||||||
self.layers[layer.id] = layer
|
self.layers[layer.id] = layer
|
||||||
@ -535,7 +529,7 @@ class OpsWorksBackend(BaseBackend):
|
|||||||
raise ResourceNotFoundException(stackid)
|
raise ResourceNotFoundException(stackid)
|
||||||
if name in [a.name for a in self.stacks[stackid].apps]:
|
if name in [a.name for a in self.stacks[stackid].apps]:
|
||||||
raise ValidationException(
|
raise ValidationException(
|
||||||
'There is already an app named "{0}" ' "for this stack".format(name)
|
f'There is already an app named "{name}" for this stack'
|
||||||
)
|
)
|
||||||
app = App(**kwargs)
|
app = App(**kwargs)
|
||||||
self.apps[app.id] = app
|
self.apps[app.id] = app
|
||||||
@ -547,9 +541,7 @@ class OpsWorksBackend(BaseBackend):
|
|||||||
layer_ids = kwargs["layer_ids"]
|
layer_ids = kwargs["layer_ids"]
|
||||||
|
|
||||||
if stack_id not in self.stacks:
|
if stack_id not in self.stacks:
|
||||||
raise ResourceNotFoundException(
|
raise ResourceNotFoundException(f"Unable to find stack with ID {stack_id}")
|
||||||
"Unable to find stack with ID {0}".format(stack_id)
|
|
||||||
)
|
|
||||||
|
|
||||||
unknown_layers = set(layer_ids) - set(self.layers.keys())
|
unknown_layers = set(layer_ids) - set(self.layers.keys())
|
||||||
if unknown_layers:
|
if unknown_layers:
|
||||||
@ -601,7 +593,7 @@ class OpsWorksBackend(BaseBackend):
|
|||||||
if stack_id is not None:
|
if stack_id is not None:
|
||||||
if stack_id not in self.stacks:
|
if stack_id not in self.stacks:
|
||||||
raise ResourceNotFoundException(
|
raise ResourceNotFoundException(
|
||||||
"Unable to find stack with ID {0}".format(stack_id)
|
f"Unable to find stack with ID {stack_id}"
|
||||||
)
|
)
|
||||||
return [layer.to_dict() for layer in self.stacks[stack_id].layers]
|
return [layer.to_dict() for layer in self.stacks[stack_id].layers]
|
||||||
|
|
||||||
@ -618,7 +610,7 @@ class OpsWorksBackend(BaseBackend):
|
|||||||
if stack_id is not None:
|
if stack_id is not None:
|
||||||
if stack_id not in self.stacks:
|
if stack_id not in self.stacks:
|
||||||
raise ResourceNotFoundException(
|
raise ResourceNotFoundException(
|
||||||
"Unable to find stack with ID {0}".format(stack_id)
|
f"Unable to find stack with ID {stack_id}"
|
||||||
)
|
)
|
||||||
return [app.to_dict() for app in self.stacks[stack_id].apps]
|
return [app.to_dict() for app in self.stacks[stack_id].apps]
|
||||||
|
|
||||||
@ -643,7 +635,7 @@ class OpsWorksBackend(BaseBackend):
|
|||||||
if layer_id:
|
if layer_id:
|
||||||
if layer_id not in self.layers:
|
if layer_id not in self.layers:
|
||||||
raise ResourceNotFoundException(
|
raise ResourceNotFoundException(
|
||||||
"Unable to find layer with ID {0}".format(layer_id)
|
f"Unable to find layer with ID {layer_id}"
|
||||||
)
|
)
|
||||||
instances = [
|
instances = [
|
||||||
i.to_dict() for i in self.instances.values() if layer_id in i.layer_ids
|
i.to_dict() for i in self.instances.values() if layer_id in i.layer_ids
|
||||||
@ -653,7 +645,7 @@ class OpsWorksBackend(BaseBackend):
|
|||||||
if stack_id:
|
if stack_id:
|
||||||
if stack_id not in self.stacks:
|
if stack_id not in self.stacks:
|
||||||
raise ResourceNotFoundException(
|
raise ResourceNotFoundException(
|
||||||
"Unable to find stack with ID {0}".format(stack_id)
|
f"Unable to find stack with ID {stack_id}"
|
||||||
)
|
)
|
||||||
instances = [
|
instances = [
|
||||||
i.to_dict() for i in self.instances.values() if stack_id == i.stack_id
|
i.to_dict() for i in self.instances.values() if stack_id == i.stack_id
|
||||||
@ -663,7 +655,7 @@ class OpsWorksBackend(BaseBackend):
|
|||||||
def start_instance(self, instance_id):
|
def start_instance(self, instance_id):
|
||||||
if instance_id not in self.instances:
|
if instance_id not in self.instances:
|
||||||
raise ResourceNotFoundException(
|
raise ResourceNotFoundException(
|
||||||
"Unable to find instance with ID {0}".format(instance_id)
|
f"Unable to find instance with ID {instance_id}"
|
||||||
)
|
)
|
||||||
self.instances[instance_id].start()
|
self.instances[instance_id].start()
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ class FakePolicy(BaseModel):
|
|||||||
self._arn_format = utils.SCP_ARN_FORMAT
|
self._arn_format = utils.SCP_ARN_FORMAT
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
"The {0} policy type has not been implemented".format(self.type)
|
f"The {self.type} policy type has not been implemented"
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -683,7 +683,7 @@ class OrganizationsBackend(BaseBackend):
|
|||||||
|
|
||||||
if _filter not in ["AISERVICES_OPT_OUT_POLICY", "SERVICE_CONTROL_POLICY"]:
|
if _filter not in ["AISERVICES_OPT_OUT_POLICY", "SERVICE_CONTROL_POLICY"]:
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
"The {0} policy type has not been implemented".format(_filter)
|
f"The {_filter} policy type has not been implemented"
|
||||||
)
|
)
|
||||||
|
|
||||||
return dict(
|
return dict(
|
||||||
|
@ -24,12 +24,12 @@ CREATE_ACCOUNT_STATUS_ID_SIZE = 8
|
|||||||
POLICY_ID_SIZE = 8
|
POLICY_ID_SIZE = 8
|
||||||
|
|
||||||
EMAIL_REGEX = "^.+@[a-zA-Z0-9-.]+.[a-zA-Z]{2,3}|[0-9]{1,3}$"
|
EMAIL_REGEX = "^.+@[a-zA-Z0-9-.]+.[a-zA-Z]{2,3}|[0-9]{1,3}$"
|
||||||
ORG_ID_REGEX = r"o-[a-z0-9]{%s}" % ORG_ID_SIZE
|
ORG_ID_REGEX = rf"o-[a-z0-9]{{{ORG_ID_SIZE}}}"
|
||||||
ROOT_ID_REGEX = r"r-[a-z0-9]{%s}" % ROOT_ID_SIZE
|
ROOT_ID_REGEX = rf"r-[a-z0-9]{{{ROOT_ID_SIZE}}}"
|
||||||
OU_ID_REGEX = r"ou-[a-z0-9]{%s}-[a-z0-9]{%s}" % (ROOT_ID_SIZE, OU_ID_SUFFIX_SIZE)
|
OU_ID_REGEX = rf"ou-[a-z0-9]{{{ROOT_ID_SIZE}}}-[a-z0-9]{{{OU_ID_SUFFIX_SIZE}}}"
|
||||||
ACCOUNT_ID_REGEX = r"[0-9]{%s}" % ACCOUNT_ID_SIZE
|
ACCOUNT_ID_REGEX = rf"[0-9]{{{ACCOUNT_ID_SIZE}}}"
|
||||||
CREATE_ACCOUNT_STATUS_ID_REGEX = r"car-[a-z0-9]{%s}" % CREATE_ACCOUNT_STATUS_ID_SIZE
|
CREATE_ACCOUNT_STATUS_ID_REGEX = rf"car-[a-z0-9]{{{CREATE_ACCOUNT_STATUS_ID_SIZE}}}"
|
||||||
POLICY_ID_REGEX = r"%s|p-[a-z0-9]{%s}" % (DEFAULT_POLICY_ID, POLICY_ID_SIZE)
|
POLICY_ID_REGEX = rf"{DEFAULT_POLICY_ID}|p-[a-z0-9]{{{POLICY_ID_SIZE}}}"
|
||||||
|
|
||||||
PAGINATION_MODEL = {
|
PAGINATION_MODEL = {
|
||||||
"list_accounts": {
|
"list_accounts": {
|
||||||
|
Loading…
Reference in New Issue
Block a user