mirror of
https://github.com/openziti/zrok.git
synced 2024-11-22 08:03:49 +01:00
admin create frontend now interrogates ziti for the identity (#129)
This commit is contained in:
parent
cbf809c06a
commit
f0228e8fe0
@ -20,6 +20,24 @@ func (h *createFrontendHandler) Handle(params admin.CreateFrontendParams, princi
|
||||
return admin.NewCreateFrontendUnauthorized()
|
||||
}
|
||||
|
||||
client, err := edgeClient()
|
||||
if err != nil {
|
||||
logrus.Errorf("error getting edge client: %v", err)
|
||||
return admin.NewCreateFrontendInternalServerError()
|
||||
}
|
||||
|
||||
zId := params.Body.ZID
|
||||
detail, err := getIdentity(zId, client)
|
||||
if err != nil {
|
||||
logrus.Errorf("error getting identity details for '%v': %v", zId, err)
|
||||
return admin.NewCreateFrontendInternalServerError()
|
||||
}
|
||||
if len(detail.Payload.Data) != 1 {
|
||||
logrus.Errorf("expected a single identity to be returned for '%v'", zId)
|
||||
return admin.NewCreateFrontendNotFound()
|
||||
}
|
||||
logrus.Infof("found frontend identity '%v'", *detail.Payload.Data[0].Name)
|
||||
|
||||
tx, err := str.Begin()
|
||||
if err != nil {
|
||||
logrus.Errorf("error starting transaction: %v", err)
|
||||
@ -50,7 +68,7 @@ func (h *createFrontendHandler) Handle(params admin.CreateFrontendParams, princi
|
||||
return admin.NewCreateFrontendInternalServerError()
|
||||
}
|
||||
|
||||
logrus.Infof("created global frontend '%v' with public name '%v'", fe.Token, fe.PublicName)
|
||||
logrus.Infof("created global frontend '%v' with public name '%v'", fe.Token, *fe.PublicName)
|
||||
|
||||
return admin.NewCreateFrontendCreated().WithPayload(&rest_model_zrok.CreateFrontendResponse{Token: feToken})
|
||||
}
|
||||
|
@ -371,6 +371,24 @@ func createIdentity(email string, client *rest_management_api_client.ZitiEdgeMan
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func getIdentity(zId string, client *rest_management_api_client.ZitiEdgeManagement) (*identity_edge.ListIdentitiesOK, error) {
|
||||
filter := fmt.Sprintf("id=\"%v\"", zId)
|
||||
limit := int64(0)
|
||||
offset := int64(0)
|
||||
req := &identity_edge.ListIdentitiesParams{
|
||||
Filter: &filter,
|
||||
Limit: &limit,
|
||||
Offset: &offset,
|
||||
Context: context.Background(),
|
||||
}
|
||||
req.SetTimeout(30 * time.Second)
|
||||
resp, err := client.Identity.ListIdentities(req, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func enrollIdentity(zId string, client *rest_management_api_client.ZitiEdgeManagement) (*sdk_config.Config, error) {
|
||||
p := &identity_edge.DetailIdentityParams{
|
||||
Context: context.Background(),
|
||||
|
@ -35,6 +35,12 @@ func (o *CreateFrontendReader) ReadResponse(response runtime.ClientResponse, con
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 404:
|
||||
result := NewCreateFrontendNotFound()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 500:
|
||||
result := NewCreateFrontendInternalServerError()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
@ -160,6 +166,57 @@ func (o *CreateFrontendUnauthorized) readResponse(response runtime.ClientRespons
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewCreateFrontendNotFound creates a CreateFrontendNotFound with default headers values
|
||||
func NewCreateFrontendNotFound() *CreateFrontendNotFound {
|
||||
return &CreateFrontendNotFound{}
|
||||
}
|
||||
|
||||
/*
|
||||
CreateFrontendNotFound describes a response with status code 404, with default header values.
|
||||
|
||||
not found
|
||||
*/
|
||||
type CreateFrontendNotFound struct {
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this create frontend not found response has a 2xx status code
|
||||
func (o *CreateFrontendNotFound) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this create frontend not found response has a 3xx status code
|
||||
func (o *CreateFrontendNotFound) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this create frontend not found response has a 4xx status code
|
||||
func (o *CreateFrontendNotFound) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this create frontend not found response has a 5xx status code
|
||||
func (o *CreateFrontendNotFound) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this create frontend not found response a status code equal to that given
|
||||
func (o *CreateFrontendNotFound) IsCode(code int) bool {
|
||||
return code == 404
|
||||
}
|
||||
|
||||
func (o *CreateFrontendNotFound) Error() string {
|
||||
return fmt.Sprintf("[POST /frontend][%d] createFrontendNotFound ", 404)
|
||||
}
|
||||
|
||||
func (o *CreateFrontendNotFound) String() string {
|
||||
return fmt.Sprintf("[POST /frontend][%d] createFrontendNotFound ", 404)
|
||||
}
|
||||
|
||||
func (o *CreateFrontendNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewCreateFrontendInternalServerError creates a CreateFrontendInternalServerError with default headers values
|
||||
func NewCreateFrontendInternalServerError() *CreateFrontendInternalServerError {
|
||||
return &CreateFrontendInternalServerError{}
|
||||
|
@ -176,6 +176,9 @@ func init() {
|
||||
"401": {
|
||||
"description": "unauthorized"
|
||||
},
|
||||
"404": {
|
||||
"description": "not found"
|
||||
},
|
||||
"500": {
|
||||
"description": "internal server error"
|
||||
}
|
||||
@ -1021,6 +1024,9 @@ func init() {
|
||||
"401": {
|
||||
"description": "unauthorized"
|
||||
},
|
||||
"404": {
|
||||
"description": "not found"
|
||||
},
|
||||
"500": {
|
||||
"description": "internal server error"
|
||||
}
|
||||
|
@ -83,6 +83,31 @@ func (o *CreateFrontendUnauthorized) WriteResponse(rw http.ResponseWriter, produ
|
||||
rw.WriteHeader(401)
|
||||
}
|
||||
|
||||
// CreateFrontendNotFoundCode is the HTTP code returned for type CreateFrontendNotFound
|
||||
const CreateFrontendNotFoundCode int = 404
|
||||
|
||||
/*
|
||||
CreateFrontendNotFound not found
|
||||
|
||||
swagger:response createFrontendNotFound
|
||||
*/
|
||||
type CreateFrontendNotFound struct {
|
||||
}
|
||||
|
||||
// NewCreateFrontendNotFound creates CreateFrontendNotFound with default headers values
|
||||
func NewCreateFrontendNotFound() *CreateFrontendNotFound {
|
||||
|
||||
return &CreateFrontendNotFound{}
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *CreateFrontendNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
|
||||
|
||||
rw.WriteHeader(404)
|
||||
}
|
||||
|
||||
// CreateFrontendInternalServerErrorCode is the HTTP code returned for type CreateFrontendInternalServerError
|
||||
const CreateFrontendInternalServerErrorCode int = 500
|
||||
|
||||
|
@ -113,6 +113,8 @@ paths:
|
||||
$ref: "#/definitions/createFrontendResponse"
|
||||
401:
|
||||
description: unauthorized
|
||||
404:
|
||||
description: not found
|
||||
500:
|
||||
description: internal server error
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user