invite token generate lint (#834)

This commit is contained in:
Michael Quigley 2025-02-03 13:20:49 -05:00
parent 62d8086aed
commit 9c77fba98a
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
12 changed files with 226 additions and 56 deletions

View File

@ -5,7 +5,6 @@ import (
"github.com/jaevor/go-nanoid"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@ -54,9 +53,8 @@ func (cmd *adminGenerateCommand) run(_ *cobra.Command, args []string) {
panic(err)
}
req := admin.NewInviteTokenGenerateParams()
req.Body = &rest_model_zrok.InviteTokenGenerateRequest{
Tokens: tokens,
}
req.Body.Tokens = tokens
_, err = zrok.Admin.InviteTokenGenerate(req, mustGetAdminAuth())
if err != nil {
if !panicInstead {

View File

@ -22,7 +22,7 @@ func (handler *inviteTokenGenerateHandler) Handle(params admin.InviteTokenGenera
return admin.NewInviteTokenGenerateUnauthorized()
}
if params.Body == nil || len(params.Body.Tokens) == 0 {
if len(params.Body.Tokens) == 0 {
logrus.Error("missing tokens")
return admin.NewInviteTokenGenerateBadRequest()
}

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"
)
// NewInviteTokenGenerateParams creates a new InviteTokenGenerateParams object,
@ -64,7 +62,7 @@ InviteTokenGenerateParams contains all the parameters to send to the API endpoin
type InviteTokenGenerateParams struct {
// Body.
Body *rest_model_zrok.InviteTokenGenerateRequest
Body InviteTokenGenerateBody
timeout time.Duration
Context context.Context
@ -120,13 +118,13 @@ func (o *InviteTokenGenerateParams) SetHTTPClient(client *http.Client) {
}
// WithBody adds the body to the invite token generate params
func (o *InviteTokenGenerateParams) WithBody(body *rest_model_zrok.InviteTokenGenerateRequest) *InviteTokenGenerateParams {
func (o *InviteTokenGenerateParams) WithBody(body InviteTokenGenerateBody) *InviteTokenGenerateParams {
o.SetBody(body)
return o
}
// SetBody adds the body to the invite token generate params
func (o *InviteTokenGenerateParams) SetBody(body *rest_model_zrok.InviteTokenGenerateRequest) {
func (o *InviteTokenGenerateParams) SetBody(body InviteTokenGenerateBody) {
o.Body = body
}
@ -137,11 +135,9 @@ func (o *InviteTokenGenerateParams) WriteToRequest(r runtime.ClientRequest, reg
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,10 +6,12 @@ package admin
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"fmt"
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// InviteTokenGenerateReader is a Reader for the InviteTokenGenerate structure.
@ -272,3 +274,41 @@ func (o *InviteTokenGenerateInternalServerError) readResponse(response runtime.C
return nil
}
/*
InviteTokenGenerateBody invite token generate body
swagger:model InviteTokenGenerateBody
*/
type InviteTokenGenerateBody struct {
// tokens
Tokens []string `json:"tokens"`
}
// Validate validates this invite token generate body
func (o *InviteTokenGenerateBody) Validate(formats strfmt.Registry) error {
return nil
}
// ContextValidate validates this invite token generate body based on context it is used
func (o *InviteTokenGenerateBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (o *InviteTokenGenerateBody) MarshalBinary() ([]byte, error) {
if o == nil {
return nil, nil
}
return swag.WriteJSON(o)
}
// UnmarshalBinary interface implementation
func (o *InviteTokenGenerateBody) UnmarshalBinary(b []byte) error {
var res InviteTokenGenerateBody
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*o = res
return nil
}

View File

@ -742,7 +742,14 @@ func init() {
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/inviteTokenGenerateRequest"
"properties": {
"tokens": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
],
@ -1952,17 +1959,6 @@ func init() {
"$ref": "#/definitions/frontend"
}
},
"inviteTokenGenerateRequest": {
"type": "object",
"properties": {
"tokens": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"metrics": {
"type": "object",
"properties": {
@ -2978,7 +2974,14 @@ func init() {
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/inviteTokenGenerateRequest"
"properties": {
"tokens": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
],
@ -4213,17 +4216,6 @@ func init() {
"$ref": "#/definitions/frontend"
}
},
"inviteTokenGenerateRequest": {
"type": "object",
"properties": {
"tokens": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"metrics": {
"type": "object",
"properties": {

View File

@ -6,9 +6,12 @@ package admin
// 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,40 @@ func (o *InviteTokenGenerate) ServeHTTP(rw http.ResponseWriter, r *http.Request)
o.Context.Respond(rw, r, route.Produces, route, res)
}
// InviteTokenGenerateBody invite token generate body
//
// swagger:model InviteTokenGenerateBody
type InviteTokenGenerateBody struct {
// tokens
Tokens []string `json:"tokens"`
}
// Validate validates this invite token generate body
func (o *InviteTokenGenerateBody) Validate(formats strfmt.Registry) error {
return nil
}
// ContextValidate validates this invite token generate body based on context it is used
func (o *InviteTokenGenerateBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (o *InviteTokenGenerateBody) MarshalBinary() ([]byte, error) {
if o == nil {
return nil, nil
}
return swag.WriteJSON(o)
}
// UnmarshalBinary interface implementation
func (o *InviteTokenGenerateBody) UnmarshalBinary(b []byte) error {
var res InviteTokenGenerateBody
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"
)
// NewInviteTokenGenerateParams creates a new InviteTokenGenerateParams object
@ -36,7 +34,7 @@ type InviteTokenGenerateParams struct {
/*
In: body
*/
Body *rest_model_zrok.InviteTokenGenerateRequest
Body InviteTokenGenerateBody
}
// 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 *InviteTokenGenerateParams) BindRequest(r *http.Request, route *middlewa
if runtime.HasBody(r) {
defer r.Body.Close()
var body rest_model_zrok.InviteTokenGenerateRequest
var body InviteTokenGenerateBody
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 *InviteTokenGenerateParams) BindRequest(r *http.Request, route *middlewa
}
if len(res) == 0 {
o.Body = &body
o.Body = body
}
}
}

View File

@ -56,7 +56,6 @@ from zrok_api.models.inline_response2005_memberships import InlineResponse2005Me
from zrok_api.models.inline_response2006 import InlineResponse2006
from zrok_api.models.inline_response201 import InlineResponse201
from zrok_api.models.invite_body import InviteBody
from zrok_api.models.invite_token_generate_request import InviteTokenGenerateRequest
from zrok_api.models.login_body import LoginBody
from zrok_api.models.metrics import Metrics
from zrok_api.models.metrics_sample import MetricsSample
@ -79,6 +78,7 @@ from zrok_api.models.shares import Shares
from zrok_api.models.spark_data import SparkData
from zrok_api.models.spark_data_sample import SparkDataSample
from zrok_api.models.sparklines_body import SparklinesBody
from zrok_api.models.token_generate_body import TokenGenerateBody
from zrok_api.models.unaccess_request import UnaccessRequest
from zrok_api.models.unshare_request import UnshareRequest
from zrok_api.models.update_share_request import UpdateShareRequest

View File

@ -769,7 +769,7 @@ class AdminApi(object):
>>> result = thread.get()
:param async_req bool
:param InviteTokenGenerateRequest body:
:param TokenGenerateBody body:
:return: None
If the method is called asynchronously,
returns the request thread.
@ -790,7 +790,7 @@ class AdminApi(object):
>>> result = thread.get()
:param async_req bool
:param InviteTokenGenerateRequest body:
:param TokenGenerateBody body:
:return: None
If the method is called asynchronously,
returns the request thread.

View File

@ -46,7 +46,6 @@ from zrok_api.models.inline_response2005_memberships import InlineResponse2005Me
from zrok_api.models.inline_response2006 import InlineResponse2006
from zrok_api.models.inline_response201 import InlineResponse201
from zrok_api.models.invite_body import InviteBody
from zrok_api.models.invite_token_generate_request import InviteTokenGenerateRequest
from zrok_api.models.login_body import LoginBody
from zrok_api.models.metrics import Metrics
from zrok_api.models.metrics_sample import MetricsSample
@ -69,6 +68,7 @@ from zrok_api.models.shares import Shares
from zrok_api.models.spark_data import SparkData
from zrok_api.models.spark_data_sample import SparkDataSample
from zrok_api.models.sparklines_body import SparklinesBody
from zrok_api.models.token_generate_body import TokenGenerateBody
from zrok_api.models.unaccess_request import UnaccessRequest
from zrok_api.models.unshare_request import UnshareRequest
from zrok_api.models.update_share_request import UpdateShareRequest

View File

@ -0,0 +1,110 @@
# 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 TokenGenerateBody(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 = {
'tokens': 'list[str]'
}
attribute_map = {
'tokens': 'tokens'
}
def __init__(self, tokens=None): # noqa: E501
"""TokenGenerateBody - a model defined in Swagger""" # noqa: E501
self._tokens = None
self.discriminator = None
if tokens is not None:
self.tokens = tokens
@property
def tokens(self):
"""Gets the tokens of this TokenGenerateBody. # noqa: E501
:return: The tokens of this TokenGenerateBody. # noqa: E501
:rtype: list[str]
"""
return self._tokens
@tokens.setter
def tokens(self, tokens):
"""Sets the tokens of this TokenGenerateBody.
:param tokens: The tokens of this TokenGenerateBody. # noqa: E501
:type: list[str]
"""
self._tokens = tokens
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(TokenGenerateBody, 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, TokenGenerateBody):
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

@ -437,7 +437,11 @@ paths:
- name: body
in: body
schema:
$ref: "#/definitions/inviteTokenGenerateRequest"
properties:
tokens:
type: array
items:
type: string
responses:
201:
description: invitation tokens created
@ -1225,14 +1229,6 @@ definitions:
items:
$ref: "#/definitions/frontend"
inviteTokenGenerateRequest:
type: object
properties:
tokens:
type: array
items:
type: string
metrics:
type: object
properties: