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

Function parseSafeScriptsConfig

pkg/workflow/safe_scripts.go:26–76  ·  view source on GitHub ↗

parseSafeScriptsConfig parses safe-scripts configuration from a scripts map. This function expects a map of script configurations directly (from safe-outputs.scripts).

(scriptsMap map[string]any)

Source from the content-addressed store, hash-verified

24// parseSafeScriptsConfig parses safe-scripts configuration from a scripts map.
25// This function expects a map of script configurations directly (from safe-outputs.scripts).
26func parseSafeScriptsConfig(scriptsMap map[string]any) map[string]*SafeScriptConfig {
27 if scriptsMap == nil {
28 return nil
29 }
30
31 safeScriptsLog.Printf("Parsing %d safe-scripts from scripts map", len(scriptsMap))
32 result := make(map[string]*SafeScriptConfig)
33
34 for scriptName, scriptValue := range scriptsMap {
35 scriptConfig, ok := scriptValue.(map[string]any)
36 if !ok {
37 continue
38 }
39
40 safeScript := &SafeScriptConfig{}
41
42 // Parse name
43 if name, exists := scriptConfig["name"]; exists {
44 if nameStr, ok := name.(string); ok {
45 safeScript.Name = nameStr
46 }
47 }
48
49 // Parse description
50 if description, exists := scriptConfig["description"]; exists {
51 if descStr, ok := description.(string); ok {
52 safeScript.Description = descStr
53 }
54 }
55
56 // Parse inputs using the unified parsing function
57 if inputs, exists := scriptConfig["inputs"]; exists {
58 if inputsMap, ok := inputs.(map[string]any); ok {
59 safeScript.Inputs = ParseInputDefinitions(inputsMap)
60 }
61 }
62
63 // Parse script content
64 if script, exists := scriptConfig["script"]; exists {
65 if scriptStr, ok := script.(string); ok {
66 safeScript.Script = scriptStr
67 }
68 }
69
70 safeScriptsLog.Printf("Parsed safe-script configuration: name=%s, has_script=%v, has_inputs=%v",
71 scriptName, safeScript.Script != "", len(safeScript.Inputs) > 0)
72 result[scriptName] = safeScript
73 }
74
75 return result
76}
77
78// isSafeScriptName returns true if the script name is safe for use as a filename component.
79// It rejects names that contain path separators or ".." sequences that could lead to

Callers 3

Calls 2

ParseInputDefinitionsFunction · 0.85
PrintfMethod · 0.45

Tested by 2