-
Notifications
You must be signed in to change notification settings - Fork 9
/
policy.go
50 lines (42 loc) · 1.09 KB
/
policy.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package iam
import (
"bytes"
"fmt"
)
type PolicyDocument struct {
Version string
Statement []StatementEntry
}
type StatementEntry struct {
Effect string
Principal *Principal `json:"Principal,omitempty"`
Action []string `json:"Action,omitempty"`
Resource []string `json:"Resource,omitempty"`
Condition *Condition `json:"Condition,omitempty"`
}
type Principal struct {
Federated string `json:"Federated,omitempty"`
AWS string `json:"AWS,omitempty"`
}
type Condition struct {
StringEquals []Condition_KeyValue
}
type Condition_KeyValue struct {
Key string
Value string
}
func (c Condition) MarshalJSON() ([]byte, error) {
var b bytes.Buffer
fmt.Fprintf(&b, "{%q:{", "StringEquals")
for k, kv := range c.StringEquals {
fmt.Fprintf(&b, "%q:%q", kv.Key, kv.Value)
if k < len(c.StringEquals)-1 {
fmt.Fprintf(&b, ",")
}
}
fmt.Fprintf(&b, "}}")
return b.Bytes(), nil
}