Skip to content

Commit fb3c995

Browse files
committed
adding source to response implementations
1 parent 8320928 commit fb3c995

File tree

239 files changed

+2824
-2664
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

239 files changed

+2824
-2664
lines changed

api_client_common.go

+3-81
Original file line numberDiff line numberDiff line change
@@ -15,84 +15,6 @@ import (
1515
"time"
1616
)
1717

18-
const (
19-
VSZResourceNameCluster = "CLUSTER_CATEGORY"
20-
VSZResourceNameAP = "AP_CATEGORY"
21-
VSZResourceNameWLAN = "WLAN_CATEGORY"
22-
VSZResourceNameDevice = "DEVICE_CATEGORY"
23-
VSZResourceNameAdministrator = "ADMINISTRATOR_CATEGORY"
24-
VSZResourceNameTenant = "TENANT_CATEGORY"
25-
VSZResourceNameICX = "ICX_CATEGORY"
26-
27-
VSZResourceDisplayCluster = "SZ"
28-
VSZResourceDisplayAP = "AP"
29-
VSZResourceDisplayWLAN = "WLAN"
30-
VSZResourceDisplayDevice = "User/Device/App"
31-
VSZResourceDisplayAdministrator = "Admin"
32-
VSZResourceDisplayTenant = "MVNO"
33-
VSZResourceDisplayICX = "ICX Switch"
34-
35-
VSZResourceAccessFullAccess = "FULL_ACCESS"
36-
VSZResourceAccessModify = "MODIFY"
37-
VSZResourceAccessReadOnly = "READ_ONLY"
38-
VSZResourceAccessRead = "READ"
39-
VSZResourceAccessNoAccess = "NO_ACCESS"
40-
41-
VSZRoleNameSuperAdmin = "SUPER_ADMIN"
42-
VSZRoleNameSystemAdmin = "SYSTEM_ADMIN"
43-
VSZRoleNameReadOnlySystemAdmin = "RO_SYSTEM_ADMIN"
44-
VSZRoleNameNetworkAdmin = "NETWORK_ADMIN"
45-
VSZRoleNameReadOnlyNetworkAdmin = "RO_NETWORK_ADMIN"
46-
VSZRoleNameAPAdmin = "AP_ADMIN"
47-
VSZRoleNameGuestPassAdmin = "GUEST_PASS_ADMIN"
48-
VSZRoleNameCustom = "CUSTOM"
49-
50-
VSZRoleLabelSuperAdmin = "Super Admin"
51-
VSZRoleLabelSystemAdmin = "System Admin"
52-
VSZRoleLabelReadOnlySystemAdmin = "Read-Only System Admin"
53-
VSZRoleLabelNetworkAdmin = "Network Admin"
54-
VSZRoleLabelReadOnlyNetworkAdmin = "Read-Only Network Admin"
55-
VSZRoleLabelAPAdmin = "AP Admin"
56-
VSZRoleLabelGuestPassAdmin = "Guest Pass Admin"
57-
VSZRoleLabelCustom = "SCGAdmin"
58-
59-
VSZSecurityProfileNameDefault = "Default"
60-
VSZSecurityProfileNameMoreSecure = "More Secure"
61-
62-
VSZDomainTypeRegular = "REGULAR"
63-
VSZDomainTypePartner = "PARTNER"
64-
65-
VSZServiceTicketQueryParameter = "serviceTicket"
66-
)
67-
68-
const (
69-
SCIAccessTokenQueryParameter = "access_token"
70-
71-
// 2016-04-06T16:04:46+00:00
72-
SCIFilterTimestampFormat = "2006-01-02T15:04:05-07:00"
73-
)
74-
75-
const (
76-
logDebugAPIRequestPrepFormat = "Preparing api request #%d \"%s %s\""
77-
logDebugAPIRequestNoBodyFormat = "%s without body"
78-
logDebugAPIRequestWithBodyFormat = "%s with body"
79-
)
80-
81-
const (
82-
uriPathParameterSearchFormat = "{%s}"
83-
uriQueryParameterPrefixFormat = "%s?%s"
84-
85-
apiRequestURLFormat = "%s%s%s"
86-
87-
headerKeyContentType = "Content-Type"
88-
headerKeyContentEncoding = "Content-Encoding"
89-
headerKeyContentDisposition = "Content-Disposition"
90-
headerKeyContentLength = "Content-Length"
91-
headerKeyAccept = "Accept"
92-
headerValueApplicationJSON = "application/json"
93-
headerValueMultipartFormData = "multipart/form-data"
94-
)
95-
9618
// todo: export this?
9719
type APIAuthProviderError struct {
9820
meta APIResponseMeta
@@ -244,11 +166,11 @@ func handleAPIResponse(req *APIRequest, successCode int, httpResp *http.Response
244166
if httpResp != nil {
245167
cleanupReadCloser(httpResp.Body)
246168
}
247-
return respFact(aerr.ResponseMeta(), nil), aerr
169+
return respFact(req.Source, aerr.ResponseMeta(), nil), aerr
248170
}
249171

250172
// otherwise, pass on constructed response and incoming error
251-
return respFact(newAPIResponseMeta(req, successCode, httpResp), nil), sourceErr
173+
return respFact(req.Source, newAPIResponseMeta(req, successCode, httpResp), nil), sourceErr
252174
}
253175

