def put_targets(self, name, event_bus_name, targets): # super simple ARN check invalid_arn = next( (target["Arn"] for target in targets if not re.match(r"arn:[\d\w:\-/]*", target["Arn"])), None, ) if invalid_arn: raise ValidationException( "Parameter {} is not valid. " "Reason: Provided Arn is not in correct format.".format( invalid_arn)) for target in targets: arn = target["Arn"] if (":sqs:" in arn and arn.endswith(".fifo") and not target.get("SqsParameters")): raise ValidationException( "Parameter(s) SqsParameters must be specified for target: {}." .format(target["Id"])) rule = self.rules.get(name) if not rule: raise ResourceNotFoundException( "Rule {0} does not exist on EventBus {1}.".format( name, event_bus_name)) rule.put_targets(targets)
def tag_resource(self, arn, tags): name = arn.split("/")[-1] if name in self.rules: self.tagger.tag_resource(self.rules[name].arn, tags) return {} raise ResourceNotFoundException( "Rule {0} does not exist on EventBus default.".format(name))
def _get_replay(self, name): replay = self.replays.get(name) if not replay: raise ResourceNotFoundException( "Replay {} does not exist.".format(name)) return replay
def list_tags_for_resource(self, arn): name = arn.split("/")[-1] if name in self.rules: return self.tagger.list_tags_for_resource(self.rules[name].arn) raise ResourceNotFoundException( "Rule {0} does not exist on EventBus default.".format(name) )
def delete_archive(self, name): archive = self.archives.get(name) if not archive: raise ResourceNotFoundException("Archive {} does not exist.".format(name)) archive.delete(self.region_name)
def describe_archive(self, name): archive = self.archives.get(name) if not archive: raise ResourceNotFoundException("Archive {} does not exist.".format(name)) return archive.describe()
def create_archive(self, name, source_arn, description, event_pattern, retention): if len(name) > 48: raise ValidationException( " 1 validation error detected: " "Value '{}' at 'archiveName' failed to satisfy constraint: " "Member must have length less than or equal to 48".format( name)) if event_pattern: self._validate_event_pattern(event_pattern) event_bus_name = source_arn.split("/")[-1] if event_bus_name not in self.event_buses: raise ResourceNotFoundException( "Event bus {} does not exist.".format(event_bus_name)) if name in self.archives: raise ResourceAlreadyExistsException( "Archive {} already exists.".format(name)) archive = Archive(self.region_name, name, source_arn, description, event_pattern, retention) self.archives[name] = archive return archive
def remove_targets(self, name, event_bus_name, ids): rule = self.rules.get(name) if not rule: raise ResourceNotFoundException( "Rule {0} does not exist on EventBus {1}.".format( name, event_bus_name)) rule.remove_targets(ids)
def _get_event_bus(self, name): event_bus_name = name.split("/")[-1] event_bus = self.event_buses.get(event_bus_name) if not event_bus: raise ResourceNotFoundException( "Event bus {} does not exist.".format(event_bus_name)) return event_bus
def update_archive(self, name, description, event_pattern, retention): archive = self.archives.get(name) if not archive: raise ResourceNotFoundException( "Archive {} does not exist.".format(name)) archive.update(description, event_pattern, retention) return { "ArchiveArn": archive.arn, "CreationTime": archive.creation_time, "State": archive.state, }
def put_targets(self, name, event_bus_name, targets): # super simple ARN check invalid_arn = next( ( target["Arn"] for target in targets if not re.match(r"arn:[\d\w:\-/]*", target["Arn"]) ), None, ) if invalid_arn: raise ValidationException( "Parameter {} is not valid. " "Reason: Provided Arn is not in correct format.".format(invalid_arn) ) rule = self.rules.get(name) if not rule: raise ResourceNotFoundException( "Rule {0} does not exist on EventBus {1}.".format(name, event_bus_name) ) rule.put_targets(targets)