github.com/safedep/dry@v0.0.0-20241016050132-a15651f0548b/apiguard/tykgen/api_policies.go (about) 1 2 /* 3 * Tyk Gateway API 4 * 5 * The Tyk Gateway API is the primary means for integrating your application with the Tyk API Gateway system. This API is very small, and has no granular permissions system. It is intended to be used purely for internal automation and integration. **Warning: Under no circumstances should outside parties be granted access to this API.** The Tyk Gateway API is capable of: * Managing session objects (key generation) * Managing and listing policies * Managing and listing API Definitions (only when not using the Dashboard) * Hot reloads / reloading a cluster configuration * OAuth client creation (only when not using the Dashboard) In order to use the Gateway API, you'll need to set the `secret` parameter in your tyk.conf file. The shared secret you set should then be sent along as a header with each Gateway API Request in order for it to be successful: ``` x-tyk-authorization: <your-secret> ``` <br/> <b>The Tyk Gateway API is subsumed by the Tyk Dashboard API in Pro installations.</b> 6 * 7 * API version: 5.5.0 8 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) 9 */ 10 package swagger 11 12 import ( 13 "context" 14 "io/ioutil" 15 "net/http" 16 "net/url" 17 "strings" 18 "fmt" 19 "github.com/antihax/optional" 20 ) 21 22 // Linger please 23 var ( 24 _ context.Context 25 ) 26 27 type PoliciesApiService service 28 /* 29 PoliciesApiService Create a Policy 30 You can create a Policy in your Tyk Instance 31 * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 32 * @param optional nil or *PoliciesApiAddPolicyOpts - Optional Parameters: 33 * @param "Body" (optional.Interface of Policy) - 34 @return ApiModifyKeySuccess 35 */ 36 37 type PoliciesApiAddPolicyOpts struct { 38 Body optional.Interface 39 } 40 41 func (a *PoliciesApiService) AddPolicy(ctx context.Context, localVarOptionals *PoliciesApiAddPolicyOpts) (ApiModifyKeySuccess, *http.Response, error) { 42 var ( 43 localVarHttpMethod = strings.ToUpper("Post") 44 localVarPostBody interface{} 45 localVarFileName string 46 localVarFileBytes []byte 47 localVarReturnValue ApiModifyKeySuccess 48 ) 49 50 // create path and map variables 51 localVarPath := a.client.cfg.BasePath + "/tyk/policies" 52 53 localVarHeaderParams := make(map[string]string) 54 localVarQueryParams := url.Values{} 55 localVarFormParams := url.Values{} 56 57 // to determine the Content-Type header 58 localVarHttpContentTypes := []string{"application/json"} 59 60 // set Content-Type header 61 localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) 62 if localVarHttpContentType != "" { 63 localVarHeaderParams["Content-Type"] = localVarHttpContentType 64 } 65 66 // to determine the Accept header 67 localVarHttpHeaderAccepts := []string{"application/json"} 68 69 // set Accept header 70 localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) 71 if localVarHttpHeaderAccept != "" { 72 localVarHeaderParams["Accept"] = localVarHttpHeaderAccept 73 } 74 // body params 75 if localVarOptionals != nil && localVarOptionals.Body.IsSet() { 76 77 localVarOptionalBody:= localVarOptionals.Body.Value() 78 localVarPostBody = &localVarOptionalBody 79 } 80 if ctx != nil { 81 // API Key Authentication 82 if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { 83 var key string 84 if auth.Prefix != "" { 85 key = auth.Prefix + " " + auth.Key 86 } else { 87 key = auth.Key 88 } 89 localVarHeaderParams["X-Tyk-Authorization"] = key 90 91 } 92 } 93 r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) 94 if err != nil { 95 return localVarReturnValue, nil, err 96 } 97 98 localVarHttpResponse, err := a.client.callAPI(r) 99 if err != nil || localVarHttpResponse == nil { 100 return localVarReturnValue, localVarHttpResponse, err 101 } 102 103 localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) 104 localVarHttpResponse.Body.Close() 105 if err != nil { 106 return localVarReturnValue, localVarHttpResponse, err 107 } 108 109 if localVarHttpResponse.StatusCode < 300 { 110 // If we succeed, return the data, otherwise pass on to decode error. 111 err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 112 if err == nil { 113 return localVarReturnValue, localVarHttpResponse, err 114 } 115 } 116 117 if localVarHttpResponse.StatusCode >= 300 { 118 newErr := GenericSwaggerError{ 119 body: localVarBody, 120 error: localVarHttpResponse.Status, 121 } 122 if localVarHttpResponse.StatusCode == 200 { 123 var v ApiModifyKeySuccess 124 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 125 if err != nil { 126 newErr.error = err.Error() 127 return localVarReturnValue, localVarHttpResponse, newErr 128 } 129 newErr.model = v 130 return localVarReturnValue, localVarHttpResponse, newErr 131 } 132 if localVarHttpResponse.StatusCode == 400 { 133 var v ApiStatusMessage 134 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 135 if err != nil { 136 newErr.error = err.Error() 137 return localVarReturnValue, localVarHttpResponse, newErr 138 } 139 newErr.model = v 140 return localVarReturnValue, localVarHttpResponse, newErr 141 } 142 if localVarHttpResponse.StatusCode == 500 { 143 var v ApiStatusMessage 144 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 145 if err != nil { 146 newErr.error = err.Error() 147 return localVarReturnValue, localVarHttpResponse, newErr 148 } 149 newErr.model = v 150 return localVarReturnValue, localVarHttpResponse, newErr 151 } 152 return localVarReturnValue, localVarHttpResponse, newErr 153 } 154 155 return localVarReturnValue, localVarHttpResponse, nil 156 } 157 /* 158 PoliciesApiService Delete a Policy 159 Delete a policy by ID in your Tyk instance. 160 * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 161 * @param polID The policy ID 162 @return ApiModifyKeySuccess 163 */ 164 func (a *PoliciesApiService) DeletePolicy(ctx context.Context, polID string) (ApiModifyKeySuccess, *http.Response, error) { 165 var ( 166 localVarHttpMethod = strings.ToUpper("Delete") 167 localVarPostBody interface{} 168 localVarFileName string 169 localVarFileBytes []byte 170 localVarReturnValue ApiModifyKeySuccess 171 ) 172 173 // create path and map variables 174 localVarPath := a.client.cfg.BasePath + "/tyk/policies/{polID}" 175 localVarPath = strings.Replace(localVarPath, "{"+"polID"+"}", fmt.Sprintf("%v", polID), -1) 176 177 localVarHeaderParams := make(map[string]string) 178 localVarQueryParams := url.Values{} 179 localVarFormParams := url.Values{} 180 181 // to determine the Content-Type header 182 localVarHttpContentTypes := []string{} 183 184 // set Content-Type header 185 localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) 186 if localVarHttpContentType != "" { 187 localVarHeaderParams["Content-Type"] = localVarHttpContentType 188 } 189 190 // to determine the Accept header 191 localVarHttpHeaderAccepts := []string{"application/json"} 192 193 // set Accept header 194 localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) 195 if localVarHttpHeaderAccept != "" { 196 localVarHeaderParams["Accept"] = localVarHttpHeaderAccept 197 } 198 if ctx != nil { 199 // API Key Authentication 200 if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { 201 var key string 202 if auth.Prefix != "" { 203 key = auth.Prefix + " " + auth.Key 204 } else { 205 key = auth.Key 206 } 207 localVarHeaderParams["X-Tyk-Authorization"] = key 208 209 } 210 } 211 r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) 212 if err != nil { 213 return localVarReturnValue, nil, err 214 } 215 216 localVarHttpResponse, err := a.client.callAPI(r) 217 if err != nil || localVarHttpResponse == nil { 218 return localVarReturnValue, localVarHttpResponse, err 219 } 220 221 localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) 222 localVarHttpResponse.Body.Close() 223 if err != nil { 224 return localVarReturnValue, localVarHttpResponse, err 225 } 226 227 if localVarHttpResponse.StatusCode < 300 { 228 // If we succeed, return the data, otherwise pass on to decode error. 229 err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 230 if err == nil { 231 return localVarReturnValue, localVarHttpResponse, err 232 } 233 } 234 235 if localVarHttpResponse.StatusCode >= 300 { 236 newErr := GenericSwaggerError{ 237 body: localVarBody, 238 error: localVarHttpResponse.Status, 239 } 240 if localVarHttpResponse.StatusCode == 200 { 241 var v ApiModifyKeySuccess 242 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 243 if err != nil { 244 newErr.error = err.Error() 245 return localVarReturnValue, localVarHttpResponse, newErr 246 } 247 newErr.model = v 248 return localVarReturnValue, localVarHttpResponse, newErr 249 } 250 if localVarHttpResponse.StatusCode == 500 { 251 var v ApiStatusMessage 252 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 253 if err != nil { 254 newErr.error = err.Error() 255 return localVarReturnValue, localVarHttpResponse, newErr 256 } 257 newErr.model = v 258 return localVarReturnValue, localVarHttpResponse, newErr 259 } 260 return localVarReturnValue, localVarHttpResponse, newErr 261 } 262 263 return localVarReturnValue, localVarHttpResponse, nil 264 } 265 /* 266 PoliciesApiService Get a Policy 267 You can retrieve details of a single policy by ID in your Tyk instance. Returns an array policies. 268 * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 269 * @param polID The policy ID 270 @return Policy 271 */ 272 func (a *PoliciesApiService) GetPolicy(ctx context.Context, polID string) (Policy, *http.Response, error) { 273 var ( 274 localVarHttpMethod = strings.ToUpper("Get") 275 localVarPostBody interface{} 276 localVarFileName string 277 localVarFileBytes []byte 278 localVarReturnValue Policy 279 ) 280 281 // create path and map variables 282 localVarPath := a.client.cfg.BasePath + "/tyk/policies/{polID}" 283 localVarPath = strings.Replace(localVarPath, "{"+"polID"+"}", fmt.Sprintf("%v", polID), -1) 284 285 localVarHeaderParams := make(map[string]string) 286 localVarQueryParams := url.Values{} 287 localVarFormParams := url.Values{} 288 289 // to determine the Content-Type header 290 localVarHttpContentTypes := []string{} 291 292 // set Content-Type header 293 localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) 294 if localVarHttpContentType != "" { 295 localVarHeaderParams["Content-Type"] = localVarHttpContentType 296 } 297 298 // to determine the Accept header 299 localVarHttpHeaderAccepts := []string{"application/json"} 300 301 // set Accept header 302 localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) 303 if localVarHttpHeaderAccept != "" { 304 localVarHeaderParams["Accept"] = localVarHttpHeaderAccept 305 } 306 if ctx != nil { 307 // API Key Authentication 308 if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { 309 var key string 310 if auth.Prefix != "" { 311 key = auth.Prefix + " " + auth.Key 312 } else { 313 key = auth.Key 314 } 315 localVarHeaderParams["X-Tyk-Authorization"] = key 316 317 } 318 } 319 r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) 320 if err != nil { 321 return localVarReturnValue, nil, err 322 } 323 324 localVarHttpResponse, err := a.client.callAPI(r) 325 if err != nil || localVarHttpResponse == nil { 326 return localVarReturnValue, localVarHttpResponse, err 327 } 328 329 localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) 330 localVarHttpResponse.Body.Close() 331 if err != nil { 332 return localVarReturnValue, localVarHttpResponse, err 333 } 334 335 if localVarHttpResponse.StatusCode < 300 { 336 // If we succeed, return the data, otherwise pass on to decode error. 337 err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 338 if err == nil { 339 return localVarReturnValue, localVarHttpResponse, err 340 } 341 } 342 343 if localVarHttpResponse.StatusCode >= 300 { 344 newErr := GenericSwaggerError{ 345 body: localVarBody, 346 error: localVarHttpResponse.Status, 347 } 348 if localVarHttpResponse.StatusCode == 200 { 349 var v Policy 350 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 351 if err != nil { 352 newErr.error = err.Error() 353 return localVarReturnValue, localVarHttpResponse, newErr 354 } 355 newErr.model = v 356 return localVarReturnValue, localVarHttpResponse, newErr 357 } 358 if localVarHttpResponse.StatusCode == 404 { 359 var v ApiStatusMessage 360 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 361 if err != nil { 362 newErr.error = err.Error() 363 return localVarReturnValue, localVarHttpResponse, newErr 364 } 365 newErr.model = v 366 return localVarReturnValue, localVarHttpResponse, newErr 367 } 368 return localVarReturnValue, localVarHttpResponse, newErr 369 } 370 371 return localVarReturnValue, localVarHttpResponse, nil 372 } 373 /* 374 PoliciesApiService List Policies 375 You can retrieve all the policies in your Tyk instance. Returns an array policies. 376 * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 377 @return []Policy 378 */ 379 func (a *PoliciesApiService) ListPolicies(ctx context.Context) ([]Policy, *http.Response, error) { 380 var ( 381 localVarHttpMethod = strings.ToUpper("Get") 382 localVarPostBody interface{} 383 localVarFileName string 384 localVarFileBytes []byte 385 localVarReturnValue []Policy 386 ) 387 388 // create path and map variables 389 localVarPath := a.client.cfg.BasePath + "/tyk/policies" 390 391 localVarHeaderParams := make(map[string]string) 392 localVarQueryParams := url.Values{} 393 localVarFormParams := url.Values{} 394 395 // to determine the Content-Type header 396 localVarHttpContentTypes := []string{} 397 398 // set Content-Type header 399 localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) 400 if localVarHttpContentType != "" { 401 localVarHeaderParams["Content-Type"] = localVarHttpContentType 402 } 403 404 // to determine the Accept header 405 localVarHttpHeaderAccepts := []string{"application/json"} 406 407 // set Accept header 408 localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) 409 if localVarHttpHeaderAccept != "" { 410 localVarHeaderParams["Accept"] = localVarHttpHeaderAccept 411 } 412 if ctx != nil { 413 // API Key Authentication 414 if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { 415 var key string 416 if auth.Prefix != "" { 417 key = auth.Prefix + " " + auth.Key 418 } else { 419 key = auth.Key 420 } 421 localVarHeaderParams["X-Tyk-Authorization"] = key 422 423 } 424 } 425 r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) 426 if err != nil { 427 return localVarReturnValue, nil, err 428 } 429 430 localVarHttpResponse, err := a.client.callAPI(r) 431 if err != nil || localVarHttpResponse == nil { 432 return localVarReturnValue, localVarHttpResponse, err 433 } 434 435 localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) 436 localVarHttpResponse.Body.Close() 437 if err != nil { 438 return localVarReturnValue, localVarHttpResponse, err 439 } 440 441 if localVarHttpResponse.StatusCode < 300 { 442 // If we succeed, return the data, otherwise pass on to decode error. 443 err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 444 if err == nil { 445 return localVarReturnValue, localVarHttpResponse, err 446 } 447 } 448 449 if localVarHttpResponse.StatusCode >= 300 { 450 newErr := GenericSwaggerError{ 451 body: localVarBody, 452 error: localVarHttpResponse.Status, 453 } 454 if localVarHttpResponse.StatusCode == 200 { 455 var v []Policy 456 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 457 if err != nil { 458 newErr.error = err.Error() 459 return localVarReturnValue, localVarHttpResponse, newErr 460 } 461 newErr.model = v 462 return localVarReturnValue, localVarHttpResponse, newErr 463 } 464 return localVarReturnValue, localVarHttpResponse, newErr 465 } 466 467 return localVarReturnValue, localVarHttpResponse, nil 468 } 469 /* 470 PoliciesApiService Update a Policy 471 You can update a Policy in your Tyk Instance by ID 472 * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 473 * @param polID The policy ID 474 * @param optional nil or *PoliciesApiUpdatePolicyOpts - Optional Parameters: 475 * @param "Body" (optional.Interface of Policy) - 476 @return ApiModifyKeySuccess 477 */ 478 479 type PoliciesApiUpdatePolicyOpts struct { 480 Body optional.Interface 481 } 482 483 func (a *PoliciesApiService) UpdatePolicy(ctx context.Context, polID string, localVarOptionals *PoliciesApiUpdatePolicyOpts) (ApiModifyKeySuccess, *http.Response, error) { 484 var ( 485 localVarHttpMethod = strings.ToUpper("Put") 486 localVarPostBody interface{} 487 localVarFileName string 488 localVarFileBytes []byte 489 localVarReturnValue ApiModifyKeySuccess 490 ) 491 492 // create path and map variables 493 localVarPath := a.client.cfg.BasePath + "/tyk/policies/{polID}" 494 localVarPath = strings.Replace(localVarPath, "{"+"polID"+"}", fmt.Sprintf("%v", polID), -1) 495 496 localVarHeaderParams := make(map[string]string) 497 localVarQueryParams := url.Values{} 498 localVarFormParams := url.Values{} 499 500 // to determine the Content-Type header 501 localVarHttpContentTypes := []string{"application/json"} 502 503 // set Content-Type header 504 localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) 505 if localVarHttpContentType != "" { 506 localVarHeaderParams["Content-Type"] = localVarHttpContentType 507 } 508 509 // to determine the Accept header 510 localVarHttpHeaderAccepts := []string{"application/json"} 511 512 // set Accept header 513 localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) 514 if localVarHttpHeaderAccept != "" { 515 localVarHeaderParams["Accept"] = localVarHttpHeaderAccept 516 } 517 // body params 518 if localVarOptionals != nil && localVarOptionals.Body.IsSet() { 519 520 localVarOptionalBody:= localVarOptionals.Body.Value() 521 localVarPostBody = &localVarOptionalBody 522 } 523 if ctx != nil { 524 // API Key Authentication 525 if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { 526 var key string 527 if auth.Prefix != "" { 528 key = auth.Prefix + " " + auth.Key 529 } else { 530 key = auth.Key 531 } 532 localVarHeaderParams["X-Tyk-Authorization"] = key 533 534 } 535 } 536 r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) 537 if err != nil { 538 return localVarReturnValue, nil, err 539 } 540 541 localVarHttpResponse, err := a.client.callAPI(r) 542 if err != nil || localVarHttpResponse == nil { 543 return localVarReturnValue, localVarHttpResponse, err 544 } 545 546 localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) 547 localVarHttpResponse.Body.Close() 548 if err != nil { 549 return localVarReturnValue, localVarHttpResponse, err 550 } 551 552 if localVarHttpResponse.StatusCode < 300 { 553 // If we succeed, return the data, otherwise pass on to decode error. 554 err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 555 if err == nil { 556 return localVarReturnValue, localVarHttpResponse, err 557 } 558 } 559 560 if localVarHttpResponse.StatusCode >= 300 { 561 newErr := GenericSwaggerError{ 562 body: localVarBody, 563 error: localVarHttpResponse.Status, 564 } 565 if localVarHttpResponse.StatusCode == 200 { 566 var v ApiModifyKeySuccess 567 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 568 if err != nil { 569 newErr.error = err.Error() 570 return localVarReturnValue, localVarHttpResponse, newErr 571 } 572 newErr.model = v 573 return localVarReturnValue, localVarHttpResponse, newErr 574 } 575 if localVarHttpResponse.StatusCode == 400 { 576 var v ApiStatusMessage 577 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 578 if err != nil { 579 newErr.error = err.Error() 580 return localVarReturnValue, localVarHttpResponse, newErr 581 } 582 newErr.model = v 583 return localVarReturnValue, localVarHttpResponse, newErr 584 } 585 if localVarHttpResponse.StatusCode == 500 { 586 var v ApiStatusMessage 587 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 588 if err != nil { 589 newErr.error = err.Error() 590 return localVarReturnValue, localVarHttpResponse, newErr 591 } 592 newErr.model = v 593 return localVarReturnValue, localVarHttpResponse, newErr 594 } 595 return localVarReturnValue, localVarHttpResponse, newErr 596 } 597 598 return localVarReturnValue, localVarHttpResponse, nil 599 }