254176
// this _should_ never happen, but check for it anyway.
@@ -257,7 +179,7 @@ func handleAPIResponse(req *APIRequest, successCode int, httpResp *http.Response
257179
}
258180

259181
// construct response
260-
apiResp := respFact(newAPIResponseMeta(req, successCode, httpResp), httpResp.Body)
182+
apiResp := respFact(req.Source, newAPIResponseMeta(req, successCode, httpResp), httpResp.Body)
261183

262184
// if the response code matches the expected "success" code...
263185
if httpResp.StatusCode == successCode {

api_request.go

+27-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ import (
1616
"sync/atomic"
1717
)
1818

19+
type APISource int
20+
21+
const (
22+
APISourceUnknown APISource = iota
23+
APISourceVSZ
24+
APISourceSCI
25+
)
26+
27+
func (s APISource) String() string {
28+
switch s {
29+
case APISourceVSZ:
30+
return "vsz"
31+
case APISourceSCI:
32+
return "sci"
33+
default:
34+
return "UNKNOWN"
35+
}
36+
}
37+
1938
type RequestMutator func(*http.Request)
2039

2140
func ToString(value interface{}) string {
@@ -99,6 +118,7 @@ func (qv QueryValues) Encode() string {
99118
var apiRequestID uint64
100119

101120
type APIRequest struct {
121+
Source APISource
102122
Method string
103123
URI string
104124
Authenticated bool
@@ -113,7 +133,8 @@ type APIRequest struct {
113133

114134
var apiRequestPool = sync.Pool{New: func() interface{} { return new(APIRequest) }}
115135

116-
func bootstrapRequest(req *APIRequest, method, uri string, authenticated bool) {
136+
func bootstrapRequest(src APISource, req *APIRequest, method, uri string, authenticated bool) {
137+
req.Source = src
117138
req.Method = method
118139
req.URI = uri
119140
req.Authenticated = authenticated
@@ -124,13 +145,14 @@ func bootstrapRequest(req *APIRequest, method, uri string, authenticated bool) {
124145
req.id = atomic.AddUint64(&apiRequestID, 1)
125146
}
126147

127-
func apiRequestFromPool(method, uri string, authenticated bool) *APIRequest {
148+
func apiRequestFromPool(src APISource, method, uri string, authenticated bool) *APIRequest {
128149
req := apiRequestPool.Get().(*APIRequest)
129-
bootstrapRequest(req, method, uri, authenticated)
150+
bootstrapRequest(src, req, method, uri, authenticated)
130151
return req
131152
}
132153

133154
func recycleAPIRequest(req *APIRequest) {
155+
req.Source = APISourceUnknown
134156
req.Method = ""
135157
req.URI = ""
136158
req.Authenticated = false
@@ -145,9 +167,9 @@ func recycleAPIRequest(req *APIRequest) {
145167
apiRequestPool.Put(req)
146168
}
147169

148-
func NewAPIRequest(method, uri string, authenticated bool) *APIRequest {
170+
func NewAPIRequest(src APISource, method, uri string, authenticated bool) *APIRequest {
149171
req := new(APIRequest)
150-
bootstrapRequest(req, method, uri, authenticated)
172+
bootstrapRequest(src, req, method, uri, authenticated)
151173
return req
152174
}
153175

api_response.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ type APIResponseMetaContainer interface {
9898
type APIResponse interface {
9999
APIResponseMetaContainer
100100

101+
// Source must return the source of this API response
102+
Source() APISource
103+
101104
// Err must return the current state error, or nil if beginning state.
102105
Err() error
103106

@@ -120,20 +123,22 @@ type ModeledAPIResponse interface {
120123
}
121124

122125
// APIResponseFactory is used by the internal response handling mechanism to construct each response type
123-
type APIResponseFactory func(meta APIResponseMeta, body io.ReadCloser) APIResponse
126+
type APIResponseFactory func(source APISource, meta APIResponseMeta, body io.ReadCloser) APIResponse
124127

125128
// RawAPIResponse is the base implementation of APIResponse. Each api either returns this or returns a type that embeds
126129
// this type.
127130
type RawAPIResponse struct {
128131
mu sync.Mutex
132+
src APISource
129133
body io.ReadCloser
130134
err error
131135

132136
meta APIResponseMeta
133137
}
134138

135-
func newRawAPIResponse(meta APIResponseMeta, body io.ReadCloser) APIResponse {
139+
func newRawAPIResponse(source APISource, meta APIResponseMeta, body io.ReadCloser) APIResponse {
136140
b := new(RawAPIResponse)
141+
b.src = source
137142
b.meta = meta
138143
if body != nil {
139144
b.body = body
@@ -156,6 +161,11 @@ func (b *RawAPIResponse) ResponseMeta() APIResponseMeta {
156161
return b.meta
157162
}
158163

164+
// Source returns the upstream source of this response (VSZ or SCI)
165+
func (b *RawAPIResponse) Source() APISource {
166+
return b.src
167+
}
168+
159169
// Err returns the current state error, if there is one.
160170
func (b *RawAPIResponse) Err() error {
161171
b.mu.Lock()
@@ -252,10 +262,10 @@ type EmptyAPIResponse struct {
252262
*RawAPIResponse
253263
}
254264

255-
func newEmptyAPIResponse(meta APIResponseMeta, body io.ReadCloser) APIResponse {
265+
func newEmptyAPIResponse(source APISource, meta APIResponseMeta, body io.ReadCloser) APIResponse {
256266
r := new(EmptyAPIResponse)
257267
cleanupReadCloser(body)
258-
r.RawAPIResponse = newRawAPIResponse(meta, nil).(*RawAPIResponse)
268+
r.RawAPIResponse = newRawAPIResponse(source, meta, nil).(*RawAPIResponse)
259269
return r
260270
}
261271

@@ -267,8 +277,8 @@ type FileAPIResponse struct {
267277
*RawAPIResponse
268278
}
269279

270-
func newFileAPIResponse(meta APIResponseMeta, body io.ReadCloser) APIResponse {
280+
func newFileAPIResponse(source APISource, meta APIResponseMeta, body io.ReadCloser) APIResponse {
271281
r := new(FileAPIResponse)
272-
r.RawAPIResponse = newRawAPIResponse(meta, body).(*RawAPIResponse)
282+
r.RawAPIResponse = newRawAPIResponse(source, meta, body).(*RawAPIResponse)
273283
return r
274284
}

constants.go

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package bigdog
2+
3+
const (
4+
VSZResourceNameCluster = "CLUSTER_CATEGORY"
5+
VSZResourceNameAP = "AP_CATEGORY"
6+
VSZResourceNameWLAN = "WLAN_CATEGORY"
7+
VSZResourceNameDevice = "DEVICE_CATEGORY"
8+
VSZResourceNameAdministrator = "ADMINISTRATOR_CATEGORY"
9+
VSZResourceNameTenant = "TENANT_CATEGORY"
10+
VSZResourceNameICX = "ICX_CATEGORY"
11+
12+
VSZResourceDisplayCluster = "SZ"
13+
VSZResourceDisplayAP = "AP"
14+
VSZResourceDisplayWLAN = "WLAN"
15+
VSZResourceDisplayDevice = "User/Device/App"
16+
VSZResourceDisplayAdministrator = "Admin"
17+
VSZResourceDisplayTenant = "MVNO"
18+
VSZResourceDisplayICX = "ICX Switch"
19+
20+
VSZResourceAccessFullAccess = "FULL_ACCESS"
21+
VSZResourceAccessModify = "MODIFY"
22+
VSZResourceAccessReadOnly = "READ_ONLY"
23+
VSZResourceAccessRead = "READ"
24+
VSZResourceAccessNoAccess = "NO_ACCESS"
25+
26+
VSZRoleNameSuperAdmin = "SUPER_ADMIN"
27+
VSZRoleNameSystemAdmin = "SYSTEM_ADMIN"
28+
VSZRoleNameReadOnlySystemAdmin = "RO_SYSTEM_ADMIN"
29+
VSZRoleNameNetworkAdmin = "NETWORK_ADMIN"
30+
VSZRoleNameReadOnlyNetworkAdmin = "RO_NETWORK_ADMIN"
31+
VSZRoleNameAPAdmin = "AP_ADMIN"
32+
VSZRoleNameGuestPassAdmin = "GUEST_PASS_ADMIN"
33+
VSZRoleNameCustom = "CUSTOM"
34+
35+
VSZRoleLabelSuperAdmin = "Super Admin"
36+
VSZRoleLabelSystemAdmin = "System Admin"
37+
VSZRoleLabelReadOnlySystemAdmin = "Read-Only System Admin"
38+
VSZRoleLabelNetworkAdmin = "Network Admin"
39+
VSZRoleLabelReadOnlyNetworkAdmin = "Read-Only Network Admin"
40+
VSZRoleLabelAPAdmin = "AP Admin"
41+
VSZRoleLabelGuestPassAdmin = "Guest Pass Admin"
42+
VSZRoleLabelCustom = "SCGAdmin"
43+
44+
VSZSecurityProfileNameDefault = "Default"
45+
VSZSecurityProfileNameMoreSecure = "More Secure"
46+
47+
VSZDomainTypeRegular = "REGULAR"
48+
VSZDomainTypePartner = "PARTNER"
49+
50+
VSZServiceTicketQueryParameter = "serviceTicket"
51+
)
52+
53+
const (
54+
SCIAccessTokenQueryParameter = "access_token"
55+
56+
// 2016-04-06T16:04:46+00:00
57+
SCIFilterTimestampFormat = "2006-01-02T15:04:05-07:00"
58+
)
59+
60+
const (
61+
logDebugAPIRequestPrepFormat = "Preparing api request #%d \"%s %s\""
62+
logDebugAPIRequestNoBodyFormat = "%s without body"
63+
logDebugAPIRequestWithBodyFormat = "%s with body"
64+
)
65+
66+
const (
67+
uriPathParameterSearchFormat = "{%s}"
68+
uriQueryParameterPrefixFormat = "%s?%s"
69+
70+
apiRequestURLFormat = "%s%s%s"
71+
72+
headerKeyContentType = "Content-Type"
73+
headerKeyContentEncoding = "Content-Encoding"
74+
headerKeyContentDisposition = "Content-Disposition"
75+
headerKeyContentLength = "Content-Length"
76+
headerKeyAccept = "Accept"
77+
headerValueApplicationJSON = "application/json"
78+
headerValueMultipartFormData = "multipart/form-data"
79+
)

sci_airtimeutilizationreport.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ func (s *SCIAirtimeUtilizationReportService) ReportAirtimeUtilizationReport1Over
10531053
if err = ctx.Err(); err != nil {
10541054
return resp.(*SCIReportAirtimeUtilizationReport1overview200ResponseTypeAPIResponse), err
10551055
}
1056-
req = apiRequestFromPool(http.MethodPost, RouteSCIReportAirtimeUtilizationReport1Overview, true)
1056+
req = apiRequestFromPool(APISourceSCI, http.MethodPost, RouteSCIReportAirtimeUtilizationReport1Overview, true)
10571057
defer recycleAPIRequest(req)
10581058
req.Header.Set(headerKeyContentType, headerValueApplicationJSON)
10591059
req.Header.Set(headerKeyAccept, "*/*")
@@ -1087,7 +1087,7 @@ func (s *SCIAirtimeUtilizationReportService) ReportAirtimeUtilizationReport2TopC
10871087
if err = ctx.Err(); err != nil {
10881088
return resp.(*SCIReportAirtimeUtilizationReport2topChart200ResponseTypeAPIResponse), err
10891089
}
1090-
req = apiRequestFromPool(http.MethodPost, RouteSCIReportAirtimeUtilizationReport2TopChart, true)
1090+
req = apiRequestFromPool(APISourceSCI, http.MethodPost, RouteSCIReportAirtimeUtilizationReport2TopChart, true)
10911091
defer recycleAPIRequest(req)
10921092
req.Header.Set(headerKeyContentType, headerValueApplicationJSON)
10931093
req.Header.Set(headerKeyAccept, "*/*")
@@ -1121,7 +1121,7 @@ func (s *SCIAirtimeUtilizationReportService) ReportAirtimeUtilizationReport3TopA
11211121
if err = ctx.Err(); err != nil {
11221122
return resp.(*SCIReportAirtimeUtilizationReport3topAPsByAirtime24Table200ResponseTypeAPIResponse), err
11231123
}
1124-
req = apiRequestFromPool(http.MethodPost, RouteSCIReportAirtimeUtilizationReport3TopAPsByAirtime24Table, true)
1124+
req = apiRequestFromPool(APISourceSCI, http.MethodPost, RouteSCIReportAirtimeUtilizationReport3TopAPsByAirtime24Table, true)
11251125
defer recycleAPIRequest(req)
11261126
req.Header.Set(headerKeyContentType, headerValueApplicationJSON)
11271127
req.Header.Set(headerKeyAccept, "*/*")
@@ -1155,7 +1155,7 @@ func (s *SCIAirtimeUtilizationReportService) ReportAirtimeUtilizationReport4TopA
11551155
if err = ctx.Err(); err != nil {
11561156
return resp.(*SCIReportAirtimeUtilizationReport4topAPsByAirtime5Table200ResponseTypeAPIResponse), err
11571157
}
1158-
req = apiRequestFromPool(http.MethodPost, RouteSCIReportAirtimeUtilizationReport4TopAPsByAirtime5Table, true)
1158+
req = apiRequestFromPool(APISourceSCI, http.MethodPost, RouteSCIReportAirtimeUtilizationReport4TopAPsByAirtime5Table, true)
11591159
defer recycleAPIRequest(req)
11601160
req.Header.Set(headerKeyContentType, headerValueApplicationJSON)
11611161
req.Header.Set(headerKeyAccept, "*/*")
@@ -1189,7 +1189,7 @@ func (s *SCIAirtimeUtilizationReportService) ReportAirtimeUtilizationReport5Tren
11891189
if err = ctx.Err(); err != nil {
11901190
return resp.(*SCIReportAirtimeUtilizationReport5trendChart200ResponseTypeAPIResponse), err
11911191
}
1192-
req = apiRequestFromPool(http.MethodPost, RouteSCIReportAirtimeUtilizationReport5TrendChart, true)
1192+
req = apiRequestFromPool(APISourceSCI, http.MethodPost, RouteSCIReportAirtimeUtilizationReport5TrendChart, true)
11931193
defer recycleAPIRequest(req)
11941194
req.Header.Set(headerKeyContentType, headerValueApplicationJSON)
11951195
req.Header.Set(headerKeyAccept, "*/*")
@@ -1223,7 +1223,7 @@ func (s *SCIAirtimeUtilizationReportService) ReportAirtimeUtilizationReport6Tren
12231223
if err = ctx.Err(); err != nil {
12241224
return resp.(*SCIReportAirtimeUtilizationReport6trendTable200ResponseTypeAPIResponse), err
12251225
}
1226-
req = apiRequestFromPool(http.MethodPost, RouteSCIReportAirtimeUtilizationReport6TrendTable, true)
1226+
req = apiRequestFromPool(APISourceSCI, http.MethodPost, RouteSCIReportAirtimeUtilizationReport6TrendTable, true)
12271227
defer recycleAPIRequest(req)
12281228
req.Header.Set(headerKeyContentType, headerValueApplicationJSON)
12291229
req.Header.Set(headerKeyAccept, "*/*")

0 commit comments

Comments
 (0)