in aws-frauddetector-eventtype/src/aws_frauddetector_eventtype/helpers/update_worker_helpers.py [0:0]
def _validate_inline_event_variable_for_update(afd_client, event_variable, previous_variables):
if not event_variable.Name:
raise exceptions.InvalidRequest("Error occurred: inline event variables must include Name!")
# TODO: update this logic if we support in-place Teardown
# This difference would require teardown if we were to support it
# check for differences in dataSource or dataType
differences = {}
previous_variable = previous_variables.get(event_variable.Name, None)
if previous_variable:
differences = validation_helpers.check_variable_differences(previous_variable, event_variable)
if differences["dataSource"] or differences["dataType"]:
raise exceptions.InvalidRequest("Error occurred: cannot update event variable data source or data type!")
if not previous_variable:
# create inline variable that does not already exist
common_helpers.create_inline_event_variable(frauddetector_client=afd_client, event_variable=event_variable)
else:
# get existing variable to get arn. Arn is readonly property, so it will not be attached to input model
(
get_variables_worked,
get_variables_response,
) = validation_helpers.check_if_get_variables_succeeds(afd_client, event_variable.Name)
if not get_variables_worked:
raise RuntimeError(f"Previously existing event variable {event_variable.Name} no longer exists!")
event_variable.Arn = get_variables_response.get("variables")[0].get("arn")
# update existing inline variable
if hasattr(event_variable, "Tags"):
common_helpers.update_tags(
frauddetector_client=afd_client,
afd_resource_arn=event_variable.Arn,
new_tags=event_variable.Tags,
)
var_type = [None, event_variable.VariableType][event_variable.VariableType != previous_variable.VariableType]
api_helpers.call_update_variable(
variable_name=event_variable.Name,
frauddetector_client=afd_client,
variable_default_value=event_variable.DefaultValue,
variable_description=event_variable.Description,
variable_type=var_type,
)