bunnyshell.com/sdk@v0.16.0/api_registry_integration.go (about)

     1  /*
     2  API Bunnyshell Environments
     3  
     4  Interact with Bunnyshell Platform
     5  
     6  API version: 1.1.0
     7  Contact: osi+support@bunnyshell.com
     8  */
     9  
    10  // Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
    11  
    12  package sdk
    13  
    14  import (
    15  	"bytes"
    16  	"context"
    17  	"io"
    18  	"net/http"
    19  	"net/url"
    20  	"strings"
    21  )
    22  
    23  // RegistryIntegrationAPIService RegistryIntegrationAPI service
    24  type RegistryIntegrationAPIService service
    25  
    26  type ApiRegistryIntegrationListRequest struct {
    27  	ctx          context.Context
    28  	ApiService   *RegistryIntegrationAPIService
    29  	page         *int32
    30  	organization *string
    31  }
    32  
    33  // The collection page number
    34  func (r ApiRegistryIntegrationListRequest) Page(page int32) ApiRegistryIntegrationListRequest {
    35  	r.page = &page
    36  	return r
    37  }
    38  
    39  // Filter by organization
    40  func (r ApiRegistryIntegrationListRequest) Organization(organization string) ApiRegistryIntegrationListRequest {
    41  	r.organization = &organization
    42  	return r
    43  }
    44  
    45  func (r ApiRegistryIntegrationListRequest) Execute() (*PaginatedRegistryIntegrationCollection, *http.Response, error) {
    46  	return r.ApiService.RegistryIntegrationListExecute(r)
    47  }
    48  
    49  /*
    50  RegistryIntegrationList List Registry integrations matching any selected filters.
    51  
    52  List Registry integrations matching any selected filters.
    53  
    54  	@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
    55  	@return ApiRegistryIntegrationListRequest
    56  */
    57  func (a *RegistryIntegrationAPIService) RegistryIntegrationList(ctx context.Context) ApiRegistryIntegrationListRequest {
    58  	return ApiRegistryIntegrationListRequest{
    59  		ApiService: a,
    60  		ctx:        ctx,
    61  	}
    62  }
    63  
    64  // Execute executes the request
    65  //
    66  //	@return PaginatedRegistryIntegrationCollection
    67  func (a *RegistryIntegrationAPIService) RegistryIntegrationListExecute(r ApiRegistryIntegrationListRequest) (*PaginatedRegistryIntegrationCollection, *http.Response, error) {
    68  	var (
    69  		localVarHTTPMethod  = http.MethodGet
    70  		localVarPostBody    interface{}
    71  		formFiles           []formFile
    72  		localVarReturnValue *PaginatedRegistryIntegrationCollection
    73  	)
    74  
    75  	localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "RegistryIntegrationAPIService.RegistryIntegrationList")
    76  	if err != nil {
    77  		return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
    78  	}
    79  
    80  	localVarPath := localBasePath + "/v1/registry_integrations"
    81  
    82  	localVarHeaderParams := make(map[string]string)
    83  	localVarQueryParams := url.Values{}
    84  	localVarFormParams := url.Values{}
    85  
    86  	if r.page != nil {
    87  		parameterAddToHeaderOrQuery(localVarQueryParams, "page", r.page, "")
    88  	} else {
    89  		var defaultValue int32 = 1
    90  		r.page = &defaultValue
    91  	}
    92  	if r.organization != nil {
    93  		parameterAddToHeaderOrQuery(localVarQueryParams, "organization", r.organization, "")
    94  	}
    95  	// to determine the Content-Type header
    96  	localVarHTTPContentTypes := []string{}
    97  
    98  	// set Content-Type header
    99  	localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
   100  	if localVarHTTPContentType != "" {
   101  		localVarHeaderParams["Content-Type"] = localVarHTTPContentType
   102  	}
   103  
   104  	// to determine the Accept header
   105  	localVarHTTPHeaderAccepts := []string{"application/hal+json", "application/problem+json"}
   106  
   107  	// set Accept header
   108  	localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
   109  	if localVarHTTPHeaderAccept != "" {
   110  		localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
   111  	}
   112  	if r.ctx != nil {
   113  		// API Key Authentication
   114  		if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
   115  			if apiKey, ok := auth["JWT"]; ok {
   116  				var key string
   117  				if apiKey.Prefix != "" {
   118  					key = apiKey.Prefix + " " + apiKey.Key
   119  				} else {
   120  					key = apiKey.Key
   121  				}
   122  				localVarHeaderParams["Authorization"] = key
   123  			}
   124  		}
   125  	}
   126  	if r.ctx != nil {
   127  		// API Key Authentication
   128  		if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
   129  			if apiKey, ok := auth["ApiKeyAuth"]; ok {
   130  				var key string
   131  				if apiKey.Prefix != "" {
   132  					key = apiKey.Prefix + " " + apiKey.Key
   133  				} else {
   134  					key = apiKey.Key
   135  				}
   136  				localVarHeaderParams["X-Auth-Token"] = key
   137  			}
   138  		}
   139  	}
   140  	req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
   141  	if err != nil {
   142  		return localVarReturnValue, nil, err
   143  	}
   144  
   145  	localVarHTTPResponse, err := a.client.callAPI(req)
   146  	if err != nil || localVarHTTPResponse == nil {
   147  		return localVarReturnValue, localVarHTTPResponse, err
   148  	}
   149  
   150  	localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
   151  	localVarHTTPResponse.Body.Close()
   152  	localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
   153  	if err != nil {
   154  		return localVarReturnValue, localVarHTTPResponse, err
   155  	}
   156  
   157  	if localVarHTTPResponse.StatusCode >= 300 {
   158  		newErr := &GenericOpenAPIError{
   159  			body:  localVarBody,
   160  			error: localVarHTTPResponse.Status,
   161  		}
   162  		if localVarHTTPResponse.StatusCode >= 400 && localVarHTTPResponse.StatusCode < 500 {
   163  			var v ProblemGeneric
   164  			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
   165  			if err != nil {
   166  				newErr.error = err.Error()
   167  				return localVarReturnValue, localVarHTTPResponse, newErr
   168  			}
   169  			newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
   170  			newErr.model = v
   171  		}
   172  		return localVarReturnValue, localVarHTTPResponse, newErr
   173  	}
   174  
   175  	err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
   176  	if err != nil {
   177  		newErr := &GenericOpenAPIError{
   178  			body:  localVarBody,
   179  			error: err.Error(),
   180  		}
   181  		return localVarReturnValue, localVarHTTPResponse, newErr
   182  	}
   183  
   184  	return localVarReturnValue, localVarHTTPResponse, nil
   185  }
   186  
   187  type ApiRegistryIntegrationViewRequest struct {
   188  	ctx        context.Context
   189  	ApiService *RegistryIntegrationAPIService
   190  	id         string
   191  }
   192  
   193  func (r ApiRegistryIntegrationViewRequest) Execute() (*RegistryIntegrationItem, *http.Response, error) {
   194  	return r.ApiService.RegistryIntegrationViewExecute(r)
   195  }
   196  
   197  /*
   198  RegistryIntegrationView View a specific Registry integration.
   199  
   200  View a specific Registry integration.
   201  
   202  	@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
   203  	@param id Resource identifier
   204  	@return ApiRegistryIntegrationViewRequest
   205  */
   206  func (a *RegistryIntegrationAPIService) RegistryIntegrationView(ctx context.Context, id string) ApiRegistryIntegrationViewRequest {
   207  	return ApiRegistryIntegrationViewRequest{
   208  		ApiService: a,
   209  		ctx:        ctx,
   210  		id:         id,
   211  	}
   212  }
   213  
   214  // Execute executes the request
   215  //
   216  //	@return RegistryIntegrationItem
   217  func (a *RegistryIntegrationAPIService) RegistryIntegrationViewExecute(r ApiRegistryIntegrationViewRequest) (*RegistryIntegrationItem, *http.Response, error) {
   218  	var (
   219  		localVarHTTPMethod  = http.MethodGet
   220  		localVarPostBody    interface{}
   221  		formFiles           []formFile
   222  		localVarReturnValue *RegistryIntegrationItem
   223  	)
   224  
   225  	localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "RegistryIntegrationAPIService.RegistryIntegrationView")
   226  	if err != nil {
   227  		return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
   228  	}
   229  
   230  	localVarPath := localBasePath + "/v1/registry_integrations/{id}"
   231  	localVarPath = strings.Replace(localVarPath, "{"+"id"+"}", url.PathEscape(parameterValueToString(r.id, "id")), -1)
   232  
   233  	localVarHeaderParams := make(map[string]string)
   234  	localVarQueryParams := url.Values{}
   235  	localVarFormParams := url.Values{}
   236  
   237  	// to determine the Content-Type header
   238  	localVarHTTPContentTypes := []string{}
   239  
   240  	// set Content-Type header
   241  	localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
   242  	if localVarHTTPContentType != "" {
   243  		localVarHeaderParams["Content-Type"] = localVarHTTPContentType
   244  	}
   245  
   246  	// to determine the Accept header
   247  	localVarHTTPHeaderAccepts := []string{"application/hal+json", "application/problem+json"}
   248  
   249  	// set Accept header
   250  	localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
   251  	if localVarHTTPHeaderAccept != "" {
   252  		localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
   253  	}
   254  	if r.ctx != nil {
   255  		// API Key Authentication
   256  		if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
   257  			if apiKey, ok := auth["JWT"]; ok {
   258  				var key string
   259  				if apiKey.Prefix != "" {
   260  					key = apiKey.Prefix + " " + apiKey.Key
   261  				} else {
   262  					key = apiKey.Key
   263  				}
   264  				localVarHeaderParams["Authorization"] = key
   265  			}
   266  		}
   267  	}
   268  	if r.ctx != nil {
   269  		// API Key Authentication
   270  		if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
   271  			if apiKey, ok := auth["ApiKeyAuth"]; ok {
   272  				var key string
   273  				if apiKey.Prefix != "" {
   274  					key = apiKey.Prefix + " " + apiKey.Key
   275  				} else {
   276  					key = apiKey.Key
   277  				}
   278  				localVarHeaderParams["X-Auth-Token"] = key
   279  			}
   280  		}
   281  	}
   282  	req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
   283  	if err != nil {
   284  		return localVarReturnValue, nil, err
   285  	}
   286  
   287  	localVarHTTPResponse, err := a.client.callAPI(req)
   288  	if err != nil || localVarHTTPResponse == nil {
   289  		return localVarReturnValue, localVarHTTPResponse, err
   290  	}
   291  
   292  	localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
   293  	localVarHTTPResponse.Body.Close()
   294  	localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
   295  	if err != nil {
   296  		return localVarReturnValue, localVarHTTPResponse, err
   297  	}
   298  
   299  	if localVarHTTPResponse.StatusCode >= 300 {
   300  		newErr := &GenericOpenAPIError{
   301  			body:  localVarBody,
   302  			error: localVarHTTPResponse.Status,
   303  		}
   304  		if localVarHTTPResponse.StatusCode >= 400 && localVarHTTPResponse.StatusCode < 500 {
   305  			var v ProblemGeneric
   306  			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
   307  			if err != nil {
   308  				newErr.error = err.Error()
   309  				return localVarReturnValue, localVarHTTPResponse, newErr
   310  			}
   311  			newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
   312  			newErr.model = v
   313  		}
   314  		return localVarReturnValue, localVarHTTPResponse, newErr
   315  	}
   316  
   317  	err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
   318  	if err != nil {
   319  		newErr := &GenericOpenAPIError{
   320  			body:  localVarBody,
   321  			error: err.Error(),
   322  		}
   323  		return localVarReturnValue, localVarHTTPResponse, newErr
   324  	}
   325  
   326  	return localVarReturnValue, localVarHTTPResponse, nil
   327  }