-
Notifications
You must be signed in to change notification settings - Fork 24
/
types.go
71 lines (59 loc) · 1.46 KB
/
types.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package pike
import "strings"
// Sorted is to help split out permission to the relevant auth.
type Sorted struct {
AWS []string
GCP []string
AZURE []string
}
// ResourceV2 is what resources get parsed into.
type ResourceV2 struct {
TypeName string
Name string
ResourceName string
Provider string
Attributes []string
}
// Policy creates iam policies.
type Policy struct {
Version string `json:"Version"`
Statements []Statement `json:"Statement"`
}
// Statement is the core of an IAM policy.
type Statement struct {
Sid string `json:"Sid"`
Effect string `json:"Effect"`
Action []string `json:"Action"`
Resource []string `json:"Resource"`
}
// NewStatement constructor.
func NewStatement(sid string, effect string, action []string, resource []string) *Statement {
return &Statement{Sid: sid, Effect: effect, Action: action, Resource: resource}
}
// OutputPolicy is the main output type.
type OutputPolicy struct {
AWS AwsOutput
GCP string
AZURE string
}
// AwsOutput structure.
type AwsOutput struct {
JSONOut string
Terraform string
}
// AsString converts object into string.
func (out OutputPolicy) AsString(format string) string {
var Output string
if strings.ToLower(format) == terraform {
Output = out.AWS.Terraform + "\n"
} else {
Output = out.AWS.JSONOut + "\n"
}
if out.GCP != "" {
Output = Output + out.GCP + "\n"
}
if out.AZURE != "" {
Output = Output + out.AZURE + "\n"
}
return Output
}