mirror of
https://github.com/openziti/zrok.git
synced 2024-12-23 23:29:22 +01:00
Merge branch 'main' of github.com:openziti/zrok
This commit is contained in:
commit
6c9180c9ee
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
|||||||
.$*
|
.$*
|
||||||
.idea
|
.idea
|
||||||
|
.vscode
|
||||||
*.db
|
*.db
|
||||||
automated-release-build
|
automated-release-build
|
||||||
etc/dev.yml
|
etc/dev.yml
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/openziti/zrok/rest_client_zrok/admin"
|
"github.com/openziti/zrok/rest_client_zrok/admin"
|
||||||
"github.com/openziti/zrok/rest_model_zrok"
|
"github.com/openziti/zrok/rest_model_zrok"
|
||||||
|
"github.com/openziti/zrok/tui"
|
||||||
"github.com/openziti/zrok/zrokdir"
|
"github.com/openziti/zrok/zrokdir"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -52,7 +55,14 @@ func (cmd *adminCreateFrontendCommand) run(_ *cobra.Command, args []string) {
|
|||||||
|
|
||||||
resp, err := zrok.Admin.CreateFrontend(req, mustGetAdminAuth())
|
resp, err := zrok.Admin.CreateFrontend(req, mustGetAdminAuth())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
switch err.(type) {
|
||||||
|
case *admin.CreateFrontendBadRequest:
|
||||||
|
tui.Error("create frontend request failed: name already exists", err)
|
||||||
|
os.Exit(1)
|
||||||
|
default:
|
||||||
|
tui.Error("create frontend request failed", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Infof("created global public frontend '%v'", resp.Payload.Token)
|
logrus.Infof("created global public frontend '%v'", resp.Payload.Token)
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/go-openapi/runtime/middleware"
|
"github.com/go-openapi/runtime/middleware"
|
||||||
|
"github.com/lib/pq"
|
||||||
|
"github.com/mattn/go-sqlite3"
|
||||||
"github.com/openziti/zrok/controller/store"
|
"github.com/openziti/zrok/controller/store"
|
||||||
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
||||||
"github.com/openziti/zrok/rest_model_zrok"
|
"github.com/openziti/zrok/rest_model_zrok"
|
||||||
@ -60,6 +64,19 @@ func (h *createFrontendHandler) Handle(params admin.CreateFrontendParams, princi
|
|||||||
Reserved: true,
|
Reserved: true,
|
||||||
}
|
}
|
||||||
if _, err := str.CreateGlobalFrontend(fe, tx); err != nil {
|
if _, err := str.CreateGlobalFrontend(fe, tx); err != nil {
|
||||||
|
perr := &pq.Error{}
|
||||||
|
sqliteErr := &sqlite3.Error{}
|
||||||
|
switch {
|
||||||
|
case errors.As(err, &perr):
|
||||||
|
if perr.Code == pq.ErrorCode("23505") {
|
||||||
|
return admin.NewCreateFrontendBadRequest()
|
||||||
|
}
|
||||||
|
case errors.As(err, sqliteErr):
|
||||||
|
if errors.Is(sqliteErr.Code, sqlite3.ErrConstraint) {
|
||||||
|
return admin.NewCreateFrontendBadRequest()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logrus.Errorf("error creating frontend record: %v", err)
|
logrus.Errorf("error creating frontend record: %v", err)
|
||||||
return admin.NewCreateFrontendInternalServerError()
|
return admin.NewCreateFrontendInternalServerError()
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,12 @@ func (o *CreateFrontendReader) ReadResponse(response runtime.ClientResponse, con
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
|
case 400:
|
||||||
|
result := NewCreateFrontendBadRequest()
|
||||||
|
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return nil, result
|
||||||
case 401:
|
case 401:
|
||||||
result := NewCreateFrontendUnauthorized()
|
result := NewCreateFrontendUnauthorized()
|
||||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||||
@ -115,6 +121,57 @@ func (o *CreateFrontendCreated) readResponse(response runtime.ClientResponse, co
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewCreateFrontendBadRequest creates a CreateFrontendBadRequest with default headers values
|
||||||
|
func NewCreateFrontendBadRequest() *CreateFrontendBadRequest {
|
||||||
|
return &CreateFrontendBadRequest{}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
CreateFrontendBadRequest describes a response with status code 400, with default header values.
|
||||||
|
|
||||||
|
bad request
|
||||||
|
*/
|
||||||
|
type CreateFrontendBadRequest struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsSuccess returns true when this create frontend bad request response has a 2xx status code
|
||||||
|
func (o *CreateFrontendBadRequest) IsSuccess() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsRedirect returns true when this create frontend bad request response has a 3xx status code
|
||||||
|
func (o *CreateFrontendBadRequest) IsRedirect() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsClientError returns true when this create frontend bad request response has a 4xx status code
|
||||||
|
func (o *CreateFrontendBadRequest) IsClientError() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsServerError returns true when this create frontend bad request response has a 5xx status code
|
||||||
|
func (o *CreateFrontendBadRequest) IsServerError() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsCode returns true when this create frontend bad request response a status code equal to that given
|
||||||
|
func (o *CreateFrontendBadRequest) IsCode(code int) bool {
|
||||||
|
return code == 400
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *CreateFrontendBadRequest) Error() string {
|
||||||
|
return fmt.Sprintf("[POST /frontend][%d] createFrontendBadRequest ", 400)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *CreateFrontendBadRequest) String() string {
|
||||||
|
return fmt.Sprintf("[POST /frontend][%d] createFrontendBadRequest ", 400)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *CreateFrontendBadRequest) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// NewCreateFrontendUnauthorized creates a CreateFrontendUnauthorized with default headers values
|
// NewCreateFrontendUnauthorized creates a CreateFrontendUnauthorized with default headers values
|
||||||
func NewCreateFrontendUnauthorized() *CreateFrontendUnauthorized {
|
func NewCreateFrontendUnauthorized() *CreateFrontendUnauthorized {
|
||||||
return &CreateFrontendUnauthorized{}
|
return &CreateFrontendUnauthorized{}
|
||||||
|
@ -265,6 +265,9 @@ func init() {
|
|||||||
"$ref": "#/definitions/createFrontendResponse"
|
"$ref": "#/definitions/createFrontendResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "bad request"
|
||||||
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"description": "unauthorized"
|
"description": "unauthorized"
|
||||||
},
|
},
|
||||||
@ -1537,6 +1540,9 @@ func init() {
|
|||||||
"$ref": "#/definitions/createFrontendResponse"
|
"$ref": "#/definitions/createFrontendResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "bad request"
|
||||||
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"description": "unauthorized"
|
"description": "unauthorized"
|
||||||
},
|
},
|
||||||
|
@ -58,6 +58,31 @@ func (o *CreateFrontendCreated) WriteResponse(rw http.ResponseWriter, producer r
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateFrontendBadRequestCode is the HTTP code returned for type CreateFrontendBadRequest
|
||||||
|
const CreateFrontendBadRequestCode int = 400
|
||||||
|
|
||||||
|
/*
|
||||||
|
CreateFrontendBadRequest bad request
|
||||||
|
|
||||||
|
swagger:response createFrontendBadRequest
|
||||||
|
*/
|
||||||
|
type CreateFrontendBadRequest struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCreateFrontendBadRequest creates CreateFrontendBadRequest with default headers values
|
||||||
|
func NewCreateFrontendBadRequest() *CreateFrontendBadRequest {
|
||||||
|
|
||||||
|
return &CreateFrontendBadRequest{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteResponse to the client
|
||||||
|
func (o *CreateFrontendBadRequest) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||||
|
|
||||||
|
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
|
||||||
|
|
||||||
|
rw.WriteHeader(400)
|
||||||
|
}
|
||||||
|
|
||||||
// CreateFrontendUnauthorizedCode is the HTTP code returned for type CreateFrontendUnauthorized
|
// CreateFrontendUnauthorizedCode is the HTTP code returned for type CreateFrontendUnauthorized
|
||||||
const CreateFrontendUnauthorizedCode int = 401
|
const CreateFrontendUnauthorizedCode int = 401
|
||||||
|
|
||||||
|
@ -151,6 +151,8 @@ paths:
|
|||||||
description: frontend created
|
description: frontend created
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/definitions/createFrontendResponse"
|
$ref: "#/definitions/createFrontendResponse"
|
||||||
|
400:
|
||||||
|
description: bad request
|
||||||
401:
|
401:
|
||||||
description: unauthorized
|
description: unauthorized
|
||||||
404:
|
404:
|
||||||
|
Loading…
Reference in New Issue
Block a user