new overview response for '/overview' endpoint (#320)

This commit is contained in:
Michael Quigley 2023-05-16 11:51:03 -04:00
parent d718e8c9ff
commit 9591f5150e
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
10 changed files with 210 additions and 62 deletions

View File

@ -20,14 +20,14 @@ func overviewHandler(_ metadata.OverviewParams, principal *rest_model_zrok.Princ
logrus.Errorf("error finding environments for '%v': %v", principal.Email, err)
return metadata.NewOverviewInternalServerError()
}
var out rest_model_zrok.EnvironmentSharesList
var envShrsList rest_model_zrok.EnvironmentSharesList
for _, env := range envs {
shrs, err := str.FindSharesForEnvironment(env.Id, tx)
if err != nil {
logrus.Errorf("error finding shares for environment '%v': %v", env.ZId, err)
return metadata.NewOverviewInternalServerError()
}
es := &rest_model_zrok.EnvironmentShares{
envShrs := &rest_model_zrok.EnvironmentShares{
Environment: &rest_model_zrok.Environment{
Address: env.Address,
CreatedAt: env.CreatedAt.UnixMilli(),
@ -63,7 +63,7 @@ func overviewHandler(_ metadata.OverviewParams, principal *rest_model_zrok.Princ
if shr.BackendProxyEndpoint != nil {
beProxyEndpoint = *shr.BackendProxyEndpoint
}
oshr := &rest_model_zrok.Share{
envShr := &rest_model_zrok.Share{
Token: shr.Token,
ZID: shr.ZId,
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 == 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,
})
}

View File

@ -51,7 +51,7 @@ OverviewOK describes a response with status code 200, with default header values
overview returned
*/
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
@ -87,14 +87,16 @@ func (o *OverviewOK) String() string {
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
}
func (o *OverviewOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(rest_model_zrok.Overview)
// 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
}

103
rest_model_zrok/overview.go Normal file
View 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
}

View File

@ -679,7 +679,7 @@ func init() {
"200": {
"description": "overview returned",
"schema": {
"$ref": "#/definitions/environmentSharesList"
"$ref": "#/definitions/overview"
}
},
"500": {
@ -1211,6 +1211,17 @@ func init() {
}
}
},
"overview": {
"type": "object",
"properties": {
"accountLimited": {
"type": "boolean"
},
"environments": {
"$ref": "#/definitions/environmentSharesList"
}
}
},
"principal": {
"type": "object",
"properties": {
@ -2156,7 +2167,7 @@ func init() {
"200": {
"description": "overview returned",
"schema": {
"$ref": "#/definitions/environmentSharesList"
"$ref": "#/definitions/overview"
}
},
"500": {
@ -2688,6 +2699,17 @@ func init() {
}
}
},
"overview": {
"type": "object",
"properties": {
"accountLimited": {
"type": "boolean"
},
"environments": {
"$ref": "#/definitions/environmentSharesList"
}
}
},
"principal": {
"type": "object",
"properties": {

View File

@ -26,7 +26,7 @@ type OverviewOK struct {
/*
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
@ -36,13 +36,13 @@ func NewOverviewOK() *OverviewOK {
}
// 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
return o
}
// 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
}
@ -50,14 +50,11 @@ func (o *OverviewOK) SetPayload(payload rest_model_zrok.EnvironmentSharesList) {
func (o *OverviewOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.WriteHeader(200)
payload := o.Payload
if payload == nil {
// return empty array
payload = rest_model_zrok.EnvironmentSharesList{}
}
if err := producer.Produce(rw, payload); err != nil {
panic(err) // let the recovery middleware deal with this
if o.Payload != nil {
payload := o.Payload
if err := producer.Produce(rw, payload); err != nil {
panic(err) // let the recovery middleware deal with this
}
}
}

View File

@ -403,7 +403,7 @@ paths:
200:
description: overview returned
schema:
$ref: "#/definitions/environmentSharesList"
$ref: "#/definitions/overview"
500:
description: internal server error
schema:
@ -785,6 +785,14 @@ definitions:
timestamp:
type: number
overview:
type: object
properties:
accountLimited:
type: boolean
environments:
$ref: "#/definitions/environmentSharesList"
principal:
type: object
properties:

View File

@ -143,6 +143,14 @@
* @property {number} timestamp
*/
/**
* @typedef overview
* @memberof module:types
*
* @property {boolean} accountLimited
* @property {module:types.environmentSharesList} environments
*/
/**
* @typedef principal
* @memberof module:types

View File

@ -15,12 +15,13 @@ const Console = (props) => {
const openVersionModal = () => setShowVersionModal(true);
const closeVersionModal = () => setShowVersionModal(false);
const [overview, setOverview] = useState([]);
const [overview, setOverview] = useState({});
useEffect(() => {
let mounted = true;
metadata.overview().then(resp => {
if(mounted) {
console.log("init overview", resp.data);
setOverview(resp.data);
}
});
@ -31,6 +32,7 @@ const Console = (props) => {
let interval = setInterval(() => {
metadata.overview().then(resp => {
if(mounted) {
console.log("update overview", resp.data);
setOverview(resp.data);
}
})

View File

@ -10,7 +10,8 @@ const Visualizer = (props) => {
const [networkGraph, setNetworkGraph] = useState({nodes: [], links: []});
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 the selection is no longer in the network graph...

View File

@ -29,43 +29,45 @@ export const mergeGraph = (oldGraph, user, newOverview) => {
}
newGraph.nodes.push(accountNode);
newOverview.forEach(env => {
let envNode = {
id: env.environment.zId,
label: env.environment.description,
type: "environment",
val: 50,
limited: env.limited
};
newGraph.nodes.push(envNode);
newGraph.links.push({
target: accountNode.id,
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(newOverview) {
newOverview.forEach(env => {
let envNode = {
id: env.environment.zId,
label: env.environment.description,
type: "environment",
val: 50,
limited: env.limited
};
newGraph.nodes.push(envNode);
newGraph.links.push({
target: accountNode.id,
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"
});
});
}
});
}
newGraph.nodes = sortNodes(newGraph.nodes);
if(nodesEqual(oldGraph.nodes, newGraph.nodes)) {