gc_batch.settings
Configuration settings for gc-batch.
This module centralizes every value that differs between deployments (project
ids, VPC network settings, etc.) into a single :class:GCBatchSettings object
with neutral defaults. A deployment adapts gc-batch entirely through
configuration -- environment variables or a TOML file -- with no code changes.
Resolution precedence (highest priority first):
- Explicit constructor arguments, e.g.
GCBatchSettings(job_name_prefix="foo-"). GC_BATCH_*environment variables (nested fields use__as a delimiter, e.g.GC_BATCH_JOB_PROFILES__MY_VPC__NETWORK).- A TOML configuration file, only consulted via :meth:
GCBatchSettings.load. - The neutral defaults defined in this module.
Classes:
| Name | Description |
|---|---|
JobProfile |
A named bundle of networking/VM settings for |
GCBatchSettings |
The top-level settings object. |
GCBatchSettings
Bases: BaseSettings
Top-level configuration for gc-batch.
All fields have neutral defaults. Deployment-specific behavior is supplied
through GC_BATCH_* environment variables or a TOML config file loaded via
:meth:load.
Attributes:
| Name | Type | Description |
|---|---|---|
job_name_prefix |
str
|
Prefix prepended to every created job's name. |
created_using_label |
str
|
Value of the "created-using" label set on every job. |
owner_email_env_vars |
list[str]
|
Environment variables checked, in order, to
determine the "created-by" label value. The default list covers the
All of Us Researcher Workbench, which does not set |
default_project_id |
str | None
|
Fallback GCP project id when none is given on the
command line or via |
job_profiles |
dict[str, JobProfile]
|
Named bundles of networking/VM settings selectable via
|
Source code in src/gc_batch/settings.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
created_using_label = 'gc-batch'
class-attribute
instance-attribute
default_project_id = None
class-attribute
instance-attribute
job_name_prefix = ''
class-attribute
instance-attribute
job_profiles = {None: _built_in_job_profiles(), None: self.job_profiles}
class-attribute
instance-attribute
model_config = SettingsConfigDict(env_prefix='GC_BATCH_', env_nested_delimiter='__', extra='ignore')
class-attribute
instance-attribute
owner_email_env_vars = Field(default_factory=(lambda: ['OWNER_EMAIL', 'WORKBENCH_USER_EMAIL', 'TERRA_USER_EMAIL', 'USER']))
class-attribute
instance-attribute
__init__(**data)
Initialize settings and merge in the built-in job profiles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**data
|
Any
|
Field overrides, following the standard pydantic-settings precedence (constructor arguments > environment variables > configured TOML source > defaults). |
{}
|
Source code in src/gc_batch/settings.py
173 174 175 176 177 178 179 180 181 182 | |
load(config_file=None, **overrides)
classmethod
Load settings, including values from a TOML configuration file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file
|
str | Path | None
|
An explicit path to a TOML config file. When omitted,
the standard discovery order is used: |
None
|
**overrides
|
Any
|
Explicit field overrides, which take precedence over everything else (environment variables, the TOML file, and defaults). |
{}
|
Returns:
| Type | Description |
|---|---|
GCBatchSettings
|
A fully resolved |
Source code in src/gc_batch/settings.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
settings_customise_sources(settings_cls, init_settings, env_settings, dotenv_settings, file_secret_settings)
classmethod
Insert a TOML file source between env vars and the default sources.
Returns:
| Type | Description |
|---|---|
PydanticBaseSettingsSource
|
The settings sources in priority order (highest first): constructor |
...
|
arguments, environment variables, the TOML file (if one was |
tuple[PydanticBaseSettingsSource, ...]
|
requested via :meth: |
tuple[PydanticBaseSettingsSource, ...]
|
sources that fall through to field defaults. |
Source code in src/gc_batch/settings.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
JobProfile
Bases: BaseModel
A named bundle of networking/VM settings applied via --job-profile.
Attributes:
| Name | Type | Description |
|---|---|---|
network |
str | None
|
VPC network path for the VM (e.g. "global/networks/network"). |
subnetwork |
str | None
|
Subnetwork path for the VM. |
use_private_address |
bool
|
Whether to use a private IP (no external IP). |
regions |
list[str] | None
|
List of allowed regions for job placement. |
service_account_from_gcloud |
bool
|
Whether to resolve the job's service account
from the current |
cloud_logging_unreadable |
bool
|
Whether callers in this environment are expected
to be unable to read Cloud Logging. When |
Source code in src/gc_batch/settings.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |