MCPcopy Create free account
hub / github.com/github/gh-aw / extractAPITargetHost

Function extractAPITargetHost

pkg/workflow/engine_api_targets.go:35–72  ·  view source on GitHub ↗

extractAPITargetHost extracts the hostname from a custom API base URL in engine.env. This supports custom OpenAI-compatible or Anthropic-compatible endpoints (e.g., internal LLM routers, Azure OpenAI) while preserving AWF's credential isolation and firewall features. The function: 1. Checks if the

(workflowData *WorkflowData, envVar string)

Source from the content-addressed store, hash-verified

33// extractAPITargetHost(workflowData, "OPENAI_BASE_URL")
34// // Returns: "llm-router.internal.example.com"
35func extractAPITargetHost(workflowData *WorkflowData, envVar string) string {
36 // Check if engine config and env are available
37 if workflowData == nil || workflowData.EngineConfig == nil || workflowData.EngineConfig.Env == nil {
38 return ""
39 }
40
41 // Get the custom base URL from engine.env
42 baseURL, exists := workflowData.EngineConfig.Env[envVar]
43 if !exists || baseURL == "" {
44 return ""
45 }
46
47 // Extract hostname from URL
48 // URLs can be:
49 // - "https://llm-router.internal.example.com/v1" → "llm-router.internal.example.com"
50 // - "http://localhost:8080/v1" → "localhost:8080"
51 // - "api.openai.com" → "api.openai.com" (treated as hostname)
52
53 // Remove protocol prefix if present
54 host := baseURL
55 if idx := strings.Index(host, "://"); idx != -1 {
56 host = host[idx+3:]
57 }
58
59 // Remove path suffix if present (everything after first /)
60 if idx := strings.Index(host, "/"); idx != -1 {
61 host = host[:idx]
62 }
63
64 // Validate that we have a non-empty hostname
65 if host == "" {
66 awfHelpersLog.Printf("Invalid %s URL (no hostname): %s", envVar, baseURL)
67 return ""
68 }
69
70 awfHelpersLog.Printf("Extracted API target host from %s: %s", envVar, host)
71 return host
72}
73
74// extractAPIBasePath extracts the path component from a custom API base URL in engine.env.
75// Returns the path prefix (e.g., "/serving-endpoints") or empty string if no path is present.

Callers 6

GetCopilotAPITargetFunction · 0.85
GetAntigravityAPITargetFunction · 0.85
GetGeminiAPITargetFunction · 0.85
BuildAWFConfigJSONFunction · 0.85
TestExtractAPITargetHostFunction · 0.85

Calls 1

PrintfMethod · 0.45

Tested by 1

TestExtractAPITargetHostFunction · 0.68