oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package provider
2
3import (
4 "bytes"
5 "encoding/json"
6 "io"
7 "strings"
8)
9
10// QuestionAnswers admits only a complete set of answers for the original keys.
11// Provider tool inputs, permissions and commands cannot be replaced by a reply.
12func QuestionAnswers(raw json.RawMessage, keys []string) (map[string]string, error) {
13 var v struct {
14 Answers map[string]string `json:"answers"`
15 }
16 d := json.NewDecoder(bytes.NewReader(raw))
17 d.DisallowUnknownFields()
18 if d.Decode(&v) != nil || d.Decode(new(any)) != io.EOF || len(keys) == 0 || len(v.Answers) != len(keys) {
19 return nil, ErrPolicy
20 }
21 seen := map[string]bool{}
22 for _, key := range keys {
23 if key == "" || seen[key] || strings.TrimSpace(v.Answers[key]) == "" || len(v.Answers[key]) > 8192 {
24 return nil, ErrPolicy
25 }
26 seen[key] = true
27 }
28 return v.Answers, nil
29}
30