/
resource_aam_authentication_account_stats.go
103 lines (94 loc) · 3.74 KB
/
resource_aam_authentication_account_stats.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
package thunder
import (
"context"
edpt "github.com/a10networks/terraform-provider-thunder/thunder/axapi/endpoint"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func resourceAamAuthenticationAccountStats() *schema.Resource {
return &schema.Resource{
Description: "`thunder_aam_authentication_account_stats`: Statistics for the object account\n\n__PLACEHOLDER__",
ReadContext: resourceAamAuthenticationAccountStatsRead,
Schema: map[string]*schema.Schema{
"stats": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"request_normal": {
Type: schema.TypeInt, Optional: true, Description: "Total Normal Request",
},
"request_dropped": {
Type: schema.TypeInt, Optional: true, Description: "Total Dropped Request",
},
"response_success": {
Type: schema.TypeInt, Optional: true, Description: "Total Success Response",
},
"response_failure": {
Type: schema.TypeInt, Optional: true, Description: "Total Failure Response",
},
"response_error": {
Type: schema.TypeInt, Optional: true, Description: "Total Error Response",
},
"response_timeout": {
Type: schema.TypeInt, Optional: true, Description: "Total Timeout Response",
},
"response_other": {
Type: schema.TypeInt, Optional: true, Description: "Total Other Response",
},
},
},
},
},
}
}
func resourceAamAuthenticationAccountStatsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceAamAuthenticationAccountStatsRead()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointAamAuthenticationAccountStats(d)
res, err := obj.Get(client.Token, client.Host, d.Id(), logger)
d.SetId(obj.GetId())
logger.Println(res)
AamAuthenticationAccountStatsStats := setObjectAamAuthenticationAccountStatsStats(res)
d.Set("stats", AamAuthenticationAccountStatsStats)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func setObjectAamAuthenticationAccountStatsStats(ret edpt.DataAamAuthenticationAccountStats) []interface{} {
return []interface{}{
map[string]interface{}{
"request_normal": ret.DtAamAuthenticationAccountStats.Stats.RequestNormal,
"request_dropped": ret.DtAamAuthenticationAccountStats.Stats.RequestDropped,
"response_success": ret.DtAamAuthenticationAccountStats.Stats.ResponseSuccess,
"response_failure": ret.DtAamAuthenticationAccountStats.Stats.ResponseFailure,
"response_error": ret.DtAamAuthenticationAccountStats.Stats.ResponseError,
"response_timeout": ret.DtAamAuthenticationAccountStats.Stats.ResponseTimeout,
"response_other": ret.DtAamAuthenticationAccountStats.Stats.ResponseOther,
},
}
}
func getObjectAamAuthenticationAccountStatsStats(d []interface{}) edpt.AamAuthenticationAccountStatsStats {
count1 := len(d)
var ret edpt.AamAuthenticationAccountStatsStats
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.RequestNormal = in["request_normal"].(int)
ret.RequestDropped = in["request_dropped"].(int)
ret.ResponseSuccess = in["response_success"].(int)
ret.ResponseFailure = in["response_failure"].(int)
ret.ResponseError = in["response_error"].(int)
ret.ResponseTimeout = in["response_timeout"].(int)
ret.ResponseOther = in["response_other"].(int)
}
return ret
}
func dataToEndpointAamAuthenticationAccountStats(d *schema.ResourceData) edpt.AamAuthenticationAccountStats {
var ret edpt.AamAuthenticationAccountStats
ret.Stats = getObjectAamAuthenticationAccountStatsStats(d.Get("stats").([]interface{}))
return ret
}