BuildAWFConfigJSON generates a compact JSON config file for AWF from the provided command configuration. The JSON is single-line (no indentation) for safe embedding in a shell printf command. The caller is responsible for writing the returned JSON to disk at the path expected by the AWF --config fl
(config AWFCommandConfig)
| 377 | // The caller is responsible for writing the returned JSON to disk at the path expected |
| 378 | // by the AWF --config flag. See BuildAWFCommand for how this is wired together. |
| 379 | func BuildAWFConfigJSON(config AWFCommandConfig) (string, error) { |
| 380 | awfConfigLog.Printf("Building AWF config JSON: engine=%s, allowed_domains=%q", config.EngineName, config.AllowedDomains) |
| 381 | |
| 382 | // Resolve firewall config once — used for both the schema URL and the container image tag. |
| 383 | firewallConfig := getFirewallConfig(config.WorkflowData) |
| 384 | |
| 385 | awfConfig := AWFConfigFile{ |
| 386 | Schema: buildAWFConfigSchemaURL(firewallConfig), |
| 387 | } |
| 388 | |
| 389 | // ── Runner section ────────────────────────────────────────────────────── |
| 390 | if topology := getRunnerTopology(config.WorkflowData); topology != "" { |
| 391 | awfConfig.Runner = &AWFRunnerConfig{Topology: topology} |
| 392 | awfConfigLog.Printf("Runner section: topology=%s", topology) |
| 393 | } |
| 394 | |
| 395 | // ── Network section ────────────────────────────────────────────────────── |
| 396 | if config.AllowedDomains != "" { |
| 397 | allowList := splitDomainList(config.AllowedDomains) |
| 398 | awfConfig.Network = &AWFNetworkConfig{ |
| 399 | AllowDomains: allowList, |
| 400 | } |
| 401 | awfConfigLog.Printf("Network section: %d allowed domains", len(allowList)) |
| 402 | |
| 403 | // Blocked domains (if configured in the workflow) |
| 404 | if config.WorkflowData != nil { |
| 405 | blockedDomainsStr := formatBlockedDomains(config.WorkflowData.NetworkPermissions) |
| 406 | if blockedDomainsStr != "" { |
| 407 | blockList := splitDomainList(blockedDomainsStr) |
| 408 | awfConfig.Network.BlockDomains = blockList |
| 409 | awfConfigLog.Printf("Network section: %d blocked domains", len(blockList)) |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | if isAWFNetworkIsolationEnabled(config.WorkflowData) { |
| 415 | if awfConfig.Network == nil { |
| 416 | awfConfig.Network = &AWFNetworkConfig{} |
| 417 | } |
| 418 | awfConfig.Network.Isolation = true |
| 419 | awfConfig.Network.TopologyAttach = buildAWFTopologyAttachList(config.WorkflowData) |
| 420 | awfConfigLog.Printf("Network section: isolation enabled with %d topology attachments", len(awfConfig.Network.TopologyAttach)) |
| 421 | } |
| 422 | |
| 423 | if platformType := extractPlatformType(config.WorkflowData); platformType != "" { |
| 424 | awfConfig.Platform = &AWFPlatformConfig{Type: platformType} |
| 425 | awfConfigLog.Printf("Platform section: type=%s", platformType) |
| 426 | } |
| 427 | |
| 428 | // ── API proxy section ───────────────────────────────────────────────────── |
| 429 | // maxAICredits is taken from frontmatter/imports only; when unset (0) the |
| 430 | // runtime value is resolved from vars.GH_AW_DEFAULT_MAX_AI_CREDITS via a |
| 431 | // GitHub Actions expression injected directly into the JSON string in |
| 432 | // BuildAWFCommand (see injectMaxAICreditsExpression in awf_helpers.go). |
| 433 | maxAICredits := int64(0) |
| 434 | maxRuns := constants.DefaultMaxRuns |
| 435 | // GetMaxTurnCacheMisses handles nil receiver and env-var fallback, so pre-init |
| 436 | // via the nil receiver avoids a redundant os.Getenv when EngineConfig is set. |