github.com/safedep/dry@v0.0.0-20241016050132-a15651f0548b/apiguard/tykgen/api_keys.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 KeysApiService service
    28  /*
    29  KeysApiService Create a key
    30  Tyk will generate the access token based on the OrgID specified in the API Definition and a random UUID. This ensures that keys can be \&quot;owned\&quot; by different API Owners should segmentation be needed at an organisational level. &lt;br/&gt;&lt;br/&gt; API keys without access_rights data will be written to all APIs on the system (this also means that they will be created across all SessionHandlers and StorageHandlers, it is recommended to always embed access_rights data in a key to ensure that only targeted APIs and their back-ends are written to.
    31   * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
    32   * @param optional nil or *KeysApiAddKeyOpts - Optional Parameters:
    33       * @param "Body" (optional.Interface of SessionState) - 
    34  @return ApiModifyKeySuccess
    35  */
    36  
    37  type KeysApiAddKeyOpts struct {
    38      Body optional.Interface
    39  }
    40  
    41  func (a *KeysApiService) AddKey(ctx context.Context, localVarOptionals *KeysApiAddKeyOpts) (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/keys"
    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  		return localVarReturnValue, localVarHttpResponse, newErr
   143  	}
   144  
   145  	return localVarReturnValue, localVarHttpResponse, nil
   146  }
   147  /*
   148  KeysApiService Create Custom Key / Import Key
   149  You can use the &#x60;POST /tyk/keys/{KEY_ID}&#x60; endpoint as defined below to import existing keys into Tyk.  This example uses standard &#x60;authorization&#x60; header authentication, and assumes that the Gateway is located at &#x60;127.0.0.1:8080&#x60; and the Tyk secret is &#x60;352d20ee67be67f6340b4c0605b044b7&#x60; - update these as necessary to match your environment.  To import a key called &#x60;mycustomkey&#x60;, save the JSON contents as &#x60;token.json&#x60; (see example below), then run the following Curl command.  &#x60;&#x60;&#x60; curl http://127.0.0.1:8080/tyk/keys/mycustomkey -H &#x27;x-tyk-authorization: 352d20ee67be67f6340b4c0605b044b7&#x27; -H &#x27;Content-Type: application/json&#x27;  -d @token.json &#x60;&#x60;&#x60;  The following request will fail as the key doesn&#x27;t exist.  &#x60;&#x60;&#x60; curl http://127.0.0.1:8080/quickstart/headers -H &#x27;Authorization. invalid123&#x27; &#x60;&#x60;&#x60;  But this request will now work, using the imported key.  &#x60;&#x60;&#x60; curl http://127.0.0.1:8080/quickstart/headers -H &#x27;Authorization: mycustomkey&#x27; &#x60;&#x60;&#x60;  &lt;h4&gt;Example token.json file&lt;h4&gt;  &#x60;&#x60;&#x60; {   \&quot;allowance\&quot;: 1000,   \&quot;rate\&quot;: 1000,   \&quot;per\&quot;: 60,   \&quot;expires\&quot;: -1,   \&quot;quota_max\&quot;: -1,   \&quot;quota_renews\&quot;: 1406121006,   \&quot;quota_remaining\&quot;: 0,   \&quot;quota_renewal_rate\&quot;: 60,   \&quot;access_rights\&quot;: {     \&quot;3\&quot;: {       \&quot;api_name\&quot;: \&quot;Tyk Test API\&quot;,       \&quot;api_id\&quot;: \&quot;3\&quot;     }   },   \&quot;org_id\&quot;: \&quot;53ac07777cbb8c2d53000002\&quot;,   \&quot;basic_auth_data\&quot;: {     \&quot;password\&quot;: \&quot;\&quot;,     \&quot;hash_type\&quot;: \&quot;\&quot;   },   \&quot;hmac_enabled\&quot;: false,   \&quot;hmac_string\&quot;: \&quot;\&quot;,   \&quot;is_inactive\&quot;: false,   \&quot;apply_policy_id\&quot;: \&quot;\&quot;,   \&quot;apply_policies\&quot;: [     \&quot;59672779fa4387000129507d\&quot;,     \&quot;53222349fa4387004324324e\&quot;,     \&quot;543534s9fa4387004324324d\&quot;     ],   \&quot;monitor\&quot;: {     \&quot;trigger_limits\&quot;: []   } } &#x60;&#x60;&#x60;
   150   * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
   151   * @param keyID The Key ID
   152   * @param optional nil or *KeysApiCreateCustomKeyOpts - Optional Parameters:
   153       * @param "Body" (optional.Interface of SessionState) - 
   154       * @param "Hashed" (optional.Bool) -  Use the hash of the key as input instead of the full key
   155       * @param "SuppressReset" (optional.String) -  Adding the suppress_reset parameter and setting it to 1, will cause Tyk not to reset the quota limit that is in the current live quota manager. By default Tyk will reset the quota in the live quota manager (initialising it) when adding a key. Adding the &#x60;suppress_reset&#x60; flag to the URL parameters will avoid this behaviour.
   156  @return ApiModifyKeySuccess
   157  */
   158  
   159  type KeysApiCreateCustomKeyOpts struct {
   160      Body optional.Interface
   161      Hashed optional.Bool
   162      SuppressReset optional.String
   163  }
   164  
   165  func (a *KeysApiService) CreateCustomKey(ctx context.Context, keyID string, localVarOptionals *KeysApiCreateCustomKeyOpts) (ApiModifyKeySuccess, *http.Response, error) {
   166  	var (
   167  		localVarHttpMethod = strings.ToUpper("Post")
   168  		localVarPostBody   interface{}
   169  		localVarFileName   string
   170  		localVarFileBytes  []byte
   171  		localVarReturnValue ApiModifyKeySuccess
   172  	)
   173  
   174  	// create path and map variables
   175  	localVarPath := a.client.cfg.BasePath + "/tyk/keys/{keyID}"
   176  	localVarPath = strings.Replace(localVarPath, "{"+"keyID"+"}", fmt.Sprintf("%v", keyID), -1)
   177  
   178  	localVarHeaderParams := make(map[string]string)
   179  	localVarQueryParams := url.Values{}
   180  	localVarFormParams := url.Values{}
   181  
   182  	if localVarOptionals != nil && localVarOptionals.Hashed.IsSet() {
   183  		localVarQueryParams.Add("hashed", parameterToString(localVarOptionals.Hashed.Value(), ""))
   184  	}
   185  	if localVarOptionals != nil && localVarOptionals.SuppressReset.IsSet() {
   186  		localVarQueryParams.Add("suppress_reset", parameterToString(localVarOptionals.SuppressReset.Value(), ""))
   187  	}
   188  	// to determine the Content-Type header
   189  	localVarHttpContentTypes := []string{"application/json"}
   190  
   191  	// set Content-Type header
   192  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
   193  	if localVarHttpContentType != "" {
   194  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
   195  	}
   196  
   197  	// to determine the Accept header
   198  	localVarHttpHeaderAccepts := []string{"application/json"}
   199  
   200  	// set Accept header
   201  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
   202  	if localVarHttpHeaderAccept != "" {
   203  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
   204  	}
   205  	// body params
   206  	if localVarOptionals != nil && localVarOptionals.Body.IsSet() {
   207  		
   208  		localVarOptionalBody:= localVarOptionals.Body.Value()
   209  		localVarPostBody = &localVarOptionalBody
   210  	}
   211  	if ctx != nil {
   212  		// API Key Authentication
   213  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   214  			var key string
   215  			if auth.Prefix != "" {
   216  				key = auth.Prefix + " " + auth.Key
   217  			} else {
   218  				key = auth.Key
   219  			}
   220  			localVarHeaderParams["X-Tyk-Authorization"] = key
   221  			
   222  		}
   223  	}
   224  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
   225  	if err != nil {
   226  		return localVarReturnValue, nil, err
   227  	}
   228  
   229  	localVarHttpResponse, err := a.client.callAPI(r)
   230  	if err != nil || localVarHttpResponse == nil {
   231  		return localVarReturnValue, localVarHttpResponse, err
   232  	}
   233  
   234  	localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
   235  	localVarHttpResponse.Body.Close()
   236  	if err != nil {
   237  		return localVarReturnValue, localVarHttpResponse, err
   238  	}
   239  
   240  	if localVarHttpResponse.StatusCode < 300 {
   241  		// If we succeed, return the data, otherwise pass on to decode error.
   242  		err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   243  		if err == nil { 
   244  			return localVarReturnValue, localVarHttpResponse, err
   245  		}
   246  	}
   247  
   248  	if localVarHttpResponse.StatusCode >= 300 {
   249  		newErr := GenericSwaggerError{
   250  			body: localVarBody,
   251  			error: localVarHttpResponse.Status,
   252  		}
   253  		if localVarHttpResponse.StatusCode == 200 {
   254  			var v ApiModifyKeySuccess
   255  			err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   256  				if err != nil {
   257  					newErr.error = err.Error()
   258  					return localVarReturnValue, localVarHttpResponse, newErr
   259  				}
   260  				newErr.model = v
   261  				return localVarReturnValue, localVarHttpResponse, newErr
   262  		}
   263  		if localVarHttpResponse.StatusCode == 400 {
   264  			var v ApiStatusMessage
   265  			err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   266  				if err != nil {
   267  					newErr.error = err.Error()
   268  					return localVarReturnValue, localVarHttpResponse, newErr
   269  				}
   270  				newErr.model = v
   271  				return localVarReturnValue, localVarHttpResponse, newErr
   272  		}
   273  		return localVarReturnValue, localVarHttpResponse, newErr
   274  	}
   275  
   276  	return localVarReturnValue, localVarHttpResponse, nil
   277  }
   278  /*
   279  KeysApiService Delete Key
   280  Deleting a key will remove it permanently from the system, however analytics relating to that key will still be available.
   281   * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
   282   * @param keyID The Key ID
   283   * @param optional nil or *KeysApiDeleteKeyOpts - Optional Parameters:
   284       * @param "Hashed" (optional.Bool) -  Use the hash of the key as input instead of the full key
   285  @return ApiStatusMessage
   286  */
   287  
   288  type KeysApiDeleteKeyOpts struct {
   289      Hashed optional.Bool
   290  }
   291  
   292  func (a *KeysApiService) DeleteKey(ctx context.Context, keyID string, localVarOptionals *KeysApiDeleteKeyOpts) (ApiStatusMessage, *http.Response, error) {
   293  	var (
   294  		localVarHttpMethod = strings.ToUpper("Delete")
   295  		localVarPostBody   interface{}
   296  		localVarFileName   string
   297  		localVarFileBytes  []byte
   298  		localVarReturnValue ApiStatusMessage
   299  	)
   300  
   301  	// create path and map variables
   302  	localVarPath := a.client.cfg.BasePath + "/tyk/keys/{keyID}"
   303  	localVarPath = strings.Replace(localVarPath, "{"+"keyID"+"}", fmt.Sprintf("%v", keyID), -1)
   304  
   305  	localVarHeaderParams := make(map[string]string)
   306  	localVarQueryParams := url.Values{}
   307  	localVarFormParams := url.Values{}
   308  
   309  	if localVarOptionals != nil && localVarOptionals.Hashed.IsSet() {
   310  		localVarQueryParams.Add("hashed", parameterToString(localVarOptionals.Hashed.Value(), ""))
   311  	}
   312  	// to determine the Content-Type header
   313  	localVarHttpContentTypes := []string{}
   314  
   315  	// set Content-Type header
   316  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
   317  	if localVarHttpContentType != "" {
   318  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
   319  	}
   320  
   321  	// to determine the Accept header
   322  	localVarHttpHeaderAccepts := []string{"application/json"}
   323  
   324  	// set Accept header
   325  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
   326  	if localVarHttpHeaderAccept != "" {
   327  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
   328  	}
   329  	if ctx != nil {
   330  		// API Key Authentication
   331  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   332  			var key string
   333  			if auth.Prefix != "" {
   334  				key = auth.Prefix + " " + auth.Key
   335  			} else {
   336  				key = auth.Key
   337  			}
   338  			localVarHeaderParams["X-Tyk-Authorization"] = key
   339  			
   340  		}
   341  	}
   342  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
   343  	if err != nil {
   344  		return localVarReturnValue, nil, err
   345  	}
   346  
   347  	localVarHttpResponse, err := a.client.callAPI(r)
   348  	if err != nil || localVarHttpResponse == nil {
   349  		return localVarReturnValue, localVarHttpResponse, err
   350  	}
   351  
   352  	localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
   353  	localVarHttpResponse.Body.Close()
   354  	if err != nil {
   355  		return localVarReturnValue, localVarHttpResponse, err
   356  	}
   357  
   358  	if localVarHttpResponse.StatusCode < 300 {
   359  		// If we succeed, return the data, otherwise pass on to decode error.
   360  		err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   361  		if err == nil { 
   362  			return localVarReturnValue, localVarHttpResponse, err
   363  		}
   364  	}
   365  
   366  	if localVarHttpResponse.StatusCode >= 300 {
   367  		newErr := GenericSwaggerError{
   368  			body: localVarBody,
   369  			error: localVarHttpResponse.Status,
   370  		}
   371  		if localVarHttpResponse.StatusCode == 200 {
   372  			var v ApiStatusMessage
   373  			err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   374  				if err != nil {
   375  					newErr.error = err.Error()
   376  					return localVarReturnValue, localVarHttpResponse, newErr
   377  				}
   378  				newErr.model = v
   379  				return localVarReturnValue, localVarHttpResponse, newErr
   380  		}
   381  		return localVarReturnValue, localVarHttpResponse, newErr
   382  	}
   383  
   384  	return localVarReturnValue, localVarHttpResponse, nil
   385  }
   386  /*
   387  KeysApiService Get a Key
   388  Get session info about the specified key. Should return up to date rate limit and quota usage numbers.
   389   * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
   390   * @param keyID The Key ID
   391   * @param optional nil or *KeysApiGetKeyOpts - Optional Parameters:
   392       * @param "Hashed" (optional.Bool) -  Use the hash of the key as input instead of the full key
   393  @return SessionState
   394  */
   395  
   396  type KeysApiGetKeyOpts struct {
   397      Hashed optional.Bool
   398  }
   399  
   400  func (a *KeysApiService) GetKey(ctx context.Context, keyID string, localVarOptionals *KeysApiGetKeyOpts) (SessionState, *http.Response, error) {
   401  	var (
   402  		localVarHttpMethod = strings.ToUpper("Get")
   403  		localVarPostBody   interface{}
   404  		localVarFileName   string
   405  		localVarFileBytes  []byte
   406  		localVarReturnValue SessionState
   407  	)
   408  
   409  	// create path and map variables
   410  	localVarPath := a.client.cfg.BasePath + "/tyk/keys/{keyID}"
   411  	localVarPath = strings.Replace(localVarPath, "{"+"keyID"+"}", fmt.Sprintf("%v", keyID), -1)
   412  
   413  	localVarHeaderParams := make(map[string]string)
   414  	localVarQueryParams := url.Values{}
   415  	localVarFormParams := url.Values{}
   416  
   417  	if localVarOptionals != nil && localVarOptionals.Hashed.IsSet() {
   418  		localVarQueryParams.Add("hashed", parameterToString(localVarOptionals.Hashed.Value(), ""))
   419  	}
   420  	// to determine the Content-Type header
   421  	localVarHttpContentTypes := []string{}
   422  
   423  	// set Content-Type header
   424  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
   425  	if localVarHttpContentType != "" {
   426  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
   427  	}
   428  
   429  	// to determine the Accept header
   430  	localVarHttpHeaderAccepts := []string{"application/json"}
   431  
   432  	// set Accept header
   433  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
   434  	if localVarHttpHeaderAccept != "" {
   435  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
   436  	}
   437  	if ctx != nil {
   438  		// API Key Authentication
   439  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   440  			var key string
   441  			if auth.Prefix != "" {
   442  				key = auth.Prefix + " " + auth.Key
   443  			} else {
   444  				key = auth.Key
   445  			}
   446  			localVarHeaderParams["X-Tyk-Authorization"] = key
   447  			
   448  		}
   449  	}
   450  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
   451  	if err != nil {
   452  		return localVarReturnValue, nil, err
   453  	}
   454  
   455  	localVarHttpResponse, err := a.client.callAPI(r)
   456  	if err != nil || localVarHttpResponse == nil {
   457  		return localVarReturnValue, localVarHttpResponse, err
   458  	}
   459  
   460  	localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
   461  	localVarHttpResponse.Body.Close()
   462  	if err != nil {
   463  		return localVarReturnValue, localVarHttpResponse, err
   464  	}
   465  
   466  	if localVarHttpResponse.StatusCode < 300 {
   467  		// If we succeed, return the data, otherwise pass on to decode error.
   468  		err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   469  		if err == nil { 
   470  			return localVarReturnValue, localVarHttpResponse, err
   471  		}
   472  	}
   473  
   474  	if localVarHttpResponse.StatusCode >= 300 {
   475  		newErr := GenericSwaggerError{
   476  			body: localVarBody,
   477  			error: localVarHttpResponse.Status,
   478  		}
   479  		if localVarHttpResponse.StatusCode == 200 {
   480  			var v SessionState
   481  			err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   482  				if err != nil {
   483  					newErr.error = err.Error()
   484  					return localVarReturnValue, localVarHttpResponse, newErr
   485  				}
   486  				newErr.model = v
   487  				return localVarReturnValue, localVarHttpResponse, newErr
   488  		}
   489  		return localVarReturnValue, localVarHttpResponse, newErr
   490  	}
   491  
   492  	return localVarReturnValue, localVarHttpResponse, nil
   493  }
   494  /*
   495  KeysApiService List Keys
   496  You can retrieve all the keys in your Tyk instance. Returns an array of Key IDs.
   497   * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
   498  @return ApiAllKeys
   499  */
   500  func (a *KeysApiService) ListKeys(ctx context.Context) (ApiAllKeys, *http.Response, error) {
   501  	var (
   502  		localVarHttpMethod = strings.ToUpper("Get")
   503  		localVarPostBody   interface{}
   504  		localVarFileName   string
   505  		localVarFileBytes  []byte
   506  		localVarReturnValue ApiAllKeys
   507  	)
   508  
   509  	// create path and map variables
   510  	localVarPath := a.client.cfg.BasePath + "/tyk/keys"
   511  
   512  	localVarHeaderParams := make(map[string]string)
   513  	localVarQueryParams := url.Values{}
   514  	localVarFormParams := url.Values{}
   515  
   516  	// to determine the Content-Type header
   517  	localVarHttpContentTypes := []string{}
   518  
   519  	// set Content-Type header
   520  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
   521  	if localVarHttpContentType != "" {
   522  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
   523  	}
   524  
   525  	// to determine the Accept header
   526  	localVarHttpHeaderAccepts := []string{"application/json"}
   527  
   528  	// set Accept header
   529  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
   530  	if localVarHttpHeaderAccept != "" {
   531  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
   532  	}
   533  	if ctx != nil {
   534  		// API Key Authentication
   535  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   536  			var key string
   537  			if auth.Prefix != "" {
   538  				key = auth.Prefix + " " + auth.Key
   539  			} else {
   540  				key = auth.Key
   541  			}
   542  			localVarHeaderParams["X-Tyk-Authorization"] = key
   543  			
   544  		}
   545  	}
   546  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
   547  	if err != nil {
   548  		return localVarReturnValue, nil, err
   549  	}
   550  
   551  	localVarHttpResponse, err := a.client.callAPI(r)
   552  	if err != nil || localVarHttpResponse == nil {
   553  		return localVarReturnValue, localVarHttpResponse, err
   554  	}
   555  
   556  	localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
   557  	localVarHttpResponse.Body.Close()
   558  	if err != nil {
   559  		return localVarReturnValue, localVarHttpResponse, err
   560  	}
   561  
   562  	if localVarHttpResponse.StatusCode < 300 {
   563  		// If we succeed, return the data, otherwise pass on to decode error.
   564  		err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   565  		if err == nil { 
   566  			return localVarReturnValue, localVarHttpResponse, err
   567  		}
   568  	}
   569  
   570  	if localVarHttpResponse.StatusCode >= 300 {
   571  		newErr := GenericSwaggerError{
   572  			body: localVarBody,
   573  			error: localVarHttpResponse.Status,
   574  		}
   575  		if localVarHttpResponse.StatusCode == 200 {
   576  			var v ApiAllKeys
   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  		return localVarReturnValue, localVarHttpResponse, newErr
   586  	}
   587  
   588  	return localVarReturnValue, localVarHttpResponse, nil
   589  }
   590  /*
   591  KeysApiService Update Key
   592  You can also manually add keys to Tyk using your own key-generation algorithm. It is recommended if using this approach to ensure that the OrgID being used in the API Definition and the key data is blank so that Tyk does not try to prepend or manage the key in any way.
   593   * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
   594   * @param keyID The Key ID
   595   * @param optional nil or *KeysApiUpdateKeyOpts - Optional Parameters:
   596       * @param "Body" (optional.Interface of SessionState) - 
   597       * @param "Hashed" (optional.Bool) -  Use the hash of the key as input instead of the full key
   598       * @param "SuppressReset" (optional.String) -  Adding the suppress_reset parameter and setting it to 1, will cause Tyk not to reset the quota limit that is in the current live quota manager. By default Tyk will reset the quota in the live quota manager (initialising it) when adding a key. Adding the &#x60;suppress_reset&#x60; flag to the URL parameters will avoid this behaviour.
   599  @return ApiModifyKeySuccess
   600  */
   601  
   602  type KeysApiUpdateKeyOpts struct {
   603      Body optional.Interface
   604      Hashed optional.Bool
   605      SuppressReset optional.String
   606  }
   607  
   608  func (a *KeysApiService) UpdateKey(ctx context.Context, keyID string, localVarOptionals *KeysApiUpdateKeyOpts) (ApiModifyKeySuccess, *http.Response, error) {
   609  	var (
   610  		localVarHttpMethod = strings.ToUpper("Put")
   611  		localVarPostBody   interface{}
   612  		localVarFileName   string
   613  		localVarFileBytes  []byte
   614  		localVarReturnValue ApiModifyKeySuccess
   615  	)
   616  
   617  	// create path and map variables
   618  	localVarPath := a.client.cfg.BasePath + "/tyk/keys/{keyID}"
   619  	localVarPath = strings.Replace(localVarPath, "{"+"keyID"+"}", fmt.Sprintf("%v", keyID), -1)
   620  
   621  	localVarHeaderParams := make(map[string]string)
   622  	localVarQueryParams := url.Values{}
   623  	localVarFormParams := url.Values{}
   624  
   625  	if localVarOptionals != nil && localVarOptionals.Hashed.IsSet() {
   626  		localVarQueryParams.Add("hashed", parameterToString(localVarOptionals.Hashed.Value(), ""))
   627  	}
   628  	if localVarOptionals != nil && localVarOptionals.SuppressReset.IsSet() {
   629  		localVarQueryParams.Add("suppress_reset", parameterToString(localVarOptionals.SuppressReset.Value(), ""))
   630  	}
   631  	// to determine the Content-Type header
   632  	localVarHttpContentTypes := []string{"application/json"}
   633  
   634  	// set Content-Type header
   635  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
   636  	if localVarHttpContentType != "" {
   637  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
   638  	}
   639  
   640  	// to determine the Accept header
   641  	localVarHttpHeaderAccepts := []string{"application/json"}
   642  
   643  	// set Accept header
   644  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
   645  	if localVarHttpHeaderAccept != "" {
   646  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
   647  	}
   648  	// body params
   649  	if localVarOptionals != nil && localVarOptionals.Body.IsSet() {
   650  		
   651  		localVarOptionalBody:= localVarOptionals.Body.Value()
   652  		localVarPostBody = &localVarOptionalBody
   653  	}
   654  	if ctx != nil {
   655  		// API Key Authentication
   656  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   657  			var key string
   658  			if auth.Prefix != "" {
   659  				key = auth.Prefix + " " + auth.Key
   660  			} else {
   661  				key = auth.Key
   662  			}
   663  			localVarHeaderParams["X-Tyk-Authorization"] = key
   664  			
   665  		}
   666  	}
   667  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
   668  	if err != nil {
   669  		return localVarReturnValue, nil, err
   670  	}
   671  
   672  	localVarHttpResponse, err := a.client.callAPI(r)
   673  	if err != nil || localVarHttpResponse == nil {
   674  		return localVarReturnValue, localVarHttpResponse, err
   675  	}
   676  
   677  	localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
   678  	localVarHttpResponse.Body.Close()
   679  	if err != nil {
   680  		return localVarReturnValue, localVarHttpResponse, err
   681  	}
   682  
   683  	if localVarHttpResponse.StatusCode < 300 {
   684  		// If we succeed, return the data, otherwise pass on to decode error.
   685  		err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   686  		if err == nil { 
   687  			return localVarReturnValue, localVarHttpResponse, err
   688  		}
   689  	}
   690  
   691  	if localVarHttpResponse.StatusCode >= 300 {
   692  		newErr := GenericSwaggerError{
   693  			body: localVarBody,
   694  			error: localVarHttpResponse.Status,
   695  		}
   696  		if localVarHttpResponse.StatusCode == 200 {
   697  			var v ApiModifyKeySuccess
   698  			err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   699  				if err != nil {
   700  					newErr.error = err.Error()
   701  					return localVarReturnValue, localVarHttpResponse, newErr
   702  				}
   703  				newErr.model = v
   704  				return localVarReturnValue, localVarHttpResponse, newErr
   705  		}
   706  		if localVarHttpResponse.StatusCode == 400 {
   707  			var v ApiStatusMessage
   708  			err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   709  				if err != nil {
   710  					newErr.error = err.Error()
   711  					return localVarReturnValue, localVarHttpResponse, newErr
   712  				}
   713  				newErr.model = v
   714  				return localVarReturnValue, localVarHttpResponse, newErr
   715  		}
   716  		return localVarReturnValue, localVarHttpResponse, newErr
   717  	}
   718  
   719  	return localVarReturnValue, localVarHttpResponse, nil
   720  }