update_projects_from_config
Script to update projects from a configuration file.
This script reads a config file containing project IDs, task template slugs, and variables, then ensures each project is updated with the correct task template version and configurable variables.
Config file format:
configurations:
- task-slug: owner/task-slug
task-template-version: "latest"
variables:
var1: value1
projects:
project-id-1: bitfount
project-id-2: bitfount-testing
This format allows you to define: "For this task-slug with these variables, update all these projects (mapped to their owners) with this task-template-version."
The script automatically filters to only process projects owned by the authenticated user.
Example usage: python -m bitfount.runners.update_projects_from_config \ task_templates/project-config-production-public.yaml --username myuser \ --password mypass
Update projects owned by bitfount-testing (authenticate as that user):
python -m bitfount.runners.update_projects_from_config \ task_templates/project-config-production-public.yaml --username bitfount-testing \ --password mypass Or without password (uses normal authentication flow): python -m bitfount.runners.update_projects_from_config \ task_templates/project-config-production-public.yaml --username myuser
Module
Functions
get_latest_task_definition_for_project
def get_latest_task_definition_for_project( project_id: str, hub: BitfountHub, hub_url: str,) ‑> Optional[dict[str, typing.Any]]:Gets the latest task definition for a project from the hub.
Returns None if there is no task definition.
get_or_update_latest_task_template
def get_or_update_latest_task_template( project_config: ProjectConfig, username: str, jwt: Optional[ExternallyManagedJWT], hub: BitfountHub, hub_url: str, additional_config_paths: Optional[list[str]] = None,) ‑> str:Check if task template on hub is the latest version and update if necessary.
Arguments
project_config: The project configuration.username: The authenticated username.jwt: The JWT token.hub: The hub connection object.hub_url: The hub URL.additional_config_paths: Any additional paths to check for project config files. These paths will be checked with priority over the default ones.
Returns The task template ID to use, corresponding to the latest version of the task template.
Raises
SkipProjectException: If project should be skipped.FailProjectException: If project update should be failed.
get_project_info
def get_project_info( project_id: str, hub: BitfountHub, hub_url: str,) ‑> dict[str, typing.Any]:Get current project information from the hub.
Arguments
project_id: The project ID to retrieve.hub: The hub connection object.hub_url: The hub URL.
Returns Project information dictionary or None if not found.
Raises
FailProjectException: If the project could not be found or accessed.
get_project_task_definitions
def get_project_task_definitions( project_id: str, hub: BitfountHub, hub_url: str,) ‑> dict[str, typing.Any]:Get task definitions for a project from the hub.
Arguments
project_id: The project ID.hub: The hub connection object.hub_url: The hub URL.
Returns Task definitions response dictionary or None if not found.
Raises
FailProjectException: If the task definitions could not be found or accessed.
get_task_template_info
def get_task_template_info( owner_or_id: str, slug: Optional[str], hub: BitfountHub, hub_url: str,) ‑> dict[str, typing.Any]:Get task template information from the hub by owner/slug or by ID.
Gets the latest task template for a given owner/slug, gets the specific version if provided with ID.
Arguments
owner_or_id: Either the task template owner (if slug provided) or template ID.slug: The task template slug (if getting by owner/slug), None if getting by ID.hub: The hub connection object.hub_url: The hub URL.
Returns Task template information dictionary or None if not found.
load_config
def load_config( config_file: str,) ‑> list[ProjectConfig]:Load and parse the project configuration file.
Expected format: configurations list where each config has:
- task-slug
- task-template-version
- variables (optional)
- projects: mapping of project_id to username (owner)
Arguments
config_file: Path to the YAML configuration file.
Returns List of ProjectConfig objects.
main
def main( config_file: str, username: str, password: Optional[str] = None, additional_task_template_config_paths: Union[str, list[str], ForwardRef(None)] = None,) ‑> None:Main function to update projects from configuration file.
Arguments
config_file: Path to the YAML configuration file.username: The username for authentication.password: Optional password for authentication. If not provided, will use the normal authentication flow (device code flow).additional_task_template_config_paths: Optional list of additional task template config paths to check with priority over the standard ones. Can be provided as a comma-separated string or a list. These paths will be checked before the standard TASK_TEMPLATES_CONFIG_PATHS.
process_project
def process_project( project_config: ProjectConfig, username: str, jwt: Optional[ExternallyManagedJWT], hub: BitfountHub, hub_url: str, additional_config_paths: Optional[list[str]] = None,) ‑> ProcessResult:Process a single project configuration.
Arguments
project_config: The project configuration to process.username: The authenticated username.jwt: The JWT token.hub: The hub connection object.hub_url: The hub URL.additional_config_paths: Any additional paths to check for project config files. These paths will be checked with priority over the default ones.
Returns ProcessResult enum value.
update_project_config
def update_project_config( target_project_config: ProjectConfig, target_task_template_id: str, current_project_info: dict[str, typing.Any], latest_task_definition: Optional[dict[str, typing.Any]], hub: BitfountHub, hub_url: str,) ‑> None:Update a project as needed, considering both task template and variables.
Arguments
target_project_config: The project configuration as we want to end up using.target_task_template_id: The task template ID we want to end up using.current_project_info: Project information for its current state.latest_task_definition: The latest task definition for that project or None if there is no latest task definition.hub: The hub connection object.hub_url: The hub URL.
Returns None if update was successful.
Raises
FailProjectException: If the project update fails.
Classes
FailProjectException
class FailProjectException(*args, **kwargs):Fail updating this project.
ProcessResult
class ProcessResult(*args, **kwds):Enum representing the result of processing a project.
ProjectConfig
class ProjectConfig(project_id: str, config_data: dict[str, typing.Any]):Class to represent a project configuration.
SkipProjectException
class SkipProjectException(*args, **kwargs):Skip updating this project.