-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathRulesClient.go
346 lines (312 loc) · 17 KB
/
RulesClient.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
// Copyright © 2019-2023 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: BSD-2-Clause
// Auto generated code. DO NOT EDIT.
// Interface file for service: Rules
// Used by client-side stubs.
package security_policies
import (
vapiStdErrors_ "github.com/vmware/vsphere-automation-sdk-go/lib/vapi/std/errors"
vapiBindings_ "github.com/vmware/vsphere-automation-sdk-go/runtime/bindings"
vapiCore_ "github.com/vmware/vsphere-automation-sdk-go/runtime/core"
vapiProtocolClient_ "github.com/vmware/vsphere-automation-sdk-go/runtime/protocol/client"
nsx_policyModel "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model"
)
const _ = vapiCore_.SupportedByRuntimeVersion2
type RulesClient interface {
// Delete rule
//
// @param domainIdParam (required)
// @param securityPolicyIdParam (required)
// @param ruleIdParam (required)
//
// @throws InvalidRequest Bad Request, Precondition Failed
// @throws Unauthorized Forbidden
// @throws ServiceUnavailable Service Unavailable
// @throws InternalServerError Internal Server Error
// @throws NotFound Not Found
Delete(domainIdParam string, securityPolicyIdParam string, ruleIdParam string) error
// Read rule
//
// @param domainIdParam (required)
// @param securityPolicyIdParam (required)
// @param ruleIdParam (required)
// @return com.vmware.nsx_policy.model.Rule
//
// @throws InvalidRequest Bad Request, Precondition Failed
// @throws Unauthorized Forbidden
// @throws ServiceUnavailable Service Unavailable
// @throws InternalServerError Internal Server Error
// @throws NotFound Not Found
Get(domainIdParam string, securityPolicyIdParam string, ruleIdParam string) (nsx_policyModel.Rule, error)
// List rules
//
// @param domainIdParam (required)
// @param securityPolicyIdParam (required)
// @param cursorParam Opaque cursor to be used for getting next page of records (supplied by current result page) (optional)
// @param includeMarkForDeleteObjectsParam Include objects that are marked for deletion in results (optional, default to false)
// @param includedFieldsParam Comma separated list of fields that should be included in query result (optional)
// @param pageSizeParam Maximum number of results to return in this page (server may return fewer) (optional, default to 1000)
// @param sortAscendingParam (optional)
// @param sortByParam Field by which records are sorted (optional)
// @return com.vmware.nsx_policy.model.RuleListResult
//
// @throws InvalidRequest Bad Request, Precondition Failed
// @throws Unauthorized Forbidden
// @throws ServiceUnavailable Service Unavailable
// @throws InternalServerError Internal Server Error
// @throws NotFound Not Found
List(domainIdParam string, securityPolicyIdParam string, cursorParam *string, includeMarkForDeleteObjectsParam *bool, includedFieldsParam *string, pageSizeParam *int64, sortAscendingParam *bool, sortByParam *string) (nsx_policyModel.RuleListResult, error)
// Patch the rule. If Rule corresponding to the the given rule-id is not present, the object will get created and if it is present it will be updated. This is a full replace. Performance Note: If you want to edit several rules in a security policy, prefer below mentioned API for optimal performance. Pass all the rules which you wish to edit as embedded rules to it. Use this API - PATCH (or PUT) /infra/domains/<domain-id>/security-policies/<security-policy-id>
//
// @param domainIdParam (required)
// @param securityPolicyIdParam (required)
// @param ruleIdParam (required)
// @param ruleParam (required)
//
// @throws InvalidRequest Bad Request, Precondition Failed
// @throws Unauthorized Forbidden
// @throws ServiceUnavailable Service Unavailable
// @throws InternalServerError Internal Server Error
// @throws NotFound Not Found
Patch(domainIdParam string, securityPolicyIdParam string, ruleIdParam string, ruleParam nsx_policyModel.Rule) error
// This is used to re-order a rule within a security policy.
//
// @param domainIdParam (required)
// @param securityPolicyIdParam (required)
// @param ruleIdParam (required)
// @param ruleParam (required)
// @param anchorPathParam The security policy/rule path if operation is 'insert_after' or 'insert_before' (optional)
// @param operationParam Operation (optional, default to insert_top)
// @return com.vmware.nsx_policy.model.Rule
//
// @throws InvalidRequest Bad Request, Precondition Failed
// @throws Unauthorized Forbidden
// @throws ServiceUnavailable Service Unavailable
// @throws InternalServerError Internal Server Error
// @throws NotFound Not Found
Revise(domainIdParam string, securityPolicyIdParam string, ruleIdParam string, ruleParam nsx_policyModel.Rule, anchorPathParam *string, operationParam *string) (nsx_policyModel.Rule, error)
// Update the rule. Create new rule if a rule with the rule-id is not already present. Performance Note: If you wish to edit several rules in a security policy, prefer below mentioned API for optimal performance. Pass all the rules which you wish to edit as embedded rules to it. Use this API - PATCH (or PUT) /infra/domains/<domain-id>/security-policies/<security-policy-id>
//
// @param domainIdParam (required)
// @param securityPolicyIdParam (required)
// @param ruleIdParam (required)
// @param ruleParam (required)
// @return com.vmware.nsx_policy.model.Rule
//
// @throws InvalidRequest Bad Request, Precondition Failed
// @throws Unauthorized Forbidden
// @throws ServiceUnavailable Service Unavailable
// @throws InternalServerError Internal Server Error
// @throws NotFound Not Found
Update(domainIdParam string, securityPolicyIdParam string, ruleIdParam string, ruleParam nsx_policyModel.Rule) (nsx_policyModel.Rule, error)
}
type rulesClient struct {
connector vapiProtocolClient_.Connector
interfaceDefinition vapiCore_.InterfaceDefinition
errorsBindingMap map[string]vapiBindings_.BindingType
}
func NewRulesClient(connector vapiProtocolClient_.Connector) *rulesClient {
interfaceIdentifier := vapiCore_.NewInterfaceIdentifier("com.vmware.nsx_policy.infra.domains.security_policies.rules")
methodIdentifiers := map[string]vapiCore_.MethodIdentifier{
"delete": vapiCore_.NewMethodIdentifier(interfaceIdentifier, "delete"),
"get": vapiCore_.NewMethodIdentifier(interfaceIdentifier, "get"),
"list": vapiCore_.NewMethodIdentifier(interfaceIdentifier, "list"),
"patch": vapiCore_.NewMethodIdentifier(interfaceIdentifier, "patch"),
"revise": vapiCore_.NewMethodIdentifier(interfaceIdentifier, "revise"),
"update": vapiCore_.NewMethodIdentifier(interfaceIdentifier, "update"),
}
interfaceDefinition := vapiCore_.NewInterfaceDefinition(interfaceIdentifier, methodIdentifiers)
errorsBindingMap := make(map[string]vapiBindings_.BindingType)
rIface := rulesClient{interfaceDefinition: interfaceDefinition, errorsBindingMap: errorsBindingMap, connector: connector}
return &rIface
}
func (rIface *rulesClient) GetErrorBindingType(errorName string) vapiBindings_.BindingType {
if entry, ok := rIface.errorsBindingMap[errorName]; ok {
return entry
}
return vapiStdErrors_.ERROR_BINDINGS_MAP[errorName]
}
func (rIface *rulesClient) Delete(domainIdParam string, securityPolicyIdParam string, ruleIdParam string) error {
typeConverter := rIface.connector.TypeConverter()
executionContext := rIface.connector.NewExecutionContext()
operationRestMetaData := rulesDeleteRestMetadata()
executionContext.SetConnectionMetadata(vapiCore_.RESTMetadataKey, operationRestMetaData)
executionContext.SetConnectionMetadata(vapiCore_.ResponseTypeKey, vapiCore_.NewResponseType(true, false))
sv := vapiBindings_.NewStructValueBuilder(rulesDeleteInputType(), typeConverter)
sv.AddStructField("DomainId", domainIdParam)
sv.AddStructField("SecurityPolicyId", securityPolicyIdParam)
sv.AddStructField("RuleId", ruleIdParam)
inputDataValue, inputError := sv.GetStructValue()
if inputError != nil {
return vapiBindings_.VAPIerrorsToError(inputError)
}
methodResult := rIface.connector.GetApiProvider().Invoke("com.vmware.nsx_policy.infra.domains.security_policies.rules", "delete", inputDataValue, executionContext)
if methodResult.IsSuccess() {
return nil
} else {
methodError, errorInError := typeConverter.ConvertToGolang(methodResult.Error(), rIface.GetErrorBindingType(methodResult.Error().Name()))
if errorInError != nil {
return vapiBindings_.VAPIerrorsToError(errorInError)
}
return methodError.(error)
}
}
func (rIface *rulesClient) Get(domainIdParam string, securityPolicyIdParam string, ruleIdParam string) (nsx_policyModel.Rule, error) {
typeConverter := rIface.connector.TypeConverter()
executionContext := rIface.connector.NewExecutionContext()
operationRestMetaData := rulesGetRestMetadata()
executionContext.SetConnectionMetadata(vapiCore_.RESTMetadataKey, operationRestMetaData)
executionContext.SetConnectionMetadata(vapiCore_.ResponseTypeKey, vapiCore_.NewResponseType(true, false))
sv := vapiBindings_.NewStructValueBuilder(rulesGetInputType(), typeConverter)
sv.AddStructField("DomainId", domainIdParam)
sv.AddStructField("SecurityPolicyId", securityPolicyIdParam)
sv.AddStructField("RuleId", ruleIdParam)
inputDataValue, inputError := sv.GetStructValue()
if inputError != nil {
var emptyOutput nsx_policyModel.Rule
return emptyOutput, vapiBindings_.VAPIerrorsToError(inputError)
}
methodResult := rIface.connector.GetApiProvider().Invoke("com.vmware.nsx_policy.infra.domains.security_policies.rules", "get", inputDataValue, executionContext)
var emptyOutput nsx_policyModel.Rule
if methodResult.IsSuccess() {
output, errorInOutput := typeConverter.ConvertToGolang(methodResult.Output(), RulesGetOutputType())
if errorInOutput != nil {
return emptyOutput, vapiBindings_.VAPIerrorsToError(errorInOutput)
}
return output.(nsx_policyModel.Rule), nil
} else {
methodError, errorInError := typeConverter.ConvertToGolang(methodResult.Error(), rIface.GetErrorBindingType(methodResult.Error().Name()))
if errorInError != nil {
return emptyOutput, vapiBindings_.VAPIerrorsToError(errorInError)
}
return emptyOutput, methodError.(error)
}
}
func (rIface *rulesClient) List(domainIdParam string, securityPolicyIdParam string, cursorParam *string, includeMarkForDeleteObjectsParam *bool, includedFieldsParam *string, pageSizeParam *int64, sortAscendingParam *bool, sortByParam *string) (nsx_policyModel.RuleListResult, error) {
typeConverter := rIface.connector.TypeConverter()
executionContext := rIface.connector.NewExecutionContext()
operationRestMetaData := rulesListRestMetadata()
executionContext.SetConnectionMetadata(vapiCore_.RESTMetadataKey, operationRestMetaData)
executionContext.SetConnectionMetadata(vapiCore_.ResponseTypeKey, vapiCore_.NewResponseType(true, false))
sv := vapiBindings_.NewStructValueBuilder(rulesListInputType(), typeConverter)
sv.AddStructField("DomainId", domainIdParam)
sv.AddStructField("SecurityPolicyId", securityPolicyIdParam)
sv.AddStructField("Cursor", cursorParam)
sv.AddStructField("IncludeMarkForDeleteObjects", includeMarkForDeleteObjectsParam)
sv.AddStructField("IncludedFields", includedFieldsParam)
sv.AddStructField("PageSize", pageSizeParam)
sv.AddStructField("SortAscending", sortAscendingParam)
sv.AddStructField("SortBy", sortByParam)
inputDataValue, inputError := sv.GetStructValue()
if inputError != nil {
var emptyOutput nsx_policyModel.RuleListResult
return emptyOutput, vapiBindings_.VAPIerrorsToError(inputError)
}
methodResult := rIface.connector.GetApiProvider().Invoke("com.vmware.nsx_policy.infra.domains.security_policies.rules", "list", inputDataValue, executionContext)
var emptyOutput nsx_policyModel.RuleListResult
if methodResult.IsSuccess() {
output, errorInOutput := typeConverter.ConvertToGolang(methodResult.Output(), RulesListOutputType())
if errorInOutput != nil {
return emptyOutput, vapiBindings_.VAPIerrorsToError(errorInOutput)
}
return output.(nsx_policyModel.RuleListResult), nil
} else {
methodError, errorInError := typeConverter.ConvertToGolang(methodResult.Error(), rIface.GetErrorBindingType(methodResult.Error().Name()))
if errorInError != nil {
return emptyOutput, vapiBindings_.VAPIerrorsToError(errorInError)
}
return emptyOutput, methodError.(error)
}
}
func (rIface *rulesClient) Patch(domainIdParam string, securityPolicyIdParam string, ruleIdParam string, ruleParam nsx_policyModel.Rule) error {
typeConverter := rIface.connector.TypeConverter()
executionContext := rIface.connector.NewExecutionContext()
operationRestMetaData := rulesPatchRestMetadata()
executionContext.SetConnectionMetadata(vapiCore_.RESTMetadataKey, operationRestMetaData)
executionContext.SetConnectionMetadata(vapiCore_.ResponseTypeKey, vapiCore_.NewResponseType(true, false))
sv := vapiBindings_.NewStructValueBuilder(rulesPatchInputType(), typeConverter)
sv.AddStructField("DomainId", domainIdParam)
sv.AddStructField("SecurityPolicyId", securityPolicyIdParam)
sv.AddStructField("RuleId", ruleIdParam)
sv.AddStructField("Rule", ruleParam)
inputDataValue, inputError := sv.GetStructValue()
if inputError != nil {
return vapiBindings_.VAPIerrorsToError(inputError)
}
methodResult := rIface.connector.GetApiProvider().Invoke("com.vmware.nsx_policy.infra.domains.security_policies.rules", "patch", inputDataValue, executionContext)
if methodResult.IsSuccess() {
return nil
} else {
methodError, errorInError := typeConverter.ConvertToGolang(methodResult.Error(), rIface.GetErrorBindingType(methodResult.Error().Name()))
if errorInError != nil {
return vapiBindings_.VAPIerrorsToError(errorInError)
}
return methodError.(error)
}
}
func (rIface *rulesClient) Revise(domainIdParam string, securityPolicyIdParam string, ruleIdParam string, ruleParam nsx_policyModel.Rule, anchorPathParam *string, operationParam *string) (nsx_policyModel.Rule, error) {
typeConverter := rIface.connector.TypeConverter()
executionContext := rIface.connector.NewExecutionContext()
operationRestMetaData := rulesReviseRestMetadata()
executionContext.SetConnectionMetadata(vapiCore_.RESTMetadataKey, operationRestMetaData)
executionContext.SetConnectionMetadata(vapiCore_.ResponseTypeKey, vapiCore_.NewResponseType(true, false))
sv := vapiBindings_.NewStructValueBuilder(rulesReviseInputType(), typeConverter)
sv.AddStructField("DomainId", domainIdParam)
sv.AddStructField("SecurityPolicyId", securityPolicyIdParam)
sv.AddStructField("RuleId", ruleIdParam)
sv.AddStructField("Rule", ruleParam)
sv.AddStructField("AnchorPath", anchorPathParam)
sv.AddStructField("Operation", operationParam)
inputDataValue, inputError := sv.GetStructValue()
if inputError != nil {
var emptyOutput nsx_policyModel.Rule
return emptyOutput, vapiBindings_.VAPIerrorsToError(inputError)
}
methodResult := rIface.connector.GetApiProvider().Invoke("com.vmware.nsx_policy.infra.domains.security_policies.rules", "revise", inputDataValue, executionContext)
var emptyOutput nsx_policyModel.Rule
if methodResult.IsSuccess() {
output, errorInOutput := typeConverter.ConvertToGolang(methodResult.Output(), RulesReviseOutputType())
if errorInOutput != nil {
return emptyOutput, vapiBindings_.VAPIerrorsToError(errorInOutput)
}
return output.(nsx_policyModel.Rule), nil
} else {
methodError, errorInError := typeConverter.ConvertToGolang(methodResult.Error(), rIface.GetErrorBindingType(methodResult.Error().Name()))
if errorInError != nil {
return emptyOutput, vapiBindings_.VAPIerrorsToError(errorInError)
}
return emptyOutput, methodError.(error)
}
}
func (rIface *rulesClient) Update(domainIdParam string, securityPolicyIdParam string, ruleIdParam string, ruleParam nsx_policyModel.Rule) (nsx_policyModel.Rule, error) {
typeConverter := rIface.connector.TypeConverter()
executionContext := rIface.connector.NewExecutionContext()
operationRestMetaData := rulesUpdateRestMetadata()
executionContext.SetConnectionMetadata(vapiCore_.RESTMetadataKey, operationRestMetaData)
executionContext.SetConnectionMetadata(vapiCore_.ResponseTypeKey, vapiCore_.NewResponseType(true, false))
sv := vapiBindings_.NewStructValueBuilder(rulesUpdateInputType(), typeConverter)
sv.AddStructField("DomainId", domainIdParam)
sv.AddStructField("SecurityPolicyId", securityPolicyIdParam)
sv.AddStructField("RuleId", ruleIdParam)
sv.AddStructField("Rule", ruleParam)
inputDataValue, inputError := sv.GetStructValue()
if inputError != nil {
var emptyOutput nsx_policyModel.Rule
return emptyOutput, vapiBindings_.VAPIerrorsToError(inputError)
}
methodResult := rIface.connector.GetApiProvider().Invoke("com.vmware.nsx_policy.infra.domains.security_policies.rules", "update", inputDataValue, executionContext)
var emptyOutput nsx_policyModel.Rule
if methodResult.IsSuccess() {
output, errorInOutput := typeConverter.ConvertToGolang(methodResult.Output(), RulesUpdateOutputType())
if errorInOutput != nil {
return emptyOutput, vapiBindings_.VAPIerrorsToError(errorInOutput)
}
return output.(nsx_policyModel.Rule), nil
} else {
methodError, errorInError := typeConverter.ConvertToGolang(methodResult.Error(), rIface.GetErrorBindingType(methodResult.Error().Name()))
if errorInError != nil {
return emptyOutput, vapiBindings_.VAPIerrorsToError(errorInError)
}
return emptyOutput, methodError.(error)
}
}