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

Function updateNetworkAllowed

pkg/cli/codemod_mcp_network.go:289–362  ·  view source on GitHub ↗

updateNetworkAllowed updates the existing top-level network.allowed configuration

(lines []string, domains []string)

Source from the content-addressed store, hash-verified

287
288// updateNetworkAllowed updates the existing top-level network.allowed configuration
289func updateNetworkAllowed(lines []string, domains []string) []string {
290 var result []string
291 var inNetworkBlock bool
292 var networkIndent string
293 var inAllowedBlock bool
294 var allowedIndent string
295 var replacedAllowed bool
296
297 for _, line := range lines {
298 trimmedLine := strings.TrimSpace(line)
299
300 // Track if we're in network block
301 if strings.HasPrefix(trimmedLine, "network:") {
302 inNetworkBlock = true
303 networkIndent = getIndentation(line)
304 result = append(result, line)
305 continue
306 }
307
308 // Check if we've left network block
309 if inNetworkBlock && len(trimmedLine) > 0 && !strings.HasPrefix(trimmedLine, "#") {
310 if hasExitedBlock(line, networkIndent) {
311 inNetworkBlock = false
312 inAllowedBlock = false
313 }
314 }
315
316 // Track if we're in allowed block within network
317 if inNetworkBlock && strings.HasPrefix(trimmedLine, "allowed:") {
318 inAllowedBlock = true
319 allowedIndent = getIndentation(line)
320 replacedAllowed = true
321 // Replace the allowed block
322 result = append(result, line)
323 for _, domain := range domains {
324 result = append(result, fmt.Sprintf("%s - %s", allowedIndent, domain))
325 }
326 continue
327 }
328
329 // Skip existing allowed array items
330 if inAllowedBlock {
331 currentIndent := getIndentation(line)
332
333 // Empty lines - skip
334 if trimmedLine == "" {
335 continue
336 }
337
338 // Comments at deeper indentation - skip
339 if strings.HasPrefix(trimmedLine, "#") && len(currentIndent) > len(allowedIndent) {
340 continue
341 }
342
343 // Array items (lines starting with -)
344 if strings.HasPrefix(trimmedLine, "-") && len(currentIndent) > len(allowedIndent) {
345 continue
346 }

Calls 3

getIndentationFunction · 0.85
hasExitedBlockFunction · 0.85
addAllowedToNetworkFunction · 0.85

Tested by

no test coverage detected