infrahouse_core package¶
Subpackages¶
- infrahouse_core.aws package
- Subpackages
- Submodules
- infrahouse_core.aws.acm_certificate module
- infrahouse_core.aws.base module
- infrahouse_core.aws.asg module
- infrahouse_core.aws.asg_instance module
- infrahouse_core.aws.cloudwatch_alarm module
- infrahouse_core.aws.cloudfront_cache_policy module
- infrahouse_core.aws.cloudfront_distribution module
- infrahouse_core.aws.cloudfront_function module
- infrahouse_core.aws.cloudfront_response_headers_policy module
- infrahouse_core.aws.cloudwatch_log_group module
- infrahouse_core.aws.ecr_repository module
- infrahouse_core.aws.ecs_service module
- infrahouse_core.aws.ecs_task_definition module
- infrahouse_core.aws.config module
- infrahouse_core.aws.dynamodb module
- infrahouse_core.aws.elastic_ip module
- infrahouse_core.aws.elasticache_cluster module
- infrahouse_core.aws.emr_serverless_application module
- infrahouse_core.aws.ec2_instance module
CommandStatusEC2InstanceEC2Instance.add_tag()EC2Instance.availability_zoneEC2Instance.delete()EC2Instance.ec2_clientEC2Instance.execute_command()EC2Instance.existsEC2Instance.hostnameEC2Instance.instance_idEC2Instance.private_dns_nameEC2Instance.private_ipEC2Instance.public_ipEC2Instance.ssm_clientEC2Instance.stateEC2Instance.tags
- infrahouse_core.aws.elb_load_balancer module
- infrahouse_core.aws.elb_target_group module
- infrahouse_core.aws.eventbridge_rule module
- infrahouse_core.aws.exceptions module
- infrahouse_core.aws.internet_gateway module
- infrahouse_core.aws.kms_key module
- infrahouse_core.aws.nat_gateway module
- infrahouse_core.aws.opensearch_domain module
- infrahouse_core.aws.iam_group module
- infrahouse_core.aws.iam_instance_profile module
- infrahouse_core.aws.iam_policy module
- infrahouse_core.aws.iam_role module
- infrahouse_core.aws.iam_user module
- infrahouse_core.aws.lambda_function module
- infrahouse_core.aws.rds_cluster module
- infrahouse_core.aws.rds_instance module
- infrahouse_core.aws.route_table module
- infrahouse_core.aws.s3_bucket module
- infrahouse_core.aws.security_group module
- infrahouse_core.aws.sns_topic module
- infrahouse_core.aws.sqs_queue module
- infrahouse_core.aws.subnet module
- infrahouse_core.aws.vpc module
- infrahouse_core.aws.vpc_endpoint module
- infrahouse_core.aws.vpc_flow_log module
- infrahouse_core.aws.secretsmanager module
- Module contents
- infrahouse_core.orchestrator package
- Submodules
- infrahouse_core.orchestrator.exceptions module
- infrahouse_core.orchestrator.raft_cluster module
- infrahouse_core.orchestrator.raft_node module
OrchestratorRaftNodeOrchestratorRaftNode.add_peer()OrchestratorRaftNode.from_peer_addr()OrchestratorRaftNode.hostnameOrchestratorRaftNode.instanceOrchestratorRaftNode.is_leaderOrchestratorRaftNode.peer_addrOrchestratorRaftNode.private_ipOrchestratorRaftNode.raft_healthOrchestratorRaftNode.raft_leaderOrchestratorRaftNode.raft_peersOrchestratorRaftNode.remove_peer()
- Module contents
Submodules¶
infrahouse_core.exceptions module¶
Top level exceptions.
The exception hierarchy repeats the structure of the infrahouse_core package. Each module in the package has its own exceptions.py module. The module exceptions are inherited from the upper module exceptions.
infrahouse_core.fs module¶
InfraHouse Toolkit file system module.
- infrahouse_core.fs.ensure_permissions(path: str, permissions: int)[source]¶
For a path on the file system check permissions and set if they differ.
- Parameters:
path (str) – Filesystem path to a file or directory.
permissions (int) – Permissions the file or directory must have. Can be an integer like 0o755 or 0o644.
infrahouse_core.github module¶
GitHub Actions
- class infrahouse_core.github.GitHubActions(github: GitHubAuth, region: str | None = None, role_arn: str | None = None)[source]¶
Bases:
objectThe GitHubActions class manages self-hosted GitHub Action runners for an organization.
- Parameters:
github (GitHubAuth) – GitHub authentication information (token and org).
region (str) – AWS region for Secrets Manager operations.
role_arn (str) – IAM role ARN to assume for cross-account access.
Example:
auth = GitHubAuth(token="ghp_...", org="my-org") gha = GitHubActions(auth, region="us-east-1") # Store a registration token in Secrets Manager gha.ensure_registration_token("my-runner-token") # Iterate over runners (lazy — one API page at a time) for runner in gha.runners: print(runner.name, runner.status) runner = gha.find_runner_by_label("instance_id:i-abc123") if runner: gha.deregister_runner(runner) # Clean up the token gha.ensure_registration_token("my-runner-token", present=False)
Note
runnersandfind_runners_by_label()return iterators, not lists. They fetch subsequent GitHub API pages only as the iterator advances, so memory usage stays bounded to one page (~100 runners) regardless of organization size. This is important in memory-constrained environments such as 128 MB AWS Lambda functions. Callers that need a materialized collection should wrap the result withlist().- deregister_runner(runner: GitHubActionsRunner)[source]¶
De-register a self-hosted runner from the GitHub organization.
Issues
DELETE /orgs/{org}/actions/runners/{runner_id}and raises if GitHub returns a non-2xx response. The caller is responsible for stopping the runner process and terminating its host; this method only removes GitHub’s record of the runner.- Parameters:
runner (GitHubActionsRunner) – The runner to de-register.
- Raises:
requests.HTTPError – If the GitHub API returns a non-2xx status (for example, 404 if the runner was already removed).
- ensure_registration_token(registration_token_secret: str, present=True)[source]¶
Ensure a registration token is present (by default) or absent in AWS Secrets Manager. If the argument present is true, and the registration token is secret does not exist, it will be created. If the argument present is false, and the registration token is secret exist, it will be deleted.
- Parameters:
registration_token_secret (str) – The name of the secret to store the token.
present (bool) – Whether the registration token should be present or not.
- find_runner_by_label(label: str) GitHubActionsRunner | None[source]¶
Find the first runner that has the specified label.
- Parameters:
label (str) – The label to search for.
- Returns:
The first runner matching the label, or None if not found.
- Return type:
GitHubActionsRunner or None
- find_runners_by_label(label: str) Iterator[GitHubActionsRunner][source]¶
Yield all runners that have the specified label.
Iterates lazily over the organization’s runners, fetching subsequent API pages only as the caller advances the iterator. Callers that need a materialized collection should wrap the result with
list().- Parameters:
label (str) – The label to search for.
- Returns:
An iterator of GitHubActionsRunner objects that match the label.
- Return type:
Iterator[GitHubActionsRunner]
- property registration_token: str¶
Request a registration token from GitHub for registering a new runner.
- Returns:
A registration token string.
- Return type:
str
- property runners: Iterator[GitHubActionsRunner]¶
Iterate over all self-hosted runners for the organization.
Yields runners one at a time, fetching subsequent API pages only as the iterator advances. Keeps memory usage bounded to one page when running in memory-constrained environments (e.g. Lambda).
Each access to this property returns a new independent generator. Iterating it consumes the generator; a second
for r in gha.runnersloop will replay the GitHub API calls from scratch. If you need to iterate the same set of runners more than once, wrap the first access withlist()to materialize the results:snapshot = list(gha.runners) busy = [r for r in snapshot if r.busy] idle = [r for r in snapshot if not r.busy]
- Returns:
An iterator of GitHubActionsRunner objects.
- Return type:
Iterator[GitHubActionsRunner]
- class infrahouse_core.github.GitHubActionsRunner(runner_id: int, github: GitHubAuth, runner_data: dict | None = None)[source]¶
Bases:
objectRepresents a GitHub Actions self-hosted runner instance.
Provides access to runner metadata such as status, labels, and instance ID, fetched dynamically via the GitHub API.
- property busy: bool¶
Indicates whether the runner is currently executing a job.
- Returns:
True if the runner is busy, False otherwise.
- Return type:
bool
- property instance_id: str¶
Extract the EC2 instance ID from the runner’s labels.
- Returns:
The instance ID if found, otherwise None.
- Return type:
str or None
- property labels: List[str]¶
List all labels assigned to the runner.
- Returns:
A list of label names.
- Return type:
list[str]
- property name: str¶
Return the name of the runner.
- Returns:
Runner name.
- Return type:
str
- property os: str¶
Return the operating system of the runner.
- Returns:
OS name (e.g., “linux”, “windows”).
- Return type:
str
- property runner_id: int¶
Return the runner ID.
- Returns:
The ID of the GitHub runner.
- Return type:
int
- property status: str¶
Return the runner’s status.
- Returns:
Status string (e.g., “online”, “offline”).
- Return type:
str
- class infrahouse_core.github.GitHubAuth(token: str, org: str)[source]¶
Bases:
objectAuthentication information for GitHub API access.
This class holds the necessary credentials to authenticate with the GitHub API. It is used by other classes in this module to make authenticated API calls.
Warning
Tokens should be stored securely (e.g., AWS Secrets Manager). Never log or print the token value. Rotate tokens regularly following your organization’s security policy.
- Parameters:
token (str) – GitHub Personal Access Token or GitHub App token for authentication. Retrieve from secure storage, never hardcode.
org (str) – GitHub organization name where the runners are registered
- org: str¶
- token: str¶
- infrahouse_core.github.get_tmp_token(gh_app_id: int, pem_key_secret: str, github_org_name: str, region: str | None = None, role_arn: str | None = None) str[source]¶
Generate a temporary GitHub token from GitHUb App PEM key. The GitHub App must be created in your org, can be found in https://github.com/organizations/YOUR_ORG/settings/apps/infrahouse-github-terraform
- Parameters:
gh_app_id (int) – GitHub Application identifier.
pem_key_secret (str) – Secret ARN with the PEM key.
github_org_name – GitHub Organization. Used to find GitHub App installation.
region (str) – AWS region for Secrets Manager operations.
role_arn (str) – IAM role ARN to assume for cross-account access.
- Returns:
GitHub token
- Return type:
str
infrahouse_core.logging module¶
InfraHouse Toolkit Logging.
- class infrahouse_core.logging.LessThanFilter(exclusive_maximum, name='')[source]¶
Bases:
FilterFilters out log messages of a lower level.
- infrahouse_core.logging.setup_logging(logger: Logger | None = None, debug: bool = False, quiet: bool = False, debug_botocore: bool = False) None[source]¶
Configure logging for the module.
Sets up stdout/stderr handlers with level-based routing. The logger is configured in place and nothing is returned.
- Parameters:
logger (logging.Logger or None) – Logger to configure. If
None, uses the root logger.debug (bool) – Enable debug logging.
quiet (bool) – Suppress INFO logs.
debug_botocore (bool) – If True, keep botocore at debug level instead of suppressing it.
infrahouse_core.timeout module¶
InfraHouse timeout module.
infrahouse_core.validation module¶
Input validation utilities for AWS resource identifiers.
- infrahouse_core.validation.validate_dns_name(dns_name: str | None) None[source]¶
Validate DNS zone name format.
- Parameters:
dns_name (str or None) – DNS name to validate
- Raises:
ValueError – If dns_name is invalid
- infrahouse_core.validation.validate_instance_id(instance_id: str | None) None[source]¶
Validate EC2 instance ID format.
- Parameters:
instance_id (str or None) – Instance ID to validate
- Raises:
ValueError – If instance_id is invalid
- infrahouse_core.validation.validate_region(region: str | None) None[source]¶
Validate AWS region name format.
- Parameters:
region (str or None) – AWS region name to validate
- Raises:
ValueError – If region is invalid
Module contents¶
InfraHouse Core Library.
This library provides reusable classes and functions for AWS and GitHub integration.
- Main modules:
aws: AWS service integration (EC2, DynamoDB, Secrets Manager, Route53)
github: GitHub Actions and API integration
logging: Logging configuration utilities
timeout: Timeout context manager for operations