mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-03-14 05:53:39 +00:00
feat: add trigger loader guard
This commit is contained in:
@@ -47,6 +47,7 @@ class LogsRotationTrigger(Trigger):
|
||||
},
|
||||
},
|
||||
}
|
||||
REQUIRES_REPOSITORY = True
|
||||
|
||||
def __init__(self, repository_id: RepositoryId, configuration: Configuration) -> None:
|
||||
"""
|
||||
|
||||
@@ -336,6 +336,7 @@ class ReportTrigger(Trigger):
|
||||
},
|
||||
},
|
||||
}
|
||||
REQUIRES_REPOSITORY = True
|
||||
|
||||
def __init__(self, repository_id: RepositoryId, configuration: Configuration) -> None:
|
||||
"""
|
||||
|
||||
@@ -103,6 +103,7 @@ class KeyringTrigger(Trigger):
|
||||
},
|
||||
},
|
||||
}
|
||||
REQUIRES_REPOSITORY = True
|
||||
|
||||
def __init__(self, repository_id: RepositoryId, configuration: Configuration) -> None:
|
||||
"""
|
||||
|
||||
@@ -90,6 +90,7 @@ class MirrorlistTrigger(Trigger):
|
||||
},
|
||||
},
|
||||
}
|
||||
REQUIRES_REPOSITORY = True
|
||||
|
||||
def __init__(self, repository_id: RepositoryId, configuration: Configuration) -> None:
|
||||
"""
|
||||
|
||||
@@ -36,6 +36,7 @@ class Trigger(LazyLogging):
|
||||
CONFIGURATION_SCHEMA(ConfigurationSchema): (class attribute) configuration schema template
|
||||
CONFIGURATION_SCHEMA_FALLBACK(str | None): (class attribute) optional fallback option for defining
|
||||
configuration schema type used
|
||||
REQUIRES_REPOSITORY(bool): (class attribute) either trigger requires loaded repository or not
|
||||
configuration(Configuration): configuration instance
|
||||
repository_id(RepositoryId): repository unique identifier
|
||||
|
||||
@@ -59,6 +60,7 @@ class Trigger(LazyLogging):
|
||||
|
||||
CONFIGURATION_SCHEMA: ClassVar[ConfigurationSchema] = {}
|
||||
CONFIGURATION_SCHEMA_FALLBACK: ClassVar[str | None] = None
|
||||
REQUIRES_REPOSITORY: ClassVar[bool] = True
|
||||
|
||||
def __init__(self, repository_id: RepositoryId, configuration: Configuration) -> None:
|
||||
"""
|
||||
@@ -79,6 +81,16 @@ class Trigger(LazyLogging):
|
||||
"""
|
||||
return self.repository_id.architecture
|
||||
|
||||
@property
|
||||
def is_allowed_to_run(self) -> bool:
|
||||
"""
|
||||
whether trigger allowed to run or not
|
||||
|
||||
Returns:
|
||||
bool: ``True`` in case if trigger allowed to run and ``False`` otherwise
|
||||
"""
|
||||
return not (self.REQUIRES_REPOSITORY and self.repository_id.is_empty)
|
||||
|
||||
@classmethod
|
||||
def configuration_schema(cls, configuration: Configuration | None) -> ConfigurationSchema:
|
||||
"""
|
||||
|
||||
@@ -77,8 +77,9 @@ class TriggerLoader(LazyLogging):
|
||||
"""
|
||||
instance = cls()
|
||||
instance.triggers = [
|
||||
instance.load_trigger(trigger, repository_id, configuration)
|
||||
for trigger in instance.selected_triggers(configuration)
|
||||
trigger
|
||||
for trigger_name in instance.selected_triggers(configuration)
|
||||
if (trigger := instance.load_trigger(trigger_name, repository_id, configuration)).is_allowed_to_run
|
||||
]
|
||||
|
||||
return instance
|
||||
|
||||
@@ -160,6 +160,7 @@ class UploadTrigger(Trigger):
|
||||
},
|
||||
},
|
||||
}
|
||||
REQUIRES_REPOSITORY = True
|
||||
|
||||
def __init__(self, repository_id: RepositoryId, configuration: Configuration) -> None:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user