Add webhook show, return info and some fixes

* Added a webhook show command. This gives us info about the webhook and
    if it is installed.
  * Return webhook info when installing the webhook
  * Small typo fixes.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2023-08-16 09:11:45 +00:00
parent 6051fa016c
commit 779afe980e
No known key found for this signature in database
GPG key ID: 7D073DCC2C074CB5
27 changed files with 1253 additions and 66 deletions

View file

@ -0,0 +1,151 @@
// Code generated by go-swagger; DO NOT EDIT.
package repositories
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
)
// NewGetRepoWebhookInfoParams creates a new GetRepoWebhookInfoParams object,
// with the default timeout for this client.
//
// Default values are not hydrated, since defaults are normally applied by the API server side.
//
// To enforce default values in parameter, use SetDefaults or WithDefaults.
func NewGetRepoWebhookInfoParams() *GetRepoWebhookInfoParams {
return &GetRepoWebhookInfoParams{
timeout: cr.DefaultTimeout,
}
}
// NewGetRepoWebhookInfoParamsWithTimeout creates a new GetRepoWebhookInfoParams object
// with the ability to set a timeout on a request.
func NewGetRepoWebhookInfoParamsWithTimeout(timeout time.Duration) *GetRepoWebhookInfoParams {
return &GetRepoWebhookInfoParams{
timeout: timeout,
}
}
// NewGetRepoWebhookInfoParamsWithContext creates a new GetRepoWebhookInfoParams object
// with the ability to set a context for a request.
func NewGetRepoWebhookInfoParamsWithContext(ctx context.Context) *GetRepoWebhookInfoParams {
return &GetRepoWebhookInfoParams{
Context: ctx,
}
}
// NewGetRepoWebhookInfoParamsWithHTTPClient creates a new GetRepoWebhookInfoParams object
// with the ability to set a custom HTTPClient for a request.
func NewGetRepoWebhookInfoParamsWithHTTPClient(client *http.Client) *GetRepoWebhookInfoParams {
return &GetRepoWebhookInfoParams{
HTTPClient: client,
}
}
/*
GetRepoWebhookInfoParams contains all the parameters to send to the API endpoint
for the get repo webhook info operation.
Typically these are written to a http.Request.
*/
type GetRepoWebhookInfoParams struct {
/* RepoID.
Repository ID.
*/
RepoID string
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithDefaults hydrates default values in the get repo webhook info params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *GetRepoWebhookInfoParams) WithDefaults() *GetRepoWebhookInfoParams {
o.SetDefaults()
return o
}
// SetDefaults hydrates default values in the get repo webhook info params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *GetRepoWebhookInfoParams) SetDefaults() {
// no default values defined for this parameter
}
// WithTimeout adds the timeout to the get repo webhook info params
func (o *GetRepoWebhookInfoParams) WithTimeout(timeout time.Duration) *GetRepoWebhookInfoParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the get repo webhook info params
func (o *GetRepoWebhookInfoParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the get repo webhook info params
func (o *GetRepoWebhookInfoParams) WithContext(ctx context.Context) *GetRepoWebhookInfoParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the get repo webhook info params
func (o *GetRepoWebhookInfoParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the get repo webhook info params
func (o *GetRepoWebhookInfoParams) WithHTTPClient(client *http.Client) *GetRepoWebhookInfoParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the get repo webhook info params
func (o *GetRepoWebhookInfoParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithRepoID adds the repoID to the get repo webhook info params
func (o *GetRepoWebhookInfoParams) WithRepoID(repoID string) *GetRepoWebhookInfoParams {
o.SetRepoID(repoID)
return o
}
// SetRepoID adds the repoId to the get repo webhook info params
func (o *GetRepoWebhookInfoParams) SetRepoID(repoID string) {
o.RepoID = repoID
}
// WriteToRequest writes these params to a swagger request
func (o *GetRepoWebhookInfoParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
// path param repoID
if err := r.SetPathParam("repoID", o.RepoID); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View file

@ -0,0 +1,179 @@
// Code generated by go-swagger; DO NOT EDIT.
package repositories
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
apiserver_params "github.com/cloudbase/garm/apiserver/params"
garm_params "github.com/cloudbase/garm/params"
)
// GetRepoWebhookInfoReader is a Reader for the GetRepoWebhookInfo structure.
type GetRepoWebhookInfoReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *GetRepoWebhookInfoReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewGetRepoWebhookInfoOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
result := NewGetRepoWebhookInfoDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
}
// NewGetRepoWebhookInfoOK creates a GetRepoWebhookInfoOK with default headers values
func NewGetRepoWebhookInfoOK() *GetRepoWebhookInfoOK {
return &GetRepoWebhookInfoOK{}
}
/*
GetRepoWebhookInfoOK describes a response with status code 200, with default header values.
HookInfo
*/
type GetRepoWebhookInfoOK struct {
Payload garm_params.HookInfo
}
// IsSuccess returns true when this get repo webhook info o k response has a 2xx status code
func (o *GetRepoWebhookInfoOK) IsSuccess() bool {
return true
}
// IsRedirect returns true when this get repo webhook info o k response has a 3xx status code
func (o *GetRepoWebhookInfoOK) IsRedirect() bool {
return false
}
// IsClientError returns true when this get repo webhook info o k response has a 4xx status code
func (o *GetRepoWebhookInfoOK) IsClientError() bool {
return false
}
// IsServerError returns true when this get repo webhook info o k response has a 5xx status code
func (o *GetRepoWebhookInfoOK) IsServerError() bool {
return false
}
// IsCode returns true when this get repo webhook info o k response a status code equal to that given
func (o *GetRepoWebhookInfoOK) IsCode(code int) bool {
return code == 200
}
// Code gets the status code for the get repo webhook info o k response
func (o *GetRepoWebhookInfoOK) Code() int {
return 200
}
func (o *GetRepoWebhookInfoOK) Error() string {
return fmt.Sprintf("[GET /repositories/{repoID}/webhook][%d] getRepoWebhookInfoOK %+v", 200, o.Payload)
}
func (o *GetRepoWebhookInfoOK) String() string {
return fmt.Sprintf("[GET /repositories/{repoID}/webhook][%d] getRepoWebhookInfoOK %+v", 200, o.Payload)
}
func (o *GetRepoWebhookInfoOK) GetPayload() garm_params.HookInfo {
return o.Payload
}
func (o *GetRepoWebhookInfoOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewGetRepoWebhookInfoDefault creates a GetRepoWebhookInfoDefault with default headers values
func NewGetRepoWebhookInfoDefault(code int) *GetRepoWebhookInfoDefault {
return &GetRepoWebhookInfoDefault{
_statusCode: code,
}
}
/*
GetRepoWebhookInfoDefault describes a response with status code -1, with default header values.
APIErrorResponse
*/
type GetRepoWebhookInfoDefault struct {
_statusCode int
Payload apiserver_params.APIErrorResponse
}
// IsSuccess returns true when this get repo webhook info default response has a 2xx status code
func (o *GetRepoWebhookInfoDefault) IsSuccess() bool {
return o._statusCode/100 == 2
}
// IsRedirect returns true when this get repo webhook info default response has a 3xx status code
func (o *GetRepoWebhookInfoDefault) IsRedirect() bool {
return o._statusCode/100 == 3
}
// IsClientError returns true when this get repo webhook info default response has a 4xx status code
func (o *GetRepoWebhookInfoDefault) IsClientError() bool {
return o._statusCode/100 == 4
}
// IsServerError returns true when this get repo webhook info default response has a 5xx status code
func (o *GetRepoWebhookInfoDefault) IsServerError() bool {
return o._statusCode/100 == 5
}
// IsCode returns true when this get repo webhook info default response a status code equal to that given
func (o *GetRepoWebhookInfoDefault) IsCode(code int) bool {
return o._statusCode == code
}
// Code gets the status code for the get repo webhook info default response
func (o *GetRepoWebhookInfoDefault) Code() int {
return o._statusCode
}
func (o *GetRepoWebhookInfoDefault) Error() string {
return fmt.Sprintf("[GET /repositories/{repoID}/webhook][%d] GetRepoWebhookInfo default %+v", o._statusCode, o.Payload)
}
func (o *GetRepoWebhookInfoDefault) String() string {
return fmt.Sprintf("[GET /repositories/{repoID}/webhook][%d] GetRepoWebhookInfo default %+v", o._statusCode, o.Payload)
}
func (o *GetRepoWebhookInfoDefault) GetPayload() apiserver_params.APIErrorResponse {
return o.Payload
}
func (o *GetRepoWebhookInfoDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View file

@ -13,6 +13,7 @@ import (
"github.com/go-openapi/strfmt"
apiserver_params "github.com/cloudbase/garm/apiserver/params"
garm_params "github.com/cloudbase/garm/params"
)
// InstallRepoWebhookReader is a Reader for the InstallRepoWebhook structure.
@ -49,9 +50,10 @@ func NewInstallRepoWebhookOK() *InstallRepoWebhookOK {
/*
InstallRepoWebhookOK describes a response with status code 200, with default header values.
InstallRepoWebhookOK install repo webhook o k
HookInfo
*/
type InstallRepoWebhookOK struct {
Payload garm_params.HookInfo
}
// IsSuccess returns true when this install repo webhook o k response has a 2xx status code
@ -85,15 +87,24 @@ func (o *InstallRepoWebhookOK) Code() int {
}
func (o *InstallRepoWebhookOK) Error() string {
return fmt.Sprintf("[POST /repositories/{repoID}/webhook][%d] installRepoWebhookOK ", 200)
return fmt.Sprintf("[POST /repositories/{repoID}/webhook][%d] installRepoWebhookOK %+v", 200, o.Payload)
}
func (o *InstallRepoWebhookOK) String() string {
return fmt.Sprintf("[POST /repositories/{repoID}/webhook][%d] installRepoWebhookOK ", 200)
return fmt.Sprintf("[POST /repositories/{repoID}/webhook][%d] installRepoWebhookOK %+v", 200, o.Payload)
}
func (o *InstallRepoWebhookOK) GetPayload() garm_params.HookInfo {
return o.Payload
}
func (o *InstallRepoWebhookOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View file

@ -40,6 +40,8 @@ type ClientService interface {
GetRepoPool(params *GetRepoPoolParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetRepoPoolOK, error)
GetRepoWebhookInfo(params *GetRepoWebhookInfoParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetRepoWebhookInfoOK, error)
InstallRepoWebhook(params *InstallRepoWebhookParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*InstallRepoWebhookOK, error)
ListRepoInstances(params *ListRepoInstancesParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ListRepoInstancesOK, error)
@ -273,6 +275,44 @@ func (a *Client) GetRepoPool(params *GetRepoPoolParams, authInfo runtime.ClientA
return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
}
/*
GetRepoWebhookInfo gets information about the g a r m installed webhook on a repository
*/
func (a *Client) GetRepoWebhookInfo(params *GetRepoWebhookInfoParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetRepoWebhookInfoOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewGetRepoWebhookInfoParams()
}
op := &runtime.ClientOperation{
ID: "GetRepoWebhookInfo",
Method: "GET",
PathPattern: "/repositories/{repoID}/webhook",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &GetRepoWebhookInfoReader{formats: a.formats},
AuthInfo: authInfo,
Context: params.Context,
Client: params.HTTPClient,
}
for _, opt := range opts {
opt(op)
}
result, err := a.transport.Submit(op)
if err != nil {
return nil, err
}
success, ok := result.(*GetRepoWebhookInfoOK)
if ok {
return success, nil
}
// unexpected success response
unexpectedSuccess := result.(*GetRepoWebhookInfoDefault)
return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
}
/*
InstallRepoWebhook Install the GARM webhook for an organization. The secret configured on the organization will