mirror of
https://github.com/openziti/zrok.git
synced 2025-01-03 04:29:19 +01:00
basic overview implementation
This commit is contained in:
parent
cf6236eeaf
commit
6e49e4991e
@ -16,7 +16,7 @@ func listEnvironmentsHandler(_ metadata.ListEnvironmentsParams, principal *rest_
|
|||||||
defer func() { _ = tx.Rollback() }()
|
defer func() { _ = tx.Rollback() }()
|
||||||
envs, err := str.FindEnvironmentsForAccount(int(principal.ID), tx)
|
envs, err := str.FindEnvironmentsForAccount(int(principal.ID), tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("error finding identities for '%v': %v", principal.Username, err)
|
logrus.Errorf("error finding environments for '%v': %v", principal.Username, err)
|
||||||
return metadata.NewListEnvironmentsInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
return metadata.NewListEnvironmentsInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
||||||
}
|
}
|
||||||
var out rest_model_zrok.Environments
|
var out rest_model_zrok.Environments
|
||||||
|
@ -4,8 +4,49 @@ import (
|
|||||||
"github.com/go-openapi/runtime/middleware"
|
"github.com/go-openapi/runtime/middleware"
|
||||||
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
|
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
|
||||||
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/metadata"
|
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/metadata"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func overviewHandler(_ metadata.OverviewParams, principal *rest_model_zrok.Principal) middleware.Responder {
|
func overviewHandler(_ metadata.OverviewParams, principal *rest_model_zrok.Principal) middleware.Responder {
|
||||||
return nil
|
tx, err := str.Begin()
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("error starting transaction: %v", err)
|
||||||
|
return metadata.NewOverviewInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
||||||
|
}
|
||||||
|
defer func() { _ = tx.Rollback() }()
|
||||||
|
envs, err := str.FindEnvironmentsForAccount(int(principal.ID), tx)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("error finding environments for '%v': %v", principal.Username, err)
|
||||||
|
return metadata.NewOverviewInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
||||||
|
}
|
||||||
|
var out rest_model_zrok.EnvironmentServicesList
|
||||||
|
for _, env := range envs {
|
||||||
|
svcs, err := str.FindServicesForEnvironment(env.Id, tx)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("error finding services for environment '%v': %v", env.ZitiIdentityId, err)
|
||||||
|
return metadata.NewOverviewInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
||||||
|
}
|
||||||
|
es := &rest_model_zrok.EnvironmentServices{
|
||||||
|
Environment: &rest_model_zrok.Environment{
|
||||||
|
Active: env.Active,
|
||||||
|
Address: env.Address,
|
||||||
|
CreatedAt: env.CreatedAt.String(),
|
||||||
|
Description: env.Description,
|
||||||
|
Host: env.Host,
|
||||||
|
UpdatedAt: env.UpdatedAt.String(),
|
||||||
|
ZitiIdentityID: env.ZitiIdentityId,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, svc := range svcs {
|
||||||
|
es.Services = append(es.Services, &rest_model_zrok.Service{
|
||||||
|
Active: svc.Active,
|
||||||
|
CreatedAt: svc.CreatedAt.String(),
|
||||||
|
Endpoint: svc.Endpoint,
|
||||||
|
UpdatedAt: svc.UpdatedAt.String(),
|
||||||
|
ZitiServiceID: svc.ZitiServiceId,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
out = append(out, es)
|
||||||
|
}
|
||||||
|
return metadata.NewOverviewOK().WithPayload(out)
|
||||||
}
|
}
|
||||||
|
@ -50,22 +50,20 @@ func NewOverviewOK() *OverviewOK {
|
|||||||
overview returned
|
overview returned
|
||||||
*/
|
*/
|
||||||
type OverviewOK struct {
|
type OverviewOK struct {
|
||||||
Payload *rest_model_zrok.EnvironmentServices
|
Payload rest_model_zrok.EnvironmentServicesList
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OverviewOK) Error() string {
|
func (o *OverviewOK) Error() string {
|
||||||
return fmt.Sprintf("[GET /overview][%d] overviewOK %+v", 200, o.Payload)
|
return fmt.Sprintf("[GET /overview][%d] overviewOK %+v", 200, o.Payload)
|
||||||
}
|
}
|
||||||
func (o *OverviewOK) GetPayload() *rest_model_zrok.EnvironmentServices {
|
func (o *OverviewOK) GetPayload() rest_model_zrok.EnvironmentServicesList {
|
||||||
return o.Payload
|
return o.Payload
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OverviewOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
func (o *OverviewOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||||
|
|
||||||
o.Payload = new(rest_model_zrok.EnvironmentServices)
|
|
||||||
|
|
||||||
// response payload
|
// response payload
|
||||||
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
|
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
73
rest_model_zrok/environment_services_list.go
Normal file
73
rest_model_zrok/environment_services_list.go
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
// 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"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/go-openapi/errors"
|
||||||
|
"github.com/go-openapi/strfmt"
|
||||||
|
"github.com/go-openapi/swag"
|
||||||
|
)
|
||||||
|
|
||||||
|
// EnvironmentServicesList environment services list
|
||||||
|
//
|
||||||
|
// swagger:model environmentServicesList
|
||||||
|
type EnvironmentServicesList []*EnvironmentServices
|
||||||
|
|
||||||
|
// Validate validates this environment services list
|
||||||
|
func (m EnvironmentServicesList) Validate(formats strfmt.Registry) error {
|
||||||
|
var res []error
|
||||||
|
|
||||||
|
for i := 0; i < len(m); i++ {
|
||||||
|
if swag.IsZero(m[i]) { // not required
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if m[i] != nil {
|
||||||
|
if err := m[i].Validate(formats); err != nil {
|
||||||
|
if ve, ok := err.(*errors.Validation); ok {
|
||||||
|
return ve.ValidateName(strconv.Itoa(i))
|
||||||
|
} else if ce, ok := err.(*errors.CompositeError); ok {
|
||||||
|
return ce.ValidateName(strconv.Itoa(i))
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(res) > 0 {
|
||||||
|
return errors.CompositeValidationError(res...)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContextValidate validate this environment services list based on the context it is used
|
||||||
|
func (m EnvironmentServicesList) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||||
|
var res []error
|
||||||
|
|
||||||
|
for i := 0; i < len(m); i++ {
|
||||||
|
|
||||||
|
if m[i] != nil {
|
||||||
|
if err := m[i].ContextValidate(ctx, formats); err != nil {
|
||||||
|
if ve, ok := err.(*errors.Validation); ok {
|
||||||
|
return ve.ValidateName(strconv.Itoa(i))
|
||||||
|
} else if ce, ok := err.(*errors.CompositeError); ok {
|
||||||
|
return ce.ValidateName(strconv.Itoa(i))
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(res) > 0 {
|
||||||
|
return errors.CompositeValidationError(res...)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
@ -184,7 +184,7 @@ func init() {
|
|||||||
"200": {
|
"200": {
|
||||||
"description": "overview returned",
|
"description": "overview returned",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/environmentServices"
|
"$ref": "#/definitions/environmentServicesList"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
@ -373,6 +373,12 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"environmentServicesList": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/environmentServices"
|
||||||
|
}
|
||||||
|
},
|
||||||
"environments": {
|
"environments": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
@ -645,7 +651,7 @@ func init() {
|
|||||||
"200": {
|
"200": {
|
||||||
"description": "overview returned",
|
"description": "overview returned",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/environmentServices"
|
"$ref": "#/definitions/environmentServicesList"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
@ -834,6 +840,12 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"environmentServicesList": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/environmentServices"
|
||||||
|
}
|
||||||
|
},
|
||||||
"environments": {
|
"environments": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
|
@ -25,7 +25,7 @@ type OverviewOK struct {
|
|||||||
/*
|
/*
|
||||||
In: Body
|
In: Body
|
||||||
*/
|
*/
|
||||||
Payload *rest_model_zrok.EnvironmentServices `json:"body,omitempty"`
|
Payload rest_model_zrok.EnvironmentServicesList `json:"body,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOverviewOK creates OverviewOK with default headers values
|
// NewOverviewOK creates OverviewOK with default headers values
|
||||||
@ -35,13 +35,13 @@ func NewOverviewOK() *OverviewOK {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithPayload adds the payload to the overview o k response
|
// WithPayload adds the payload to the overview o k response
|
||||||
func (o *OverviewOK) WithPayload(payload *rest_model_zrok.EnvironmentServices) *OverviewOK {
|
func (o *OverviewOK) WithPayload(payload rest_model_zrok.EnvironmentServicesList) *OverviewOK {
|
||||||
o.Payload = payload
|
o.Payload = payload
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetPayload sets the payload to the overview o k response
|
// SetPayload sets the payload to the overview o k response
|
||||||
func (o *OverviewOK) SetPayload(payload *rest_model_zrok.EnvironmentServices) {
|
func (o *OverviewOK) SetPayload(payload rest_model_zrok.EnvironmentServicesList) {
|
||||||
o.Payload = payload
|
o.Payload = payload
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,11 +49,14 @@ func (o *OverviewOK) SetPayload(payload *rest_model_zrok.EnvironmentServices) {
|
|||||||
func (o *OverviewOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
func (o *OverviewOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||||
|
|
||||||
rw.WriteHeader(200)
|
rw.WriteHeader(200)
|
||||||
if o.Payload != nil {
|
payload := o.Payload
|
||||||
payload := o.Payload
|
if payload == nil {
|
||||||
if err := producer.Produce(rw, payload); err != nil {
|
// return empty array
|
||||||
panic(err) // let the recovery middleware deal with this
|
payload = rest_model_zrok.EnvironmentServicesList{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := producer.Produce(rw, payload); err != nil {
|
||||||
|
panic(err) // let the recovery middleware deal with this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ paths:
|
|||||||
200:
|
200:
|
||||||
description: overview returned
|
description: overview returned
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/definitions/environmentServices"
|
$ref: "#/definitions/environmentServicesList"
|
||||||
500:
|
500:
|
||||||
description: internal server error
|
description: internal server error
|
||||||
schema:
|
schema:
|
||||||
@ -224,6 +224,10 @@ definitions:
|
|||||||
updatedAt:
|
updatedAt:
|
||||||
type: string
|
type: string
|
||||||
|
|
||||||
|
environmentServicesList:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: "#/definitions/environmentServices"
|
||||||
environmentServices:
|
environmentServices:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
Loading…
Reference in New Issue
Block a user