github.com/safedep/dry@v0.0.0-20241016050132-a15651f0548b/apiguard/tykgen/api_certs.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  	"github.com/antihax/optional"
    19  )
    20  
    21  // Linger please
    22  var (
    23  	_ context.Context
    24  )
    25  
    26  type CertsApiService service
    27  /*
    28  CertsApiService Add a certificate
    29  Add a certificate to the Tyk Gateway
    30   * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
    31   * @param orgId Organisation ID to list the certificates
    32   * @param optional nil or *CertsApiAddCertOpts - Optional Parameters:
    33       * @param "Body" (optional.Interface of string) - 
    34  @return ApiCertificateStatusMessage
    35  */
    36  
    37  type CertsApiAddCertOpts struct {
    38      Body optional.Interface
    39  }
    40  
    41  func (a *CertsApiService) AddCert(ctx context.Context, orgId string, localVarOptionals *CertsApiAddCertOpts) (ApiCertificateStatusMessage, *http.Response, error) {
    42  	var (
    43  		localVarHttpMethod = strings.ToUpper("Post")
    44  		localVarPostBody   interface{}
    45  		localVarFileName   string
    46  		localVarFileBytes  []byte
    47  		localVarReturnValue ApiCertificateStatusMessage
    48  	)
    49  
    50  	// create path and map variables
    51  	localVarPath := a.client.cfg.BasePath + "/tyk/certs"
    52  
    53  	localVarHeaderParams := make(map[string]string)
    54  	localVarQueryParams := url.Values{}
    55  	localVarFormParams := url.Values{}
    56  
    57  	localVarQueryParams.Add("org_id", parameterToString(orgId, ""))
    58  	// to determine the Content-Type header
    59  	localVarHttpContentTypes := []string{"text/plain"}
    60  
    61  	// set Content-Type header
    62  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
    63  	if localVarHttpContentType != "" {
    64  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
    65  	}
    66  
    67  	// to determine the Accept header
    68  	localVarHttpHeaderAccepts := []string{"application/json"}
    69  
    70  	// set Accept header
    71  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
    72  	if localVarHttpHeaderAccept != "" {
    73  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
    74  	}
    75  	// body params
    76  	if localVarOptionals != nil && localVarOptionals.Body.IsSet() {
    77  		
    78  		localVarOptionalBody:= localVarOptionals.Body.Value()
    79  		localVarPostBody = &localVarOptionalBody
    80  	}
    81  	if ctx != nil {
    82  		// API Key Authentication
    83  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
    84  			var key string
    85  			if auth.Prefix != "" {
    86  				key = auth.Prefix + " " + auth.Key
    87  			} else {
    88  				key = auth.Key
    89  			}
    90  			localVarHeaderParams["X-Tyk-Authorization"] = key
    91  			
    92  		}
    93  	}
    94  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
    95  	if err != nil {
    96  		return localVarReturnValue, nil, err
    97  	}
    98  
    99  	localVarHttpResponse, err := a.client.callAPI(r)
   100  	if err != nil || localVarHttpResponse == nil {
   101  		return localVarReturnValue, localVarHttpResponse, err
   102  	}
   103  
   104  	localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
   105  	localVarHttpResponse.Body.Close()
   106  	if err != nil {
   107  		return localVarReturnValue, localVarHttpResponse, err
   108  	}
   109  
   110  	if localVarHttpResponse.StatusCode < 300 {
   111  		// If we succeed, return the data, otherwise pass on to decode error.
   112  		err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   113  		if err == nil { 
   114  			return localVarReturnValue, localVarHttpResponse, err
   115  		}
   116  	}
   117  
   118  	if localVarHttpResponse.StatusCode >= 300 {
   119  		newErr := GenericSwaggerError{
   120  			body: localVarBody,
   121  			error: localVarHttpResponse.Status,
   122  		}
   123  		if localVarHttpResponse.StatusCode == 200 {
   124  			var v ApiCertificateStatusMessage
   125  			err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   126  				if err != nil {
   127  					newErr.error = err.Error()
   128  					return localVarReturnValue, localVarHttpResponse, newErr
   129  				}
   130  				newErr.model = v
   131  				return localVarReturnValue, localVarHttpResponse, newErr
   132  		}
   133  		if localVarHttpResponse.StatusCode == 403 {
   134  			var v ApiStatusMessage
   135  			err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   136  				if err != nil {
   137  					newErr.error = err.Error()
   138  					return localVarReturnValue, localVarHttpResponse, newErr
   139  				}
   140  				newErr.model = v
   141  				return localVarReturnValue, localVarHttpResponse, newErr
   142  		}
   143  		return localVarReturnValue, localVarHttpResponse, newErr
   144  	}
   145  
   146  	return localVarReturnValue, localVarHttpResponse, nil
   147  }
   148  /*
   149  CertsApiService Delete Certificate
   150  Delete certificate by id
   151   * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
   152   * @param certID Certifiicate ID to be deleted
   153   * @param orgId Organisation ID to list the certificates
   154  @return ApiStatusMessage
   155  */
   156  func (a *CertsApiService) DeleteCerts(ctx context.Context, certID string, orgId string) (ApiStatusMessage, *http.Response, error) {
   157  	var (
   158  		localVarHttpMethod = strings.ToUpper("Delete")
   159  		localVarPostBody   interface{}
   160  		localVarFileName   string
   161  		localVarFileBytes  []byte
   162  		localVarReturnValue ApiStatusMessage
   163  	)
   164  
   165  	// create path and map variables
   166  	localVarPath := a.client.cfg.BasePath + "/tyk/certs"
   167  
   168  	localVarHeaderParams := make(map[string]string)
   169  	localVarQueryParams := url.Values{}
   170  	localVarFormParams := url.Values{}
   171  
   172  	localVarQueryParams.Add("certID", parameterToString(certID, ""))
   173  	localVarQueryParams.Add("org_id", parameterToString(orgId, ""))
   174  	// to determine the Content-Type header
   175  	localVarHttpContentTypes := []string{}
   176  
   177  	// set Content-Type header
   178  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
   179  	if localVarHttpContentType != "" {
   180  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
   181  	}
   182  
   183  	// to determine the Accept header
   184  	localVarHttpHeaderAccepts := []string{"application/json"}
   185  
   186  	// set Accept header
   187  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
   188  	if localVarHttpHeaderAccept != "" {
   189  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
   190  	}
   191  	if ctx != nil {
   192  		// API Key Authentication
   193  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   194  			var key string
   195  			if auth.Prefix != "" {
   196  				key = auth.Prefix + " " + auth.Key
   197  			} else {
   198  				key = auth.Key
   199  			}
   200  			localVarHeaderParams["X-Tyk-Authorization"] = key
   201  			
   202  		}
   203  	}
   204  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
   205  	if err != nil {
   206  		return localVarReturnValue, nil, err
   207  	}
   208  
   209  	localVarHttpResponse, err := a.client.callAPI(r)
   210  	if err != nil || localVarHttpResponse == nil {
   211  		return localVarReturnValue, localVarHttpResponse, err
   212  	}
   213  
   214  	localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
   215  	localVarHttpResponse.Body.Close()
   216  	if err != nil {
   217  		return localVarReturnValue, localVarHttpResponse, err
   218  	}
   219  
   220  	if localVarHttpResponse.StatusCode < 300 {
   221  		// If we succeed, return the data, otherwise pass on to decode error.
   222  		err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   223  		if err == nil { 
   224  			return localVarReturnValue, localVarHttpResponse, err
   225  		}
   226  	}
   227  
   228  	if localVarHttpResponse.StatusCode >= 300 {
   229  		newErr := GenericSwaggerError{
   230  			body: localVarBody,
   231  			error: localVarHttpResponse.Status,
   232  		}
   233  		if localVarHttpResponse.StatusCode == 200 {
   234  			var v ApiStatusMessage
   235  			err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   236  				if err != nil {
   237  					newErr.error = err.Error()
   238  					return localVarReturnValue, localVarHttpResponse, newErr
   239  				}
   240  				newErr.model = v
   241  				return localVarReturnValue, localVarHttpResponse, newErr
   242  		}
   243  		return localVarReturnValue, localVarHttpResponse, newErr
   244  	}
   245  
   246  	return localVarReturnValue, localVarHttpResponse, nil
   247  }
   248  /*
   249  CertsApiService List Certificates
   250  List All Certificates in the Tyk Gateway
   251   * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
   252   * @param orgId Organisation ID to list the certificates
   253   * @param optional nil or *CertsApiListCertsOpts - Optional Parameters:
   254       * @param "Mode" (optional.String) -  Mode to list the certificate details
   255       * @param "CertID" (optional.String) -  Comma separated list of certificates to list
   256  @return InlineResponse2001
   257  */
   258  
   259  type CertsApiListCertsOpts struct {
   260      Mode optional.String
   261      CertID optional.String
   262  }
   263  
   264  func (a *CertsApiService) ListCerts(ctx context.Context, orgId string, localVarOptionals *CertsApiListCertsOpts) (InlineResponse2001, *http.Response, error) {
   265  	var (
   266  		localVarHttpMethod = strings.ToUpper("Get")
   267  		localVarPostBody   interface{}
   268  		localVarFileName   string
   269  		localVarFileBytes  []byte
   270  		localVarReturnValue InlineResponse2001
   271  	)
   272  
   273  	// create path and map variables
   274  	localVarPath := a.client.cfg.BasePath + "/tyk/certs"
   275  
   276  	localVarHeaderParams := make(map[string]string)
   277  	localVarQueryParams := url.Values{}
   278  	localVarFormParams := url.Values{}
   279  
   280  	localVarQueryParams.Add("org_id", parameterToString(orgId, ""))
   281  	if localVarOptionals != nil && localVarOptionals.Mode.IsSet() {
   282  		localVarQueryParams.Add("mode", parameterToString(localVarOptionals.Mode.Value(), ""))
   283  	}
   284  	if localVarOptionals != nil && localVarOptionals.CertID.IsSet() {
   285  		localVarQueryParams.Add("certID", parameterToString(localVarOptionals.CertID.Value(), ""))
   286  	}
   287  	// to determine the Content-Type header
   288  	localVarHttpContentTypes := []string{}
   289  
   290  	// set Content-Type header
   291  	localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
   292  	if localVarHttpContentType != "" {
   293  		localVarHeaderParams["Content-Type"] = localVarHttpContentType
   294  	}
   295  
   296  	// to determine the Accept header
   297  	localVarHttpHeaderAccepts := []string{"application/json"}
   298  
   299  	// set Accept header
   300  	localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
   301  	if localVarHttpHeaderAccept != "" {
   302  		localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
   303  	}
   304  	if ctx != nil {
   305  		// API Key Authentication
   306  		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
   307  			var key string
   308  			if auth.Prefix != "" {
   309  				key = auth.Prefix + " " + auth.Key
   310  			} else {
   311  				key = auth.Key
   312  			}
   313  			localVarHeaderParams["X-Tyk-Authorization"] = key
   314  			
   315  		}
   316  	}
   317  	r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
   318  	if err != nil {
   319  		return localVarReturnValue, nil, err
   320  	}
   321  
   322  	localVarHttpResponse, err := a.client.callAPI(r)
   323  	if err != nil || localVarHttpResponse == nil {
   324  		return localVarReturnValue, localVarHttpResponse, err
   325  	}
   326  
   327  	localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
   328  	localVarHttpResponse.Body.Close()
   329  	if err != nil {
   330  		return localVarReturnValue, localVarHttpResponse, err
   331  	}
   332  
   333  	if localVarHttpResponse.StatusCode < 300 {
   334  		// If we succeed, return the data, otherwise pass on to decode error.
   335  		err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   336  		if err == nil { 
   337  			return localVarReturnValue, localVarHttpResponse, err
   338  		}
   339  	}
   340  
   341  	if localVarHttpResponse.StatusCode >= 300 {
   342  		newErr := GenericSwaggerError{
   343  			body: localVarBody,
   344  			error: localVarHttpResponse.Status,
   345  		}
   346  		if localVarHttpResponse.StatusCode == 200 {
   347  			var v InlineResponse2001
   348  			err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
   349  				if err != nil {
   350  					newErr.error = err.Error()
   351  					return localVarReturnValue, localVarHttpResponse, newErr
   352  				}
   353  				newErr.model = v
   354  				return localVarReturnValue, localVarHttpResponse, newErr
   355  		}
   356  		return localVarReturnValue, localVarHttpResponse, newErr
   357  	}
   358  
   359  	return localVarReturnValue, localVarHttpResponse, nil
   360  }