Main entry point for the deployment script. Args: args (list[str] | None): CLI arguments. Defaults to sys.argv. Returns: int: Exit code (0 for success).
(args: list[str] | None = None)
| 1153 | |
| 1154 | |
| 1155 | def main(args: list[str] | None = None) -> int: |
| 1156 | """ |
| 1157 | Main entry point for the deployment script. |
| 1158 | |
| 1159 | Args: |
| 1160 | args (list[str] | None): CLI arguments. Defaults to sys.argv. |
| 1161 | |
| 1162 | Returns: |
| 1163 | int: Exit code (0 for success). |
| 1164 | """ |
| 1165 | parsed = parse_args(args) |
| 1166 | |
| 1167 | instance = parsed.instance_name |
| 1168 | env_file = parsed.env_file.resolve() |
| 1169 | |
| 1170 | if not env_file.exists(): |
| 1171 | logger.error("Env file not found: %s", env_file) |
| 1172 | return 1 |
| 1173 | |
| 1174 | if not BICEP_TEMPLATE.exists(): |
| 1175 | logger.error("Bicep template not found: %s", BICEP_TEMPLATE) |
| 1176 | return 1 |
| 1177 | |
| 1178 | # Derive resource names from instance name |
| 1179 | rg_name = f"copyrit-{instance}" |
| 1180 | app_name = f"copyrit-{instance}" |
| 1181 | sql_server_name = f"copyrit-{instance}-sql" |
| 1182 | sql_db_name = f"pyrit-{instance}" |
| 1183 | kv_name = f"copyrit-{instance}-kv" |
| 1184 | storage_account_name = _storage_account_name(instance) |
| 1185 | entra_app_name = f"CoPyRIT GUI ({instance})" |
| 1186 | group_ids = [g.strip() for g in parsed.allowed_groups.split(",") if g.strip()] |
| 1187 | |
| 1188 | # Validate Azure resource name length constraints |
| 1189 | if len(kv_name) > 24: |
| 1190 | logger.error( |
| 1191 | "Key Vault name '%s' exceeds 24-char limit (got %d). Use a shorter --instance-name (max 13 characters).", |
| 1192 | kv_name, |
| 1193 | len(kv_name), |
| 1194 | ) |
| 1195 | return 1 |
| 1196 | if len(app_name) > 32: |
| 1197 | logger.error( |
| 1198 | "Container App name '%s' exceeds 32-char limit (got %d). " |
| 1199 | "Use a shorter --instance-name (max 24 characters).", |
| 1200 | app_name, |
| 1201 | len(app_name), |
| 1202 | ) |
| 1203 | return 1 |
| 1204 | if len(storage_account_name) > 24 or len(storage_account_name) < 3: |
| 1205 | logger.error( |
| 1206 | "Storage account name '%s' is %d chars (must be 3-24). " |
| 1207 | "After stripping non-alphanumerics from --instance-name, the name " |
| 1208 | "is 'copyrit{normalized}sa'. Use an --instance-name whose alphanumeric " |
| 1209 | "length keeps the total under 24.", |
| 1210 | storage_account_name, |
| 1211 | len(storage_account_name), |
| 1212 | ) |
no test coverage detected