enable endpoint refactoring (#834)

This commit is contained in:
Michael Quigley 2025-02-03 16:29:27 -05:00
parent fc45d4b690
commit 9f63b911ed
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
19 changed files with 379 additions and 123 deletions

View File

@ -8,7 +8,6 @@ import (
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/environment/env_core"
restEnvironment "github.com/openziti/zrok/rest_client_zrok/environment"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/tui"
"github.com/shirou/gopsutil/v3/host"
"github.com/sirupsen/logrus"
@ -77,10 +76,8 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
}
auth := httptransport.APIKeyAuth("X-TOKEN", "header", token)
req := restEnvironment.NewEnableParams()
req.Body = &rest_model_zrok.EnableRequest{
Description: cmd.description,
Host: hostDetail,
}
req.Body.Description = cmd.description
req.Body.Host = hostDetail
var prg *tea.Program
var done = make(chan struct{})

View File

@ -81,9 +81,7 @@ func (h *enableHandler) Handle(params environment.EnableParams, principal *rest_
}
logrus.Infof("created environment for '%v', with ziti identity '%v', and database id '%v'", principal.Email, ident.Payload.Data.ID, envId)
resp := environment.NewEnableCreated().WithPayload(&rest_model_zrok.EnableResponse{
Identity: envZId,
})
resp := environment.NewEnableCreated().WithPayload(&environment.EnableCreatedBody{Identity: envZId})
var out bytes.Buffer
enc := json.NewEncoder(&out)

View File

@ -14,8 +14,6 @@ import (
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
"github.com/openziti/zrok/rest_model_zrok"
)
// NewEnableParams creates a new EnableParams object,
@ -64,7 +62,7 @@ EnableParams contains all the parameters to send to the API endpoint
type EnableParams struct {
// Body.
Body *rest_model_zrok.EnableRequest
Body EnableBody
timeout time.Duration
Context context.Context
@ -120,13 +118,13 @@ func (o *EnableParams) SetHTTPClient(client *http.Client) {
}
// WithBody adds the body to the enable params
func (o *EnableParams) WithBody(body *rest_model_zrok.EnableRequest) *EnableParams {
func (o *EnableParams) WithBody(body EnableBody) *EnableParams {
o.SetBody(body)
return o
}
// SetBody adds the body to the enable params
func (o *EnableParams) SetBody(body *rest_model_zrok.EnableRequest) {
func (o *EnableParams) SetBody(body EnableBody) {
o.Body = body
}
@ -137,11 +135,9 @@ func (o *EnableParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Regist
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...)

View File

@ -6,13 +6,13 @@ package environment
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"fmt"
"io"
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/go-openapi/swag"
)
// EnableReader is a Reader for the Enable structure.
@ -63,7 +63,7 @@ EnableCreated describes a response with status code 201, with default header val
environment enabled
*/
type EnableCreated struct {
Payload *rest_model_zrok.EnableResponse
Payload *EnableCreatedBody
}
// IsSuccess returns true when this enable created response has a 2xx status code
@ -104,13 +104,13 @@ func (o *EnableCreated) String() string {
return fmt.Sprintf("[POST /enable][%d] enableCreated %+v", 201, o.Payload)
}
func (o *EnableCreated) GetPayload() *rest_model_zrok.EnableResponse {
func (o *EnableCreated) GetPayload() *EnableCreatedBody {
return o.Payload
}
func (o *EnableCreated) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(rest_model_zrok.EnableResponse)
o.Payload = new(EnableCreatedBody)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
@ -287,3 +287,85 @@ func (o *EnableInternalServerError) readResponse(response runtime.ClientResponse
return nil
}
/*
EnableBody enable body
swagger:model EnableBody
*/
type EnableBody struct {
// description
Description string `json:"description,omitempty"`
// host
Host string `json:"host,omitempty"`
}
// Validate validates this enable body
func (o *EnableBody) Validate(formats strfmt.Registry) error {
return nil
}
// ContextValidate validates this enable body based on context it is used
func (o *EnableBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (o *EnableBody) MarshalBinary() ([]byte, error) {
if o == nil {
return nil, nil
}
return swag.WriteJSON(o)
}
// UnmarshalBinary interface implementation
func (o *EnableBody) UnmarshalBinary(b []byte) error {
var res EnableBody
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*o = res
return nil
}
/*
EnableCreatedBody enable created body
swagger:model EnableCreatedBody
*/
type EnableCreatedBody struct {
// cfg
Cfg string `json:"cfg,omitempty"`
// identity
Identity string `json:"identity,omitempty"`
}
// Validate validates this enable created body
func (o *EnableCreatedBody) Validate(formats strfmt.Registry) error {
return nil
}
// ContextValidate validates this enable created body based on context it is used
func (o *EnableCreatedBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (o *EnableCreatedBody) MarshalBinary() ([]byte, error) {
if o == nil {
return nil, nil
}
return swag.WriteJSON(o)
}
// UnmarshalBinary interface implementation
func (o *EnableCreatedBody) UnmarshalBinary(b []byte) error {
var res EnableCreatedBody
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*o = res
return nil
}

View File

@ -376,7 +376,14 @@ func init() {
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/enableRequest"
"properties": {
"description": {
"type": "string"
},
"host": {
"type": "string"
}
}
}
}
],
@ -384,7 +391,14 @@ func init() {
"201": {
"description": "environment enabled",
"schema": {
"$ref": "#/definitions/enableResponse"
"properties": {
"cfg": {
"type": "string"
},
"identity": {
"type": "string"
}
}
}
},
"401": {
@ -1856,28 +1870,6 @@ func init() {
}
}
},
"enableRequest": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"host": {
"type": "string"
}
}
},
"enableResponse": {
"type": "object",
"properties": {
"cfg": {
"type": "string"
},
"identity": {
"type": "string"
}
}
},
"environment": {
"type": "object",
"properties": {
@ -2628,7 +2620,14 @@ func init() {
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/enableRequest"
"properties": {
"description": {
"type": "string"
},
"host": {
"type": "string"
}
}
}
}
],
@ -2636,7 +2635,14 @@ func init() {
"201": {
"description": "environment enabled",
"schema": {
"$ref": "#/definitions/enableResponse"
"properties": {
"cfg": {
"type": "string"
},
"identity": {
"type": "string"
}
}
}
},
"401": {
@ -4113,28 +4119,6 @@ func init() {
}
}
},
"enableRequest": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"host": {
"type": "string"
}
}
},
"enableResponse": {
"type": "object",
"properties": {
"cfg": {
"type": "string"
},
"identity": {
"type": "string"
}
}
},
"environment": {
"type": "object",
"properties": {

View File

@ -6,9 +6,12 @@ package environment
// Editing this file might prove futile when you re-run the generate command
import (
"context"
"net/http"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/openziti/zrok/rest_model_zrok"
)
@ -69,3 +72,83 @@ func (o *Enable) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
o.Context.Respond(rw, r, route.Produces, route, res)
}
// EnableBody enable body
//
// swagger:model EnableBody
type EnableBody struct {
// description
Description string `json:"description,omitempty"`
// host
Host string `json:"host,omitempty"`
}
// Validate validates this enable body
func (o *EnableBody) Validate(formats strfmt.Registry) error {
return nil
}
// ContextValidate validates this enable body based on context it is used
func (o *EnableBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (o *EnableBody) MarshalBinary() ([]byte, error) {
if o == nil {
return nil, nil
}
return swag.WriteJSON(o)
}
// UnmarshalBinary interface implementation
func (o *EnableBody) UnmarshalBinary(b []byte) error {
var res EnableBody
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*o = res
return nil
}
// EnableCreatedBody enable created body
//
// swagger:model EnableCreatedBody
type EnableCreatedBody struct {
// cfg
Cfg string `json:"cfg,omitempty"`
// identity
Identity string `json:"identity,omitempty"`
}
// Validate validates this enable created body
func (o *EnableCreatedBody) Validate(formats strfmt.Registry) error {
return nil
}
// ContextValidate validates this enable created body based on context it is used
func (o *EnableCreatedBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (o *EnableCreatedBody) MarshalBinary() ([]byte, error) {
if o == nil {
return nil, nil
}
return swag.WriteJSON(o)
}
// UnmarshalBinary interface implementation
func (o *EnableCreatedBody) UnmarshalBinary(b []byte) error {
var res EnableCreatedBody
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*o = res
return nil
}

View File

@ -12,8 +12,6 @@ import (
"github.com/go-openapi/runtime"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/validate"
"github.com/openziti/zrok/rest_model_zrok"
)
// NewEnableParams creates a new EnableParams object
@ -36,7 +34,7 @@ type EnableParams struct {
/*
In: body
*/
Body *rest_model_zrok.EnableRequest
Body EnableBody
}
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
@ -50,7 +48,7 @@ func (o *EnableParams) BindRequest(r *http.Request, route *middleware.MatchedRou
if runtime.HasBody(r) {
defer r.Body.Close()
var body rest_model_zrok.EnableRequest
var body EnableBody
if err := route.Consumer.Consume(r.Body, &body); err != nil {
res = append(res, errors.NewParseError("body", "body", "", err))
} else {
@ -65,7 +63,7 @@ func (o *EnableParams) BindRequest(r *http.Request, route *middleware.MatchedRou
}
if len(res) == 0 {
o.Body = &body
o.Body = body
}
}
}

View File

@ -9,8 +9,6 @@ import (
"net/http"
"github.com/go-openapi/runtime"
"github.com/openziti/zrok/rest_model_zrok"
)
// EnableCreatedCode is the HTTP code returned for type EnableCreated
@ -26,7 +24,7 @@ type EnableCreated struct {
/*
In: Body
*/
Payload *rest_model_zrok.EnableResponse `json:"body,omitempty"`
Payload *EnableCreatedBody `json:"body,omitempty"`
}
// NewEnableCreated creates EnableCreated with default headers values
@ -36,13 +34,13 @@ func NewEnableCreated() *EnableCreated {
}
// WithPayload adds the payload to the enable created response
func (o *EnableCreated) WithPayload(payload *rest_model_zrok.EnableResponse) *EnableCreated {
func (o *EnableCreated) WithPayload(payload *EnableCreatedBody) *EnableCreated {
o.Payload = payload
return o
}
// SetPayload sets the payload to the enable created response
func (o *EnableCreated) SetPayload(payload *rest_model_zrok.EnableResponse) {
func (o *EnableCreated) SetPayload(payload *EnableCreatedBody) {
o.Payload = payload
}

View File

@ -19,7 +19,6 @@ model/createOrganizationRequest.ts
model/deleteFrontendRequest.ts
model/disableRequest.ts
model/enableRequest.ts
model/enableResponse.ts
model/environment.ts
model/environmentAndResources.ts
model/frontend.ts

View File

@ -15,9 +15,9 @@ import localVarRequest from 'request';
import http from 'http';
/* tslint:disable:no-unused-locals */
import { CreateIdentity201Response } from '../model/createIdentity201Response';
import { DisableRequest } from '../model/disableRequest';
import { EnableRequest } from '../model/enableRequest';
import { EnableResponse } from '../model/enableResponse';
import { ObjectSerializer, Authentication, VoidAuth, Interceptor } from '../model/models';
import { HttpBasicAuth, HttpBearerAuth, ApiKeyAuth, OAuth } from '../model/models';
@ -153,7 +153,7 @@ export class EnvironmentApi {
*
* @param body
*/
public async enable (body?: EnableRequest, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: EnableResponse; }> {
public async enable (body?: EnableRequest, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: CreateIdentity201Response; }> {
const localVarPath = this.basePath + '/enable';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
@ -199,13 +199,13 @@ export class EnvironmentApi {
localVarRequestOptions.form = localVarFormParams;
}
}
return new Promise<{ response: http.IncomingMessage; body: EnableResponse; }>((resolve, reject) => {
return new Promise<{ response: http.IncomingMessage; body: CreateIdentity201Response; }>((resolve, reject) => {
localVarRequest(localVarRequestOptions, (error, response, body) => {
if (error) {
reject(error);
} else {
if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) {
body = ObjectSerializer.deserialize(body, "EnableResponse");
body = ObjectSerializer.deserialize(body, "CreateIdentity201Response");
resolve({ response: response, body: body });
} else {
reject(new HttpError(response, body, response.statusCode));

View File

@ -13,7 +13,6 @@ export * from './createOrganizationRequest';
export * from './deleteFrontendRequest';
export * from './disableRequest';
export * from './enableRequest';
export * from './enableResponse';
export * from './environment';
export * from './environmentAndResources';
export * from './frontend';
@ -74,7 +73,6 @@ import { CreateOrganizationRequest } from './createOrganizationRequest';
import { DeleteFrontendRequest } from './deleteFrontendRequest';
import { DisableRequest } from './disableRequest';
import { EnableRequest } from './enableRequest';
import { EnableResponse } from './enableResponse';
import { Environment } from './environment';
import { EnvironmentAndResources } from './environmentAndResources';
import { Frontend } from './frontend';
@ -143,7 +141,6 @@ let typeMap: {[index: string]: any} = {
"DeleteFrontendRequest": DeleteFrontendRequest,
"DisableRequest": DisableRequest,
"EnableRequest": EnableRequest,
"EnableResponse": EnableResponse,
"Environment": Environment,
"EnvironmentAndResources": EnvironmentAndResources,
"Frontend": Frontend,

View File

@ -31,8 +31,7 @@ from zrok_api.models.auth_user import AuthUser
from zrok_api.models.change_password_body import ChangePasswordBody
from zrok_api.models.configuration import Configuration
from zrok_api.models.disable_request import DisableRequest
from zrok_api.models.enable_request import EnableRequest
from zrok_api.models.enable_response import EnableResponse
from zrok_api.models.enable_body import EnableBody
from zrok_api.models.environment import Environment
from zrok_api.models.environment_and_resources import EnvironmentAndResources
from zrok_api.models.environments import Environments

View File

@ -130,8 +130,8 @@ class EnvironmentApi(object):
>>> result = thread.get()
:param async_req bool
:param EnableRequest body:
:return: EnableResponse
:param EnableBody body:
:return: InlineResponse201
If the method is called asynchronously,
returns the request thread.
"""
@ -151,8 +151,8 @@ class EnvironmentApi(object):
>>> result = thread.get()
:param async_req bool
:param EnableRequest body:
:return: EnableResponse
:param EnableBody body:
:return: InlineResponse201
If the method is called asynchronously,
returns the request thread.
"""
@ -206,7 +206,7 @@ class EnvironmentApi(object):
body=body_params,
post_params=form_params,
files=local_var_files,
response_type='EnableResponse', # noqa: E501
response_type='InlineResponse201', # noqa: E501
auth_settings=auth_settings,
async_req=params.get('async_req'),
_return_http_data_only=params.get('_return_http_data_only'),

View File

@ -21,8 +21,7 @@ from zrok_api.models.auth_user import AuthUser
from zrok_api.models.change_password_body import ChangePasswordBody
from zrok_api.models.configuration import Configuration
from zrok_api.models.disable_request import DisableRequest
from zrok_api.models.enable_request import EnableRequest
from zrok_api.models.enable_response import EnableResponse
from zrok_api.models.enable_body import EnableBody
from zrok_api.models.environment import Environment
from zrok_api.models.environment_and_resources import EnvironmentAndResources
from zrok_api.models.environments import Environments

View File

@ -0,0 +1,136 @@
# coding: utf-8
"""
zrok
zrok client access # noqa: E501
OpenAPI spec version: 1.0.0
Generated by: https://github.com/swagger-api/swagger-codegen.git
"""
import pprint
import re # noqa: F401
import six
class EnableBody(object):
"""NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""
"""
Attributes:
swagger_types (dict): The key is attribute name
and the value is attribute type.
attribute_map (dict): The key is attribute name
and the value is json key in definition.
"""
swagger_types = {
'description': 'str',
'host': 'str'
}
attribute_map = {
'description': 'description',
'host': 'host'
}
def __init__(self, description=None, host=None): # noqa: E501
"""EnableBody - a model defined in Swagger""" # noqa: E501
self._description = None
self._host = None
self.discriminator = None
if description is not None:
self.description = description
if host is not None:
self.host = host
@property
def description(self):
"""Gets the description of this EnableBody. # noqa: E501
:return: The description of this EnableBody. # noqa: E501
:rtype: str
"""
return self._description
@description.setter
def description(self, description):
"""Sets the description of this EnableBody.
:param description: The description of this EnableBody. # noqa: E501
:type: str
"""
self._description = description
@property
def host(self):
"""Gets the host of this EnableBody. # noqa: E501
:return: The host of this EnableBody. # noqa: E501
:rtype: str
"""
return self._host
@host.setter
def host(self, host):
"""Sets the host of this EnableBody.
:param host: The host of this EnableBody. # noqa: E501
:type: str
"""
self._host = host
def to_dict(self):
"""Returns the model properties as a dict"""
result = {}
for attr, _ in six.iteritems(self.swagger_types):
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0], item[1].to_dict())
if hasattr(item[1], "to_dict") else item,
value.items()
))
else:
result[attr] = value
if issubclass(EnableBody, dict):
for key, value in self.items():
result[key] = value
return result
def to_str(self):
"""Returns the string representation of the model"""
return pprint.pformat(self.to_dict())
def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()
def __eq__(self, other):
"""Returns true if both objects are equal"""
if not isinstance(other, EnableBody):
return False
return self.__dict__ == other.__dict__
def __ne__(self, other):
"""Returns true if both objects are not equal"""
return not self == other

View File

@ -627,12 +627,20 @@ paths:
- name: body
in: body
schema:
$ref: "#/definitions/enableRequest"
properties:
description:
type: string
host:
type: string
responses:
201:
description: environment enabled
schema:
$ref: "#/definitions/enableResponse"
properties:
identity:
type: string
cfg:
type: string
401:
description: unauthorized
404:
@ -1154,22 +1162,6 @@ definitions:
identity:
type: string
enableRequest:
type: object
properties:
description:
type: string
host:
type: string
enableResponse:
type: object
properties:
identity:
type: string
cfg:
type: string
environment:
type: object
properties:

View File

@ -17,7 +17,6 @@ models/CreateOrganizationRequest.ts
models/DeleteFrontendRequest.ts
models/DisableRequest.ts
models/EnableRequest.ts
models/EnableResponse.ts
models/Environment.ts
models/EnvironmentAndResources.ts
models/Frontend.ts

View File

@ -15,17 +15,17 @@
import * as runtime from '../runtime';
import type {
CreateIdentity201Response,
DisableRequest,
EnableRequest,
EnableResponse,
} from '../models/index';
import {
CreateIdentity201ResponseFromJSON,
CreateIdentity201ResponseToJSON,
DisableRequestFromJSON,
DisableRequestToJSON,
EnableRequestFromJSON,
EnableRequestToJSON,
EnableResponseFromJSON,
EnableResponseToJSON,
} from '../models/index';
export interface DisableOperationRequest {
@ -73,7 +73,7 @@ export class EnvironmentApi extends runtime.BaseAPI {
/**
*/
async enableRaw(requestParameters: EnableOperationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<EnableResponse>> {
async enableRaw(requestParameters: EnableOperationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<CreateIdentity201Response>> {
const queryParameters: any = {};
const headerParameters: runtime.HTTPHeaders = {};
@ -92,12 +92,12 @@ export class EnvironmentApi extends runtime.BaseAPI {
body: EnableRequestToJSON(requestParameters['body']),
}, initOverrides);
return new runtime.JSONApiResponse(response, (jsonValue) => EnableResponseFromJSON(jsonValue));
return new runtime.JSONApiResponse(response, (jsonValue) => CreateIdentity201ResponseFromJSON(jsonValue));
}
/**
*/
async enable(requestParameters: EnableOperationRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<EnableResponse> {
async enable(requestParameters: EnableOperationRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<CreateIdentity201Response> {
const response = await this.enableRaw(requestParameters, initOverrides);
return await response.value();
}

View File

@ -12,7 +12,6 @@ export * from './CreateOrganizationRequest';
export * from './DeleteFrontendRequest';
export * from './DisableRequest';
export * from './EnableRequest';
export * from './EnableResponse';
export * from './Environment';
export * from './EnvironmentAndResources';
export * from './Frontend';