1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package participant
import (
"encoding/json"
"errors"
"fmt"
"strings"
"gopkg.in/yaml.v3"
)
const PolicyRecordType = "computer.socialweb.temp.policy.ghalite"
func PolicyRecordWorkflow(value map[string]any) (json.RawMessage, error) {
if kind, _ := value["$type"].(string); kind != PolicyRecordType {
return nil, fmt.Errorf("the policy record type %q is not gha-lite and is denied", kind)
}
raw, ok := value["workflow"]
if !ok || raw == nil {
return nil, errors.New("the policy record names no workflow")
}
switch v := raw.(type) {
case string:
if strings.TrimSpace(v) == "" {
return nil, errors.New("the policy record names an empty workflow")
}
var parsed map[string]any
if err := yaml.Unmarshal([]byte(v), &parsed); err != nil || parsed == nil {
return nil, errors.New("the policy record's workflow is not a gha-lite workflow mapping")
}
return json.Marshal(parsed)
case map[string]any:
return json.Marshal(v)
default:
return nil, errors.New("the policy record's workflow is not a string or object")
}
}