Move URLs from default section of config to DB

This change moves the callback_url, metadata_url and webhooks_url from
the config to the database. The goal is to move as much as possible from
the config to the DB, in preparation for a potential refactor that will
allow GARM to scale out. This would allow multiple nodes to share a single
source of truth.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2024-06-05 06:41:16 +00:00
parent 7ee235aeb0
commit 9748aa47af
22 changed files with 1067 additions and 177 deletions

View file

@ -0,0 +1,106 @@
// Code generated by go-swagger; DO NOT EDIT.
package controller
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
)
// New creates a new controller API client.
func New(transport runtime.ClientTransport, formats strfmt.Registry) ClientService {
return &Client{transport: transport, formats: formats}
}
// New creates a new controller API client with basic auth credentials.
// It takes the following parameters:
// - host: http host (github.com).
// - basePath: any base path for the API client ("/v1", "/v3").
// - scheme: http scheme ("http", "https").
// - user: user for basic authentication header.
// - password: password for basic authentication header.
func NewClientWithBasicAuth(host, basePath, scheme, user, password string) ClientService {
transport := httptransport.New(host, basePath, []string{scheme})
transport.DefaultAuthentication = httptransport.BasicAuth(user, password)
return &Client{transport: transport, formats: strfmt.Default}
}
// New creates a new controller API client with a bearer token for authentication.
// It takes the following parameters:
// - host: http host (github.com).
// - basePath: any base path for the API client ("/v1", "/v3").
// - scheme: http scheme ("http", "https").
// - bearerToken: bearer token for Bearer authentication header.
func NewClientWithBearerToken(host, basePath, scheme, bearerToken string) ClientService {
transport := httptransport.New(host, basePath, []string{scheme})
transport.DefaultAuthentication = httptransport.BearerToken(bearerToken)
return &Client{transport: transport, formats: strfmt.Default}
}
/*
Client for controller API
*/
type Client struct {
transport runtime.ClientTransport
formats strfmt.Registry
}
// ClientOption may be used to customize the behavior of Client methods.
type ClientOption func(*runtime.ClientOperation)
// ClientService is the interface for Client methods
type ClientService interface {
UpdateController(params *UpdateControllerParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UpdateControllerOK, error)
SetTransport(transport runtime.ClientTransport)
}
/*
UpdateController updates controller
*/
func (a *Client) UpdateController(params *UpdateControllerParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UpdateControllerOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewUpdateControllerParams()
}
op := &runtime.ClientOperation{
ID: "UpdateController",
Method: "PUT",
PathPattern: "/controller",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &UpdateControllerReader{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.(*UpdateControllerOK)
if ok {
return success, nil
}
// unexpected success response
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
msg := fmt.Sprintf("unexpected success response for UpdateController: API contract not enforced by server. Client expected to get an error, but got: %T", result)
panic(msg)
}
// SetTransport changes the transport on the client
func (a *Client) SetTransport(transport runtime.ClientTransport) {
a.transport = transport
}

View file

@ -0,0 +1,151 @@
// Code generated by go-swagger; DO NOT EDIT.
package controller
// 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"
garm_params "github.com/cloudbase/garm/params"
)
// NewUpdateControllerParams creates a new UpdateControllerParams 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 NewUpdateControllerParams() *UpdateControllerParams {
return &UpdateControllerParams{
timeout: cr.DefaultTimeout,
}
}
// NewUpdateControllerParamsWithTimeout creates a new UpdateControllerParams object
// with the ability to set a timeout on a request.
func NewUpdateControllerParamsWithTimeout(timeout time.Duration) *UpdateControllerParams {
return &UpdateControllerParams{
timeout: timeout,
}
}
// NewUpdateControllerParamsWithContext creates a new UpdateControllerParams object
// with the ability to set a context for a request.
func NewUpdateControllerParamsWithContext(ctx context.Context) *UpdateControllerParams {
return &UpdateControllerParams{
Context: ctx,
}
}
// NewUpdateControllerParamsWithHTTPClient creates a new UpdateControllerParams object
// with the ability to set a custom HTTPClient for a request.
func NewUpdateControllerParamsWithHTTPClient(client *http.Client) *UpdateControllerParams {
return &UpdateControllerParams{
HTTPClient: client,
}
}
/*
UpdateControllerParams contains all the parameters to send to the API endpoint
for the update controller operation.
Typically these are written to a http.Request.
*/
type UpdateControllerParams struct {
/* Body.
Parameters used when updating the controller.
*/
Body garm_params.UpdateControllerParams
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithDefaults hydrates default values in the update controller params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *UpdateControllerParams) WithDefaults() *UpdateControllerParams {
o.SetDefaults()
return o
}
// SetDefaults hydrates default values in the update controller params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *UpdateControllerParams) SetDefaults() {
// no default values defined for this parameter
}
// WithTimeout adds the timeout to the update controller params
func (o *UpdateControllerParams) WithTimeout(timeout time.Duration) *UpdateControllerParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the update controller params
func (o *UpdateControllerParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the update controller params
func (o *UpdateControllerParams) WithContext(ctx context.Context) *UpdateControllerParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the update controller params
func (o *UpdateControllerParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the update controller params
func (o *UpdateControllerParams) WithHTTPClient(client *http.Client) *UpdateControllerParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the update controller params
func (o *UpdateControllerParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithBody adds the body to the update controller params
func (o *UpdateControllerParams) WithBody(body garm_params.UpdateControllerParams) *UpdateControllerParams {
o.SetBody(body)
return o
}
// SetBody adds the body to the update controller params
func (o *UpdateControllerParams) SetBody(body garm_params.UpdateControllerParams) {
o.Body = body
}
// WriteToRequest writes these params to a swagger request
func (o *UpdateControllerParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if err := r.SetBodyParam(o.Body); 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 controller
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"encoding/json"
"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"
)
// UpdateControllerReader is a Reader for the UpdateController structure.
type UpdateControllerReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *UpdateControllerReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewUpdateControllerOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
case 400:
result := NewUpdateControllerBadRequest()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
default:
return nil, runtime.NewAPIError("[PUT /controller] UpdateController", response, response.Code())
}
}
// NewUpdateControllerOK creates a UpdateControllerOK with default headers values
func NewUpdateControllerOK() *UpdateControllerOK {
return &UpdateControllerOK{}
}
/*
UpdateControllerOK describes a response with status code 200, with default header values.
ControllerInfo
*/
type UpdateControllerOK struct {
Payload garm_params.ControllerInfo
}
// IsSuccess returns true when this update controller o k response has a 2xx status code
func (o *UpdateControllerOK) IsSuccess() bool {
return true
}
// IsRedirect returns true when this update controller o k response has a 3xx status code
func (o *UpdateControllerOK) IsRedirect() bool {
return false
}
// IsClientError returns true when this update controller o k response has a 4xx status code
func (o *UpdateControllerOK) IsClientError() bool {
return false
}
// IsServerError returns true when this update controller o k response has a 5xx status code
func (o *UpdateControllerOK) IsServerError() bool {
return false
}
// IsCode returns true when this update controller o k response a status code equal to that given
func (o *UpdateControllerOK) IsCode(code int) bool {
return code == 200
}
// Code gets the status code for the update controller o k response
func (o *UpdateControllerOK) Code() int {
return 200
}
func (o *UpdateControllerOK) Error() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[PUT /controller][%d] updateControllerOK %s", 200, payload)
}
func (o *UpdateControllerOK) String() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[PUT /controller][%d] updateControllerOK %s", 200, payload)
}
func (o *UpdateControllerOK) GetPayload() garm_params.ControllerInfo {
return o.Payload
}
func (o *UpdateControllerOK) 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
}
// NewUpdateControllerBadRequest creates a UpdateControllerBadRequest with default headers values
func NewUpdateControllerBadRequest() *UpdateControllerBadRequest {
return &UpdateControllerBadRequest{}
}
/*
UpdateControllerBadRequest describes a response with status code 400, with default header values.
APIErrorResponse
*/
type UpdateControllerBadRequest struct {
Payload apiserver_params.APIErrorResponse
}
// IsSuccess returns true when this update controller bad request response has a 2xx status code
func (o *UpdateControllerBadRequest) IsSuccess() bool {
return false
}
// IsRedirect returns true when this update controller bad request response has a 3xx status code
func (o *UpdateControllerBadRequest) IsRedirect() bool {
return false
}
// IsClientError returns true when this update controller bad request response has a 4xx status code
func (o *UpdateControllerBadRequest) IsClientError() bool {
return true
}
// IsServerError returns true when this update controller bad request response has a 5xx status code
func (o *UpdateControllerBadRequest) IsServerError() bool {
return false
}
// IsCode returns true when this update controller bad request response a status code equal to that given
func (o *UpdateControllerBadRequest) IsCode(code int) bool {
return code == 400
}
// Code gets the status code for the update controller bad request response
func (o *UpdateControllerBadRequest) Code() int {
return 400
}
func (o *UpdateControllerBadRequest) Error() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[PUT /controller][%d] updateControllerBadRequest %s", 400, payload)
}
func (o *UpdateControllerBadRequest) String() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[PUT /controller][%d] updateControllerBadRequest %s", 400, payload)
}
func (o *UpdateControllerBadRequest) GetPayload() apiserver_params.APIErrorResponse {
return o.Payload
}
func (o *UpdateControllerBadRequest) 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
}