-
Notifications
You must be signed in to change notification settings - Fork 31
/
settings.go
155 lines (147 loc) · 6.14 KB
/
settings.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package quota
import (
"github.com/dynatrace-oss/terraform-provider-dynatrace/terraform/hcl"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
// Settings represents environment level consumption and quotas information. Only returned if includeConsumptionInfo or includeUncachedConsumptionInfo param is true. If skipped when editing via PUT method then already set quotas will remain
type Settings struct {
HostUnits *HostUnits `json:"hostUnits,omitempty"` // Host units consumption and quota information on environment level. If skipped when editing via PUT method then already set quota will remain
DEMUnits *DEMUnits `json:"demUnits,omitempty"` // DEM units consumption and quota information on environment level. Not set (and not editable) if DEM units is not enabled. If skipped when editing via PUT method then already set quotas will remain
UserSessions *UserSessions `json:"userSessions,omitempty"` // User sessions consumption and quota information on environment level. If skipped when editing via PUT method then already set quotas will remain
Synthetic *Synthetic `json:"syntheticMonitors,omitempty"` // Synthetic monitors consumption and quota information on environment level. Not set (and not editable) if neither Synthetic nor DEM units is enabled. If skipped when editing via PUT method then already set quotas will remain
DDUs *DavisDataUnits `json:"davisDataUnits,omitempty"` // Davis Data Units consumption and quota information on environment level. Not set (and not editable) if Davis data units is not enabled. If skipped when editing via PUT method then already set quotas will remain
LogMonitoring *LogMonitoring `json:"logMonitoring,omitempty"` // Log Monitoring consumption and quota information on environment level. Not set (and not editable) if Log monitoring is not enabled. Not set (and not editable) if Log monitoring is migrated to Davis data on license level. If skipped when editing via PUT method then already set quotas will remain
}
func (me *Settings) IsEmpty() bool {
if me == nil {
return true
}
return me.HostUnits.IsEmpty() &&
me.DEMUnits.IsEmpty() &&
me.UserSessions.IsEmpty() &&
me.Synthetic.IsEmpty() &&
me.DDUs.IsEmpty() &&
me.LogMonitoring.IsEmpty()
}
func (me *Settings) Schema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"host_units": {
Type: schema.TypeInt,
Optional: true,
Description: "Host units consumption and quota information on environment level",
},
"dem_units": {
Type: schema.TypeList,
MinItems: 1,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{Schema: new(DEMUnits).Schema()},
Description: "DEM units consumption and quota information on environment level",
},
"user_sessions": {
Type: schema.TypeList,
MinItems: 1,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{Schema: new(UserSessions).Schema()},
Description: "User sessions consumption and quota information on environment level",
},
"synthetic": {
Type: schema.TypeList,
MinItems: 1,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{Schema: new(Synthetic).Schema()},
Description: "Synthetic monitors consumption and quota information on environment level. Not set (and not editable) if neither Synthetic nor DEM units is enabled",
},
"ddus": {
Type: schema.TypeList,
MinItems: 1,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{Schema: new(DavisDataUnits).Schema()},
Description: "Davis Data Units consumption and quota information on environment level. Not set (and not editable) if Davis data units is not enabled",
},
"logs": {
Type: schema.TypeList,
MinItems: 1,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{Schema: new(LogMonitoring).Schema()},
Description: "Log Monitoring consumption and quota information on environment level. Not set (and not editable) if Log monitoring is not enabled. Not set (and not editable) if Log monitoring is migrated to Davis data on license level",
},
}
}
func (me *Settings) MarshalHCL(properties hcl.Properties) error {
if !me.HostUnits.IsEmpty() {
if err := properties.Encode("host_units", me.HostUnits.MaxLimit); err != nil {
return err
}
}
if !me.DEMUnits.IsEmpty() {
if err := properties.Encode("dem_units", me.DEMUnits); err != nil {
return err
}
}
if !me.UserSessions.IsEmpty() {
if err := properties.Encode("user_sessions", me.UserSessions); err != nil {
return err
}
}
if !me.Synthetic.IsEmpty() {
if err := properties.Encode("synthetic", me.Synthetic); err != nil {
return err
}
}
if me.DDUs != nil && !me.DDUs.IsEmpty() {
if err := properties.Encode("ddus", me.DDUs); err != nil {
return err
}
}
if me.LogMonitoring != nil && !me.LogMonitoring.IsEmpty() {
if err := properties.Encode("logs", me.LogMonitoring); err != nil {
return err
}
}
return nil
}
func (me *Settings) UnmarshalHCL(decoder hcl.Decoder) error {
me.HostUnits = new(HostUnits)
if err := decoder.Decode("host_units", &me.HostUnits.MaxLimit); err != nil {
return err
}
if err := decoder.Decode("dem_units", &me.DEMUnits); err != nil {
return err
}
if me.DEMUnits == nil {
me.DEMUnits = &DEMUnits{MonthlyLimit: nil, AnnualLimit: nil}
}
if err := decoder.Decode("user_sessions", &me.UserSessions); err != nil {
return err
}
if me.UserSessions == nil {
me.UserSessions = &UserSessions{TotalAnnualLimit: nil, TotalMonthlyLimit: nil}
}
if err := decoder.Decode("synthetic", &me.Synthetic); err != nil {
return err
}
if me.Synthetic == nil {
me.Synthetic = &Synthetic{MonthlyLimit: nil, AnnualLimit: nil}
}
if err := decoder.Decode("ddus", &me.DDUs); err != nil {
return err
}
if me.DDUs == nil {
me.DDUs = &DavisDataUnits{MonthlyLimit: nil, AnnualLimit: nil}
}
if err := decoder.Decode("logs", &me.LogMonitoring); err != nil {
return err
}
if me.LogMonitoring != nil && me.LogMonitoring.IsEmpty() {
me.LogMonitoring = nil
}
// if me.LogMonitoring == nil {
// me.LogMonitoring = &LogMonitoring{MonthlyLimit: nil, AnnualLimit: nil}
// }
return nil
}