MCPcopy Create free account
hub / github.com/Hidden-Node/GooseRelayVPN-AndroidClient / parseScriptKeys

Function parseScriptKeys

internal/config/client.go:201–227  ·  view source on GitHub ↗

parseScriptKeys turns the script_keys JSON value into a slice of entries. Returns a usage-friendly error when a particular element is malformed so the user can fix the right index without parsing line numbers.

(raw json.RawMessage)

Source from the content-addressed store, hash-verified

199// Returns a usage-friendly error when a particular element is malformed so
200// the user can fix the right index without parsing line numbers.
201func parseScriptKeys(raw json.RawMessage) ([]scriptKeyEntry, error) {
202 if len(raw) == 0 {
203 return nil, nil
204 }
205 var arr []json.RawMessage
206 if err := json.Unmarshal(raw, &arr); err != nil {
207 return nil, fmt.Errorf("script_keys must be a JSON array (a list of strings or {id, account} objects)")
208 }
209 out := make([]scriptKeyEntry, 0, len(arr))
210 for i, item := range arr {
211 // Try the bare-string form first (preserves the existing config shape).
212 var s string
213 if err := json.Unmarshal(item, &s); err == nil {
214 out = append(out, scriptKeyEntry{ID: s})
215 continue
216 }
217 var obj scriptKeyEntry
218 if err := json.Unmarshal(item, &obj); err != nil {
219 return nil, fmt.Errorf("script_keys[%d] must be a Deployment ID string or an object {\"id\": \"...\", \"account\": \"...\"}", i)
220 }
221 if strings.TrimSpace(obj.ID) == "" {
222 return nil, fmt.Errorf("script_keys[%d] is an object without an \"id\" field — provide the Deployment ID there", i)
223 }
224 out = append(out, obj)
225 }
226 return out, nil
227}
228
229// validateDeploymentID checks that the value looks like an Apps Script
230// deployment ID and produces a hint when it looks like a common copy-paste

Callers 2

generateConfigMethod · 0.85
LoadClientFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected