mirror of
https://github.com/openziti/zrok.git
synced 2025-06-20 01:37:52 +02:00
new overview response for '/overview' endpoint (#320)
This commit is contained in:
parent
d718e8c9ff
commit
9591f5150e
@ -20,14 +20,14 @@ func overviewHandler(_ metadata.OverviewParams, principal *rest_model_zrok.Princ
|
|||||||
logrus.Errorf("error finding environments for '%v': %v", principal.Email, err)
|
logrus.Errorf("error finding environments for '%v': %v", principal.Email, err)
|
||||||
return metadata.NewOverviewInternalServerError()
|
return metadata.NewOverviewInternalServerError()
|
||||||
}
|
}
|
||||||
var out rest_model_zrok.EnvironmentSharesList
|
var envShrsList rest_model_zrok.EnvironmentSharesList
|
||||||
for _, env := range envs {
|
for _, env := range envs {
|
||||||
shrs, err := str.FindSharesForEnvironment(env.Id, tx)
|
shrs, err := str.FindSharesForEnvironment(env.Id, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("error finding shares for environment '%v': %v", env.ZId, err)
|
logrus.Errorf("error finding shares for environment '%v': %v", env.ZId, err)
|
||||||
return metadata.NewOverviewInternalServerError()
|
return metadata.NewOverviewInternalServerError()
|
||||||
}
|
}
|
||||||
es := &rest_model_zrok.EnvironmentShares{
|
envShrs := &rest_model_zrok.EnvironmentShares{
|
||||||
Environment: &rest_model_zrok.Environment{
|
Environment: &rest_model_zrok.Environment{
|
||||||
Address: env.Address,
|
Address: env.Address,
|
||||||
CreatedAt: env.CreatedAt.UnixMilli(),
|
CreatedAt: env.CreatedAt.UnixMilli(),
|
||||||
@ -63,7 +63,7 @@ func overviewHandler(_ metadata.OverviewParams, principal *rest_model_zrok.Princ
|
|||||||
if shr.BackendProxyEndpoint != nil {
|
if shr.BackendProxyEndpoint != nil {
|
||||||
beProxyEndpoint = *shr.BackendProxyEndpoint
|
beProxyEndpoint = *shr.BackendProxyEndpoint
|
||||||
}
|
}
|
||||||
oshr := &rest_model_zrok.Share{
|
envShr := &rest_model_zrok.Share{
|
||||||
Token: shr.Token,
|
Token: shr.Token,
|
||||||
ZID: shr.ZId,
|
ZID: shr.ZId,
|
||||||
ShareMode: shr.ShareMode,
|
ShareMode: shr.ShareMode,
|
||||||
@ -77,12 +77,15 @@ func overviewHandler(_ metadata.OverviewParams, principal *rest_model_zrok.Princ
|
|||||||
}
|
}
|
||||||
if action, found := shrsLimitedMap[shr.Id]; found {
|
if action, found := shrsLimitedMap[shr.Id]; found {
|
||||||
if action == store.LimitAction {
|
if action == store.LimitAction {
|
||||||
oshr.Limited = true
|
envShr.Limited = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
es.Shares = append(es.Shares, oshr)
|
envShrs.Shares = append(envShrs.Shares, envShr)
|
||||||
}
|
}
|
||||||
out = append(out, es)
|
envShrsList = append(envShrsList, envShrs)
|
||||||
}
|
}
|
||||||
return metadata.NewOverviewOK().WithPayload(out)
|
return metadata.NewOverviewOK().WithPayload(&rest_model_zrok.Overview{
|
||||||
|
AccountLimited: false,
|
||||||
|
Environments: envShrsList,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ OverviewOK describes a response with status code 200, with default header values
|
|||||||
overview returned
|
overview returned
|
||||||
*/
|
*/
|
||||||
type OverviewOK struct {
|
type OverviewOK struct {
|
||||||
Payload rest_model_zrok.EnvironmentSharesList
|
Payload *rest_model_zrok.Overview
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsSuccess returns true when this overview o k response has a 2xx status code
|
// IsSuccess returns true when this overview o k response has a 2xx status code
|
||||||
@ -87,14 +87,16 @@ func (o *OverviewOK) String() 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.EnvironmentSharesList {
|
func (o *OverviewOK) GetPayload() *rest_model_zrok.Overview {
|
||||||
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.Overview)
|
||||||
|
|
||||||
// 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
103
rest_model_zrok/overview.go
Normal file
103
rest_model_zrok/overview.go
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
// 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"
|
||||||
|
|
||||||
|
"github.com/go-openapi/errors"
|
||||||
|
"github.com/go-openapi/strfmt"
|
||||||
|
"github.com/go-openapi/swag"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Overview overview
|
||||||
|
//
|
||||||
|
// swagger:model overview
|
||||||
|
type Overview struct {
|
||||||
|
|
||||||
|
// account limited
|
||||||
|
AccountLimited bool `json:"accountLimited,omitempty"`
|
||||||
|
|
||||||
|
// environments
|
||||||
|
Environments EnvironmentSharesList `json:"environments,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate validates this overview
|
||||||
|
func (m *Overview) Validate(formats strfmt.Registry) error {
|
||||||
|
var res []error
|
||||||
|
|
||||||
|
if err := m.validateEnvironments(formats); err != nil {
|
||||||
|
res = append(res, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(res) > 0 {
|
||||||
|
return errors.CompositeValidationError(res...)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Overview) validateEnvironments(formats strfmt.Registry) error {
|
||||||
|
if swag.IsZero(m.Environments) { // not required
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := m.Environments.Validate(formats); err != nil {
|
||||||
|
if ve, ok := err.(*errors.Validation); ok {
|
||||||
|
return ve.ValidateName("environments")
|
||||||
|
} else if ce, ok := err.(*errors.CompositeError); ok {
|
||||||
|
return ce.ValidateName("environments")
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContextValidate validate this overview based on the context it is used
|
||||||
|
func (m *Overview) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||||
|
var res []error
|
||||||
|
|
||||||
|
if err := m.contextValidateEnvironments(ctx, formats); err != nil {
|
||||||
|
res = append(res, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(res) > 0 {
|
||||||
|
return errors.CompositeValidationError(res...)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Overview) contextValidateEnvironments(ctx context.Context, formats strfmt.Registry) error {
|
||||||
|
|
||||||
|
if err := m.Environments.ContextValidate(ctx, formats); err != nil {
|
||||||
|
if ve, ok := err.(*errors.Validation); ok {
|
||||||
|
return ve.ValidateName("environments")
|
||||||
|
} else if ce, ok := err.(*errors.CompositeError); ok {
|
||||||
|
return ce.ValidateName("environments")
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalBinary interface implementation
|
||||||
|
func (m *Overview) MarshalBinary() ([]byte, error) {
|
||||||
|
if m == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return swag.WriteJSON(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalBinary interface implementation
|
||||||
|
func (m *Overview) UnmarshalBinary(b []byte) error {
|
||||||
|
var res Overview
|
||||||
|
if err := swag.ReadJSON(b, &res); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*m = res
|
||||||
|
return nil
|
||||||
|
}
|
@ -679,7 +679,7 @@ func init() {
|
|||||||
"200": {
|
"200": {
|
||||||
"description": "overview returned",
|
"description": "overview returned",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/environmentSharesList"
|
"$ref": "#/definitions/overview"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
@ -1211,6 +1211,17 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"overview": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"accountLimited": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"environments": {
|
||||||
|
"$ref": "#/definitions/environmentSharesList"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"principal": {
|
"principal": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@ -2156,7 +2167,7 @@ func init() {
|
|||||||
"200": {
|
"200": {
|
||||||
"description": "overview returned",
|
"description": "overview returned",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/environmentSharesList"
|
"$ref": "#/definitions/overview"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
@ -2688,6 +2699,17 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"overview": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"accountLimited": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"environments": {
|
||||||
|
"$ref": "#/definitions/environmentSharesList"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"principal": {
|
"principal": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -26,7 +26,7 @@ type OverviewOK struct {
|
|||||||
/*
|
/*
|
||||||
In: Body
|
In: Body
|
||||||
*/
|
*/
|
||||||
Payload rest_model_zrok.EnvironmentSharesList `json:"body,omitempty"`
|
Payload *rest_model_zrok.Overview `json:"body,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOverviewOK creates OverviewOK with default headers values
|
// NewOverviewOK creates OverviewOK with default headers values
|
||||||
@ -36,13 +36,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.EnvironmentSharesList) *OverviewOK {
|
func (o *OverviewOK) WithPayload(payload *rest_model_zrok.Overview) *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.EnvironmentSharesList) {
|
func (o *OverviewOK) SetPayload(payload *rest_model_zrok.Overview) {
|
||||||
o.Payload = payload
|
o.Payload = payload
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,14 +50,11 @@ func (o *OverviewOK) SetPayload(payload rest_model_zrok.EnvironmentSharesList) {
|
|||||||
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)
|
||||||
payload := o.Payload
|
if o.Payload != nil {
|
||||||
if payload == nil {
|
payload := o.Payload
|
||||||
// return empty array
|
if err := producer.Produce(rw, payload); err != nil {
|
||||||
payload = rest_model_zrok.EnvironmentSharesList{}
|
panic(err) // let the recovery middleware deal with this
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := producer.Produce(rw, payload); err != nil {
|
|
||||||
panic(err) // let the recovery middleware deal with this
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,7 +403,7 @@ paths:
|
|||||||
200:
|
200:
|
||||||
description: overview returned
|
description: overview returned
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/definitions/environmentSharesList"
|
$ref: "#/definitions/overview"
|
||||||
500:
|
500:
|
||||||
description: internal server error
|
description: internal server error
|
||||||
schema:
|
schema:
|
||||||
@ -785,6 +785,14 @@ definitions:
|
|||||||
timestamp:
|
timestamp:
|
||||||
type: number
|
type: number
|
||||||
|
|
||||||
|
overview:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
accountLimited:
|
||||||
|
type: boolean
|
||||||
|
environments:
|
||||||
|
$ref: "#/definitions/environmentSharesList"
|
||||||
|
|
||||||
principal:
|
principal:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
@ -143,6 +143,14 @@
|
|||||||
* @property {number} timestamp
|
* @property {number} timestamp
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef overview
|
||||||
|
* @memberof module:types
|
||||||
|
*
|
||||||
|
* @property {boolean} accountLimited
|
||||||
|
* @property {module:types.environmentSharesList} environments
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef principal
|
* @typedef principal
|
||||||
* @memberof module:types
|
* @memberof module:types
|
||||||
|
@ -15,12 +15,13 @@ const Console = (props) => {
|
|||||||
const openVersionModal = () => setShowVersionModal(true);
|
const openVersionModal = () => setShowVersionModal(true);
|
||||||
const closeVersionModal = () => setShowVersionModal(false);
|
const closeVersionModal = () => setShowVersionModal(false);
|
||||||
|
|
||||||
const [overview, setOverview] = useState([]);
|
const [overview, setOverview] = useState({});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let mounted = true;
|
let mounted = true;
|
||||||
metadata.overview().then(resp => {
|
metadata.overview().then(resp => {
|
||||||
if(mounted) {
|
if(mounted) {
|
||||||
|
console.log("init overview", resp.data);
|
||||||
setOverview(resp.data);
|
setOverview(resp.data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -31,6 +32,7 @@ const Console = (props) => {
|
|||||||
let interval = setInterval(() => {
|
let interval = setInterval(() => {
|
||||||
metadata.overview().then(resp => {
|
metadata.overview().then(resp => {
|
||||||
if(mounted) {
|
if(mounted) {
|
||||||
|
console.log("update overview", resp.data);
|
||||||
setOverview(resp.data);
|
setOverview(resp.data);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -10,7 +10,8 @@ const Visualizer = (props) => {
|
|||||||
const [networkGraph, setNetworkGraph] = useState({nodes: [], links: []});
|
const [networkGraph, setNetworkGraph] = useState({nodes: [], links: []});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setNetworkGraph(mergeGraph(networkGraph, props.user, props.overview));
|
console.log("visualizer overview", props.overview);
|
||||||
|
setNetworkGraph(mergeGraph(networkGraph, props.user, props.overview.environments));
|
||||||
|
|
||||||
if(isSelectionGone(networkGraph, props.selection)) {
|
if(isSelectionGone(networkGraph, props.selection)) {
|
||||||
// if the selection is no longer in the network graph...
|
// if the selection is no longer in the network graph...
|
||||||
|
@ -29,43 +29,45 @@ export const mergeGraph = (oldGraph, user, newOverview) => {
|
|||||||
}
|
}
|
||||||
newGraph.nodes.push(accountNode);
|
newGraph.nodes.push(accountNode);
|
||||||
|
|
||||||
newOverview.forEach(env => {
|
if(newOverview) {
|
||||||
let envNode = {
|
newOverview.forEach(env => {
|
||||||
id: env.environment.zId,
|
let envNode = {
|
||||||
label: env.environment.description,
|
id: env.environment.zId,
|
||||||
type: "environment",
|
label: env.environment.description,
|
||||||
val: 50,
|
type: "environment",
|
||||||
limited: env.limited
|
val: 50,
|
||||||
};
|
limited: env.limited
|
||||||
newGraph.nodes.push(envNode);
|
};
|
||||||
newGraph.links.push({
|
newGraph.nodes.push(envNode);
|
||||||
target: accountNode.id,
|
newGraph.links.push({
|
||||||
source: envNode.id,
|
target: accountNode.id,
|
||||||
color: "#04adef"
|
source: envNode.id,
|
||||||
});
|
color: "#04adef"
|
||||||
if(env.shares) {
|
|
||||||
env.shares.forEach(shr => {
|
|
||||||
let shrLabel = shr.token;
|
|
||||||
if(shr.backendProxyEndpoint !== "") {
|
|
||||||
shrLabel = shr.backendProxyEndpoint;
|
|
||||||
}
|
|
||||||
let shrNode = {
|
|
||||||
id: shr.token,
|
|
||||||
envZId: env.environment.zId,
|
|
||||||
label: shrLabel,
|
|
||||||
type: "share",
|
|
||||||
limited: !!shr.limited,
|
|
||||||
val: 50
|
|
||||||
};
|
|
||||||
newGraph.nodes.push(shrNode);
|
|
||||||
newGraph.links.push({
|
|
||||||
target: envNode.id,
|
|
||||||
source: shrNode.id,
|
|
||||||
color: "#04adef"
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
if(env.shares) {
|
||||||
});
|
env.shares.forEach(shr => {
|
||||||
|
let shrLabel = shr.token;
|
||||||
|
if(shr.backendProxyEndpoint !== "") {
|
||||||
|
shrLabel = shr.backendProxyEndpoint;
|
||||||
|
}
|
||||||
|
let shrNode = {
|
||||||
|
id: shr.token,
|
||||||
|
envZId: env.environment.zId,
|
||||||
|
label: shrLabel,
|
||||||
|
type: "share",
|
||||||
|
limited: !!shr.limited,
|
||||||
|
val: 50
|
||||||
|
};
|
||||||
|
newGraph.nodes.push(shrNode);
|
||||||
|
newGraph.links.push({
|
||||||
|
target: envNode.id,
|
||||||
|
source: shrNode.id,
|
||||||
|
color: "#04adef"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
newGraph.nodes = sortNodes(newGraph.nodes);
|
newGraph.nodes = sortNodes(newGraph.nodes);
|
||||||
|
|
||||||
if(nodesEqual(oldGraph.nodes, newGraph.nodes)) {
|
if(nodesEqual(oldGraph.nodes, newGraph.nodes)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user