untunnel swagger (#3, #9)

This commit is contained in:
Michael Quigley 2022-07-27 11:35:28 -04:00
parent ad93c613b5
commit b852518a0d
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
11 changed files with 693 additions and 0 deletions

View File

@ -32,6 +32,8 @@ type ClientOption func(*runtime.ClientOperation)
type ClientService interface { type ClientService interface {
Tunnel(params *TunnelParams, opts ...ClientOption) (*TunnelCreated, error) Tunnel(params *TunnelParams, opts ...ClientOption) (*TunnelCreated, error)
Untunnel(params *UntunnelParams, opts ...ClientOption) (*UntunnelOK, error)
SetTransport(transport runtime.ClientTransport) SetTransport(transport runtime.ClientTransport)
} }
@ -73,6 +75,44 @@ func (a *Client) Tunnel(params *TunnelParams, opts ...ClientOption) (*TunnelCrea
panic(msg) panic(msg)
} }
/*
Untunnel untunnel API
*/
func (a *Client) Untunnel(params *UntunnelParams, opts ...ClientOption) (*UntunnelOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewUntunnelParams()
}
op := &runtime.ClientOperation{
ID: "untunnel",
Method: "DELETE",
PathPattern: "/untunnel",
ProducesMediaTypes: []string{"application/zrok.v1+json"},
ConsumesMediaTypes: []string{"application/zrok.v1+json"},
Schemes: []string{"http"},
Params: params,
Reader: &UntunnelReader{formats: a.formats},
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.(*UntunnelOK)
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 untunnel: 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 // SetTransport changes the transport on the client
func (a *Client) SetTransport(transport runtime.ClientTransport) { func (a *Client) SetTransport(transport runtime.ClientTransport) {
a.transport = transport a.transport = transport

View File

@ -0,0 +1,148 @@
// Code generated by go-swagger; DO NOT EDIT.
package tunnel
// 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"
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
)
// NewUntunnelParams creates a new UntunnelParams 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 NewUntunnelParams() *UntunnelParams {
return &UntunnelParams{
timeout: cr.DefaultTimeout,
}
}
// NewUntunnelParamsWithTimeout creates a new UntunnelParams object
// with the ability to set a timeout on a request.
func NewUntunnelParamsWithTimeout(timeout time.Duration) *UntunnelParams {
return &UntunnelParams{
timeout: timeout,
}
}
// NewUntunnelParamsWithContext creates a new UntunnelParams object
// with the ability to set a context for a request.
func NewUntunnelParamsWithContext(ctx context.Context) *UntunnelParams {
return &UntunnelParams{
Context: ctx,
}
}
// NewUntunnelParamsWithHTTPClient creates a new UntunnelParams object
// with the ability to set a custom HTTPClient for a request.
func NewUntunnelParamsWithHTTPClient(client *http.Client) *UntunnelParams {
return &UntunnelParams{
HTTPClient: client,
}
}
/* UntunnelParams contains all the parameters to send to the API endpoint
for the untunnel operation.
Typically these are written to a http.Request.
*/
type UntunnelParams struct {
// Body.
Body *rest_model_zrok.UntunnelRequest
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithDefaults hydrates default values in the untunnel params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *UntunnelParams) WithDefaults() *UntunnelParams {
o.SetDefaults()
return o
}
// SetDefaults hydrates default values in the untunnel params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *UntunnelParams) SetDefaults() {
// no default values defined for this parameter
}
// WithTimeout adds the timeout to the untunnel params
func (o *UntunnelParams) WithTimeout(timeout time.Duration) *UntunnelParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the untunnel params
func (o *UntunnelParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the untunnel params
func (o *UntunnelParams) WithContext(ctx context.Context) *UntunnelParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the untunnel params
func (o *UntunnelParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the untunnel params
func (o *UntunnelParams) WithHTTPClient(client *http.Client) *UntunnelParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the untunnel params
func (o *UntunnelParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithBody adds the body to the untunnel params
func (o *UntunnelParams) WithBody(body *rest_model_zrok.UntunnelRequest) *UntunnelParams {
o.SetBody(body)
return o
}
// SetBody adds the body to the untunnel params
func (o *UntunnelParams) SetBody(body *rest_model_zrok.UntunnelRequest) {
o.Body = body
}
// WriteToRequest writes these params to a swagger request
func (o *UntunnelParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if o.Body != nil {
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,80 @@
// Code generated by go-swagger; DO NOT EDIT.
package tunnel
// 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"
"github.com/go-openapi/strfmt"
)
// UntunnelReader is a Reader for the Untunnel structure.
type UntunnelReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *UntunnelReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewUntunnelOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
case 500:
result := NewUntunnelInternalServerError()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
default:
return nil, runtime.NewAPIError("response status code does not match any response statuses defined for this endpoint in the swagger spec", response, response.Code())
}
}
// NewUntunnelOK creates a UntunnelOK with default headers values
func NewUntunnelOK() *UntunnelOK {
return &UntunnelOK{}
}
/* UntunnelOK describes a response with status code 200, with default header values.
tunnel removed
*/
type UntunnelOK struct {
}
func (o *UntunnelOK) Error() string {
return fmt.Sprintf("[DELETE /untunnel][%d] untunnelOK ", 200)
}
func (o *UntunnelOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
return nil
}
// NewUntunnelInternalServerError creates a UntunnelInternalServerError with default headers values
func NewUntunnelInternalServerError() *UntunnelInternalServerError {
return &UntunnelInternalServerError{}
}
/* UntunnelInternalServerError describes a response with status code 500, with default header values.
internal server error
*/
type UntunnelInternalServerError struct {
}
func (o *UntunnelInternalServerError) Error() string {
return fmt.Sprintf("[DELETE /untunnel][%d] untunnelInternalServerError ", 500)
}
func (o *UntunnelInternalServerError) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
return nil
}

View File

@ -0,0 +1,50 @@
// Code generated by go-swagger; DO NOT EDIT.
package rest_model_zrok
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// UntunnelRequest untunnel request
//
// swagger:model untunnelRequest
type UntunnelRequest struct {
// service
Service string `json:"service,omitempty"`
}
// Validate validates this untunnel request
func (m *UntunnelRequest) Validate(formats strfmt.Registry) error {
return nil
}
// ContextValidate validates this untunnel request based on context it is used
func (m *UntunnelRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *UntunnelRequest) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *UntunnelRequest) UnmarshalBinary(b []byte) error {
var res UntunnelRequest
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@ -121,6 +121,31 @@ func init() {
} }
} }
}, },
"/untunnel": {
"delete": {
"tags": [
"tunnel"
],
"operationId": "untunnel",
"parameters": [
{
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/untunnelRequest"
}
}
],
"responses": {
"200": {
"description": "tunnel removed"
},
"500": {
"description": "internal server error"
}
}
}
},
"/version": { "/version": {
"get": { "get": {
"tags": [ "tags": [
@ -196,6 +221,14 @@ func init() {
} }
} }
}, },
"untunnelRequest": {
"type": "object",
"properties": {
"service": {
"type": "string"
}
}
},
"version": { "version": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -310,6 +343,31 @@ func init() {
} }
} }
}, },
"/untunnel": {
"delete": {
"tags": [
"tunnel"
],
"operationId": "untunnel",
"parameters": [
{
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/untunnelRequest"
}
}
],
"responses": {
"200": {
"description": "tunnel removed"
},
"500": {
"description": "internal server error"
}
}
}
},
"/version": { "/version": {
"get": { "get": {
"tags": [ "tags": [
@ -385,6 +443,14 @@ func init() {
} }
} }
}, },
"untunnelRequest": {
"type": "object",
"properties": {
"service": {
"type": "string"
}
}
},
"version": { "version": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@ -0,0 +1,56 @@
// Code generated by go-swagger; DO NOT EDIT.
package tunnel
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the generate command
import (
"net/http"
"github.com/go-openapi/runtime/middleware"
)
// UntunnelHandlerFunc turns a function with the right signature into a untunnel handler
type UntunnelHandlerFunc func(UntunnelParams) middleware.Responder
// Handle executing the request and returning a response
func (fn UntunnelHandlerFunc) Handle(params UntunnelParams) middleware.Responder {
return fn(params)
}
// UntunnelHandler interface for that can handle valid untunnel params
type UntunnelHandler interface {
Handle(UntunnelParams) middleware.Responder
}
// NewUntunnel creates a new http.Handler for the untunnel operation
func NewUntunnel(ctx *middleware.Context, handler UntunnelHandler) *Untunnel {
return &Untunnel{Context: ctx, Handler: handler}
}
/* Untunnel swagger:route DELETE /untunnel tunnel untunnel
Untunnel untunnel API
*/
type Untunnel struct {
Context *middleware.Context
Handler UntunnelHandler
}
func (o *Untunnel) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, rCtx, _ := o.Context.RouteInfo(r)
if rCtx != nil {
*r = *rCtx
}
var Params = NewUntunnelParams()
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
o.Context.Respond(rw, r, route.Produces, route, err)
return
}
res := o.Handler.Handle(Params) // actually handle the request
o.Context.Respond(rw, r, route.Produces, route, res)
}

