github.com/safedep/dry@v0.0.0-20241016050132-a15651f0548b/apiguard/tykgen/api_cache_invalidation.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  )
    20  
    21  // Linger please
    22  var (
    23  	_ context.Context
    24  )
    25  
    26  type CacheInvalidationApiService service
    27  /*
    28  CacheInvalidationApiService Invalidate cache
    29  Invalidate cache for the given API
    30   * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
    31   * @param apiID The API ID
    32  @return ApiStatusMessage
    33  */
    34  func (a *CacheInvalidationApiService) InvalidateCache(ctx context.Context, apiID string) (ApiStatusMessage, *http.Response, error) {
    35  	var (
    36  		localVarHttpMethod = strings.ToUpper("Delete")
    37  		localVarPostBody   interface{}
    38  		localVarFileName   string
    39  		localVarFileBytes  []byte
    40  		localVarReturnValue ApiStatusMessage
    41  	)
    42  
    43  	// create path and map variables
    44  	localVarPath := a.client.cfg.BasePath + "/tyk/cache/{apiID}"
    45  	localVarPath = strings.Replace(localVarPath, "{"+"apiID"+"}", fmt.Sprintf("%v", apiID), -1)
    46  
    47  	localVarHeaderParams := make(map[string]string)
    48  	localVarQueryParams := url.Values{}
    49  	localVarFormParams := url.Values{}
    50  
    51  	// to determine the Content-Type header
    52  	localVarHttpContentTypes := []string{}
    53  
    54  	// set Content-Type header
    55  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
    56  	if localVarHttpContentType != "" {
    57  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
    58  	}
    59  
    60  	// to determine the Accept header
    61  	localVarHttpHeaderAccepts := []string{"application/json"}
    62  
    63  	// set Accept header
    64  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
    65  	if localVarHttpHeaderAccept != "" {
    66  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
    67  	}
    68  	if ctx != nil {
    69  		// API Key Authentication
    70  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
    71  			var key string
    72  			if auth.Prefix != "" {
    73  				key = auth.Prefix + " " + auth.Key
    74  			} else {
    75  				key = auth.Key
    76  			}
    77  			localVarHeaderParams["X-Tyk-Authorization"] = key
    78  			
    79  		}
    80  	}
    81  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
    82  	if err != nil {
    83  		return localVarReturnValue, nil, err
    84  	}
    85  
    86  	localVarHttpResponse, err := a.client.callAPI(r)
    87  	if err != nil || localVarHttpResponse == nil {
    88  		return localVarReturnValue, localVarHttpResponse, err
    89  	}
    90  
    91  	localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
    92  	localVarHttpResponse.Body.Close()
    93  	if err != nil {
    94  		return localVarReturnValue, localVarHttpResponse, err
    95  	}
    96  
    97  	if localVarHttpResponse.StatusCode < 300 {
    98  		// If we succeed, return the data, otherwise pass on to decode error.
    99  		err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   100  		if err == nil { 
   101  			return localVarReturnValue, localVarHttpResponse, err
   102  		}
   103  	}
   104  
   105  	if localVarHttpResponse.StatusCode >= 300 {
   106  		newErr := GenericSwaggerError{
   107  			body: localVarBody,
   108  			error: localVarHttpResponse.Status,
   109  		}
   110  		if localVarHttpResponse.StatusCode == 200 {
   111  			var v ApiStatusMessage
   112  			err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   113  				if err != nil {
   114  					newErr.error = err.Error()
   115  					return localVarReturnValue, localVarHttpResponse, newErr
   116  				}
   117  				newErr.model = v
   118  				return localVarReturnValue, localVarHttpResponse, newErr
   119  		}
   120  		return localVarReturnValue, localVarHttpResponse, newErr
   121  	}
   122  
   123  	return localVarReturnValue, localVarHttpResponse, nil
   124  }