View File

@ -0,0 +1,77 @@
// Code generated by go-swagger; DO NOT EDIT.
package tunnel
// 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"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/validate"
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
)
// NewUntunnelParams creates a new UntunnelParams object
//
// There are no default values defined in the spec.
func NewUntunnelParams() UntunnelParams {
return UntunnelParams{}
}
// UntunnelParams contains all the bound params for the untunnel operation
// typically these are obtained from a http.Request
//
// swagger:parameters untunnel
type UntunnelParams struct {
// HTTP Request Object
HTTPRequest *http.Request `json:"-"`
/*
In: body
*/
Body *rest_model_zrok.UntunnelRequest
}
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
// for simple values it will use straight method calls.
//
// To ensure default values, the struct must have been initialized with NewUntunnelParams() beforehand.
func (o *UntunnelParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
var res []error
o.HTTPRequest = r
if runtime.HasBody(r) {
defer r.Body.Close()
var body rest_model_zrok.UntunnelRequest
if err := route.Consumer.Consume(r.Body, &body); err != nil {
res = append(res, errors.NewParseError("body", "body", "", err))
} else {
// validate body object
if err := body.Validate(route.Formats); err != nil {
res = append(res, err)
}
ctx := validate.WithOperationRequest(context.Background())
if err := body.ContextValidate(ctx, route.Formats); err != nil {
res = append(res, err)
}
if len(res) == 0 {
o.Body = &body
}
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@ -0,0 +1,60 @@
// Code generated by go-swagger; DO NOT EDIT.
package tunnel
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"net/http"
"github.com/go-openapi/runtime"
)
// UntunnelOKCode is the HTTP code returned for type UntunnelOK
const UntunnelOKCode int = 200
/*UntunnelOK tunnel removed
swagger:response untunnelOK
*/
type UntunnelOK struct {
}
// NewUntunnelOK creates UntunnelOK with default headers values
func NewUntunnelOK() *UntunnelOK {
return &UntunnelOK{}
}
// WriteResponse to the client
func (o *UntunnelOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
rw.WriteHeader(200)
}
// UntunnelInternalServerErrorCode is the HTTP code returned for type UntunnelInternalServerError
const UntunnelInternalServerErrorCode int = 500
/*UntunnelInternalServerError internal server error
swagger:response untunnelInternalServerError
*/
type UntunnelInternalServerError struct {
}
// NewUntunnelInternalServerError creates UntunnelInternalServerError with default headers values
func NewUntunnelInternalServerError() *UntunnelInternalServerError {
return &UntunnelInternalServerError{}
}
// WriteResponse to the client
func (o *UntunnelInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
rw.WriteHeader(500)
}

View File

@ -0,0 +1,84 @@
// Code generated by go-swagger; DO NOT EDIT.
package tunnel
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the generate command
import (
"errors"
"net/url"
golangswaggerpaths "path"
)
// UntunnelURL generates an URL for the untunnel operation
type UntunnelURL struct {
_basePath string
}
// WithBasePath sets the base path for this url builder, only required when it's different from the
// base path specified in the swagger spec.
// When the value of the base path is an empty string
func (o *UntunnelURL) WithBasePath(bp string) *UntunnelURL {
o.SetBasePath(bp)
return o
}
// SetBasePath sets the base path for this url builder, only required when it's different from the
// base path specified in the swagger spec.
// When the value of the base path is an empty string
func (o *UntunnelURL) SetBasePath(bp string) {
o._basePath = bp
}
// Build a url path and query string
func (o *UntunnelURL) Build() (*url.URL, error) {
var _result url.URL
var _path = "/untunnel"
_basePath := o._basePath
_result.Path = golangswaggerpaths.Join(_basePath, _path)
return &_result, nil
}
// Must is a helper function to panic when the url builder returns an error
func (o *UntunnelURL) Must(u *url.URL, err error) *url.URL {
if err != nil {
panic(err)
}
if u == nil {
panic("url can't be nil")
}
return u
}
// String returns the string representation of the path with query string
func (o *UntunnelURL) String() string {
return o.Must(o.Build()).String()
}
// BuildFull builds a full url with scheme, host, path and query string
func (o *UntunnelURL) BuildFull(scheme, host string) (*url.URL, error) {
if scheme == "" {
return nil, errors.New("scheme is required for a full url on UntunnelURL")
}
if host == "" {
return nil, errors.New("host is required for a full url on UntunnelURL")
}
base, err := o.Build()
if err != nil {
return nil, err
}
base.Scheme = scheme
base.Host = host
return base, nil
}
// StringFull returns the string representation of a complete url
func (o *UntunnelURL) StringFull(scheme, host string) string {
return o.Must(o.BuildFull(scheme, host)).String()
}

View File

@ -55,6 +55,9 @@ func NewZrokAPI(spec *loads.Document) *ZrokAPI {
TunnelTunnelHandler: tunnel.TunnelHandlerFunc(func(params tunnel.TunnelParams) middleware.Responder { TunnelTunnelHandler: tunnel.TunnelHandlerFunc(func(params tunnel.TunnelParams) middleware.Responder {
return middleware.NotImplemented("operation tunnel.Tunnel has not yet been implemented") return middleware.NotImplemented("operation tunnel.Tunnel has not yet been implemented")
}), }),
TunnelUntunnelHandler: tunnel.UntunnelHandlerFunc(func(params tunnel.UntunnelParams) middleware.Responder {
return middleware.NotImplemented("operation tunnel.Untunnel has not yet been implemented")
}),
MetadataVersionHandler: metadata.VersionHandlerFunc(func(params metadata.VersionParams) middleware.Responder { MetadataVersionHandler: metadata.VersionHandlerFunc(func(params metadata.VersionParams) middleware.Responder {
return middleware.NotImplemented("operation metadata.Version has not yet been implemented") return middleware.NotImplemented("operation metadata.Version has not yet been implemented")
}), }),
@ -100,6 +103,8 @@ type ZrokAPI struct {
IdentityEnableHandler identity.EnableHandler IdentityEnableHandler identity.EnableHandler
// TunnelTunnelHandler sets the operation handler for the tunnel operation // TunnelTunnelHandler sets the operation handler for the tunnel operation
TunnelTunnelHandler tunnel.TunnelHandler TunnelTunnelHandler tunnel.TunnelHandler
// TunnelUntunnelHandler sets the operation handler for the untunnel operation
TunnelUntunnelHandler tunnel.UntunnelHandler
// MetadataVersionHandler sets the operation handler for the version operation // MetadataVersionHandler sets the operation handler for the version operation
MetadataVersionHandler metadata.VersionHandler MetadataVersionHandler metadata.VersionHandler
@ -188,6 +193,9 @@ func (o *ZrokAPI) Validate() error {
if o.TunnelTunnelHandler == nil { if o.TunnelTunnelHandler == nil {
unregistered = append(unregistered, "tunnel.TunnelHandler") unregistered = append(unregistered, "tunnel.TunnelHandler")
} }
if o.TunnelUntunnelHandler == nil {
unregistered = append(unregistered, "tunnel.UntunnelHandler")
}
if o.MetadataVersionHandler == nil { if o.MetadataVersionHandler == nil {
unregistered = append(unregistered, "metadata.VersionHandler") unregistered = append(unregistered, "metadata.VersionHandler")
} }
@ -291,6 +299,10 @@ func (o *ZrokAPI) initHandlerCache() {
o.handlers["POST"] = make(map[string]http.Handler) o.handlers["POST"] = make(map[string]http.Handler)
} }
o.handlers["POST"]["/tunnel"] = tunnel.NewTunnel(o.context, o.TunnelTunnelHandler) o.handlers["POST"]["/tunnel"] = tunnel.NewTunnel(o.context, o.TunnelTunnelHandler)
if o.handlers["DELETE"] == nil {
o.handlers["DELETE"] = make(map[string]http.Handler)
}
o.handlers["DELETE"]["/untunnel"] = tunnel.NewUntunnel(o.context, o.TunnelUntunnelHandler)
if o.handlers["GET"] == nil { if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler) o.handlers["GET"] = make(map[string]http.Handler)
} }

View File

@ -57,6 +57,21 @@ paths:
description: tunnel created description: tunnel created
schema: schema:
$ref: "#/definitions/tunnelResponse" $ref: "#/definitions/tunnelResponse"
/untunnel:
delete:
tags:
- tunnel
operationId: untunnel
parameters:
- name: body
in: body
schema:
$ref: "#/definitions/untunnelRequest"
responses:
200:
description: tunnel removed
500:
description: internal server error
/version: /version:
get: get:
tags: tags:
@ -110,6 +125,11 @@ definitions:
properties: properties:
service: service:
type: string type: string
untunnelRequest:
type: object
properties:
service:
type: string
produces: produces:
- application/zrok.v1+json - application/zrok.v1+json