env+shrs -> env+res; making space to return frontends (#323)

This commit is contained in:
Michael Quigley 2023-05-17 11:23:16 -04:00
parent 75376969ca
commit 8a9e02e464
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
12 changed files with 467 additions and 61 deletions

View File

@ -25,7 +25,7 @@ func (h *environmentDetailHandler) Handle(params metadata.GetEnvironmentDetailPa
logrus.Errorf("environment '%v' not found for account '%v': %v", params.EnvZID, principal.Email, err) logrus.Errorf("environment '%v' not found for account '%v': %v", params.EnvZID, principal.Email, err)
return metadata.NewGetEnvironmentDetailNotFound() return metadata.NewGetEnvironmentDetailNotFound()
} }
es := &rest_model_zrok.EnvironmentShares{ es := &rest_model_zrok.EnvironmentAndResources{
Environment: &rest_model_zrok.Environment{ Environment: &rest_model_zrok.Environment{
Address: senv.Address, Address: senv.Address,
CreatedAt: senv.CreatedAt.UnixMilli(), CreatedAt: senv.CreatedAt.UnixMilli(),

View File

@ -32,7 +32,11 @@ func (h *overviewHandler) Handle(_ metadata.OverviewParams, principal *rest_mode
logrus.Errorf("error finding limited environments for '%v': %v", principal.Email, err) logrus.Errorf("error finding limited environments for '%v': %v", principal.Email, err)
return metadata.NewOverviewInternalServerError() return metadata.NewOverviewInternalServerError()
} }
var envShrsList rest_model_zrok.EnvironmentSharesList accountLimited, err := h.isAccountLimited(principal, trx)
if err != nil {
logrus.Errorf("error checking account limited for '%v': %v", principal.Email, err)
}
ovr := &rest_model_zrok.Overview{AccountLimited: accountLimited}
for _, env := range envs { for _, env := range envs {
shrs, err := str.FindSharesForEnvironment(env.Id, trx) shrs, err := str.FindSharesForEnvironment(env.Id, trx)
if err != nil { if err != nil {
@ -44,7 +48,7 @@ func (h *overviewHandler) Handle(_ metadata.OverviewParams, principal *rest_mode
logrus.Errorf("error finding limited shares for environment '%v': %v", env.ZId, err) logrus.Errorf("error finding limited shares for environment '%v': %v", env.ZId, err)
return metadata.NewOverviewInternalServerError() return metadata.NewOverviewInternalServerError()
} }
envShrs := &rest_model_zrok.EnvironmentShares{ envRes := &rest_model_zrok.EnvironmentAndResources{
Environment: &rest_model_zrok.Environment{ Environment: &rest_model_zrok.Environment{
Address: env.Address, Address: env.Address,
Description: env.Description, Description: env.Description,
@ -81,18 +85,11 @@ func (h *overviewHandler) Handle(_ metadata.OverviewParams, principal *rest_mode
CreatedAt: shr.CreatedAt.UnixMilli(), CreatedAt: shr.CreatedAt.UnixMilli(),
UpdatedAt: shr.UpdatedAt.UnixMilli(), UpdatedAt: shr.UpdatedAt.UnixMilli(),
} }
envShrs.Shares = append(envShrs.Shares, envShr) envRes.Shares = append(envRes.Shares, envShr)
} }
envShrsList = append(envShrsList, envShrs) ovr.Environments = append(ovr.Environments, envRes)
} }
accountLimited, err := h.isAccountLimited(principal, trx) return metadata.NewOverviewOK().WithPayload(ovr)
if err != nil {
logrus.Errorf("error checking account limited for '%v': %v", principal.Email, err)
}
return metadata.NewOverviewOK().WithPayload(&rest_model_zrok.Overview{
AccountLimited: accountLimited,
Environments: envShrsList,
})
} }
func (h *overviewHandler) isAccountLimited(principal *rest_model_zrok.Principal, trx *sqlx.Tx) (bool, error) { func (h *overviewHandler) isAccountLimited(principal *rest_model_zrok.Principal, trx *sqlx.Tx) (bool, error) {

View File

@ -63,7 +63,7 @@ GetEnvironmentDetailOK describes a response with status code 200, with default h
ok ok
*/ */
type GetEnvironmentDetailOK struct { type GetEnvironmentDetailOK struct {
Payload *rest_model_zrok.EnvironmentShares Payload *rest_model_zrok.EnvironmentAndResources
} }
// IsSuccess returns true when this get environment detail o k response has a 2xx status code // IsSuccess returns true when this get environment detail o k response has a 2xx status code
@ -99,13 +99,13 @@ func (o *GetEnvironmentDetailOK) String() string {
return fmt.Sprintf("[GET /detail/environment/{envZId}][%d] getEnvironmentDetailOK %+v", 200, o.Payload) return fmt.Sprintf("[GET /detail/environment/{envZId}][%d] getEnvironmentDetailOK %+v", 200, o.Payload)
} }
func (o *GetEnvironmentDetailOK) GetPayload() *rest_model_zrok.EnvironmentShares { func (o *GetEnvironmentDetailOK) GetPayload() *rest_model_zrok.EnvironmentAndResources {
return o.Payload return o.Payload
} }
func (o *GetEnvironmentDetailOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { func (o *GetEnvironmentDetailOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(rest_model_zrok.EnvironmentShares) o.Payload = new(rest_model_zrok.EnvironmentAndResources)
// 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 {

View File

@ -0,0 +1,188 @@
// 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"
)
// EnvironmentAndResources environment and resources
//
// swagger:model environmentAndResources
type EnvironmentAndResources struct {
// environment
Environment *Environment `json:"environment,omitempty"`
// frontends
Frontends Frontends `json:"frontends,omitempty"`
// shares
Shares Shares `json:"shares,omitempty"`
}
// Validate validates this environment and resources
func (m *EnvironmentAndResources) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateEnvironment(formats); err != nil {
res = append(res, err)
}
if err := m.validateFrontends(formats); err != nil {
res = append(res, err)
}
if err := m.validateShares(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *EnvironmentAndResources) validateEnvironment(formats strfmt.Registry) error {
if swag.IsZero(m.Environment) { // not required
return nil
}
if m.Environment != nil {
if err := m.Environment.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("environment")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("environment")
}
return err
}
}
return nil
}
func (m *EnvironmentAndResources) validateFrontends(formats strfmt.Registry) error {
if swag.IsZero(m.Frontends) { // not required
return nil
}
if err := m.Frontends.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("frontends")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("frontends")
}
return err
}
return nil
}
func (m *EnvironmentAndResources) validateShares(formats strfmt.Registry) error {
if swag.IsZero(m.Shares) { // not required
return nil
}
if err := m.Shares.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("shares")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("shares")
}
return err
}
return nil
}
// ContextValidate validate this environment and resources based on the context it is used
func (m *EnvironmentAndResources) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
var res []error
if err := m.contextValidateEnvironment(ctx, formats); err != nil {
res = append(res, err)
}
if err := m.contextValidateFrontends(ctx, formats); err != nil {
res = append(res, err)
}
if err := m.contextValidateShares(ctx, formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *EnvironmentAndResources) contextValidateEnvironment(ctx context.Context, formats strfmt.Registry) error {
if m.Environment != nil {
if err := m.Environment.ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("environment")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("environment")
}
return err
}
}
return nil
}
func (m *EnvironmentAndResources) contextValidateFrontends(ctx context.Context, formats strfmt.Registry) error {
if err := m.Frontends.ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("frontends")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("frontends")
}
return err
}
return nil
}
func (m *EnvironmentAndResources) contextValidateShares(ctx context.Context, formats strfmt.Registry) error {
if err := m.Shares.ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("shares")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("shares")
}
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *EnvironmentAndResources) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *EnvironmentAndResources) UnmarshalBinary(b []byte) error {
var res EnvironmentAndResources
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@ -0,0 +1,59 @@
// 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/strfmt"
"github.com/go-openapi/swag"
)
// Frontend frontend
//
// swagger:model frontend
type Frontend struct {
// created at
CreatedAt int64 `json:"createdAt,omitempty"`
// shr token
ShrToken string `json:"shrToken,omitempty"`
// updated at
UpdatedAt int64 `json:"updatedAt,omitempty"`
// z Id
ZID string `json:"zId,omitempty"`
}
// Validate validates this frontend
func (m *Frontend) Validate(formats strfmt.Registry) error {
return nil
}
// ContextValidate validates this frontend based on context it is used
func (m *Frontend) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *Frontend) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *Frontend) UnmarshalBinary(b []byte) error {
var res Frontend
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View 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"
)
// Frontends frontends
//
// swagger:model frontends
type Frontends []*Frontend
// Validate validates this frontends
func (m Frontends) 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 frontends based on the context it is used
func (m Frontends) 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
}

View File

@ -7,6 +7,7 @@ package rest_model_zrok
import ( import (
"context" "context"
"strconv"
"github.com/go-openapi/errors" "github.com/go-openapi/errors"
"github.com/go-openapi/strfmt" "github.com/go-openapi/strfmt"
@ -22,7 +23,7 @@ type Overview struct {
AccountLimited bool `json:"accountLimited,omitempty"` AccountLimited bool `json:"accountLimited,omitempty"`
// environments // environments
Environments EnvironmentSharesList `json:"environments,omitempty"` Environments []*EnvironmentAndResources `json:"environments"`
} }
// Validate validates this overview // Validate validates this overview
@ -44,13 +45,22 @@ func (m *Overview) validateEnvironments(formats strfmt.Registry) error {
return nil return nil
} }
if err := m.Environments.Validate(formats); err != nil { for i := 0; i < len(m.Environments); i++ {
if ve, ok := err.(*errors.Validation); ok { if swag.IsZero(m.Environments[i]) { // not required
return ve.ValidateName("environments") continue
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("environments")
} }
return err
if m.Environments[i] != nil {
if err := m.Environments[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("environments" + "." + strconv.Itoa(i))
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("environments" + "." + strconv.Itoa(i))
}
return err
}
}
} }
return nil return nil
@ -72,13 +82,19 @@ func (m *Overview) ContextValidate(ctx context.Context, formats strfmt.Registry)
func (m *Overview) contextValidateEnvironments(ctx context.Context, formats strfmt.Registry) error { func (m *Overview) contextValidateEnvironments(ctx context.Context, formats strfmt.Registry) error {
if err := m.Environments.ContextValidate(ctx, formats); err != nil { for i := 0; i < len(m.Environments); i++ {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("environments") if m.Environments[i] != nil {
} else if ce, ok := err.(*errors.CompositeError); ok { if err := m.Environments[i].ContextValidate(ctx, formats); err != nil {
return ce.ValidateName("environments") if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("environments" + "." + strconv.Itoa(i))
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("environments" + "." + strconv.Itoa(i))
}
return err
}
} }
return err
} }
return nil return nil

View File

@ -137,7 +137,7 @@ func init() {
"200": { "200": {
"description": "ok", "description": "ok",
"schema": { "schema": {
"$ref": "#/definitions/environmentShares" "$ref": "#/definitions/environmentAndResources"
} }
}, },
"401": { "401": {
@ -1115,23 +1115,20 @@ func init() {
} }
} }
}, },
"environmentShares": { "environmentAndResources": {
"type": "object", "type": "object",
"properties": { "properties": {
"environment": { "environment": {
"$ref": "#/definitions/environment" "$ref": "#/definitions/environment"
}, },
"frontends": {
"$ref": "#/definitions/frontends"
},
"shares": { "shares": {
"$ref": "#/definitions/shares" "$ref": "#/definitions/shares"
} }
} }
}, },
"environmentSharesList": {
"type": "array",
"items": {
"$ref": "#/definitions/environmentShares"
}
},
"environments": { "environments": {
"type": "array", "type": "array",
"items": { "items": {
@ -1141,6 +1138,29 @@ func init() {
"errorMessage": { "errorMessage": {
"type": "string" "type": "string"
}, },
"frontend": {
"type": "object",
"properties": {
"createdAt": {
"type": "integer"
},
"shrToken": {
"type": "string"
},
"updatedAt": {
"type": "integer"
},
"zId": {
"type": "string"
}
}
},
"frontends": {
"type": "array",
"items": {
"$ref": "#/definitions/frontend"
}
},
"inviteRequest": { "inviteRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -1218,7 +1238,10 @@ func init() {
"type": "boolean" "type": "boolean"
}, },
"environments": { "environments": {
"$ref": "#/definitions/environmentSharesList" "type": "array",
"items": {
"$ref": "#/definitions/environmentAndResources"
}
} }
} }
}, },
@ -1625,7 +1648,7 @@ func init() {
"200": { "200": {
"description": "ok", "description": "ok",
"schema": { "schema": {
"$ref": "#/definitions/environmentShares" "$ref": "#/definitions/environmentAndResources"
} }
}, },
"401": { "401": {
@ -2603,23 +2626,20 @@ func init() {
} }
} }
}, },
"environmentShares": { "environmentAndResources": {
"type": "object", "type": "object",
"properties": { "properties": {
"environment": { "environment": {
"$ref": "#/definitions/environment" "$ref": "#/definitions/environment"
}, },
"frontends": {
"$ref": "#/definitions/frontends"
},
"shares": { "shares": {
"$ref": "#/definitions/shares" "$ref": "#/definitions/shares"
} }
} }
}, },
"environmentSharesList": {
"type": "array",
"items": {
"$ref": "#/definitions/environmentShares"
}
},
"environments": { "environments": {
"type": "array", "type": "array",
"items": { "items": {
@ -2629,6 +2649,29 @@ func init() {
"errorMessage": { "errorMessage": {
"type": "string" "type": "string"
}, },
"frontend": {
"type": "object",
"properties": {
"createdAt": {
"type": "integer"
},
"shrToken": {
"type": "string"
},
"updatedAt": {
"type": "integer"
},
"zId": {
"type": "string"
}
}
},
"frontends": {
"type": "array",
"items": {
"$ref": "#/definitions/frontend"
}
},
"inviteRequest": { "inviteRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -2706,7 +2749,10 @@ func init() {
"type": "boolean" "type": "boolean"
}, },
"environments": { "environments": {
"$ref": "#/definitions/environmentSharesList" "type": "array",
"items": {
"$ref": "#/definitions/environmentAndResources"
}
} }
} }
}, },

View File

@ -26,7 +26,7 @@ type GetEnvironmentDetailOK struct {
/* /*
In: Body In: Body
*/ */
Payload *rest_model_zrok.EnvironmentShares `json:"body,omitempty"` Payload *rest_model_zrok.EnvironmentAndResources `json:"body,omitempty"`
} }
// NewGetEnvironmentDetailOK creates GetEnvironmentDetailOK with default headers values // NewGetEnvironmentDetailOK creates GetEnvironmentDetailOK with default headers values
@ -36,13 +36,13 @@ func NewGetEnvironmentDetailOK() *GetEnvironmentDetailOK {
} }
// WithPayload adds the payload to the get environment detail o k response // WithPayload adds the payload to the get environment detail o k response
func (o *GetEnvironmentDetailOK) WithPayload(payload *rest_model_zrok.EnvironmentShares) *GetEnvironmentDetailOK { func (o *GetEnvironmentDetailOK) WithPayload(payload *rest_model_zrok.EnvironmentAndResources) *GetEnvironmentDetailOK {
o.Payload = payload o.Payload = payload
return o return o
} }
// SetPayload sets the payload to the get environment detail o k response // SetPayload sets the payload to the get environment detail o k response
func (o *GetEnvironmentDetailOK) SetPayload(payload *rest_model_zrok.EnvironmentShares) { func (o *GetEnvironmentDetailOK) SetPayload(payload *rest_model_zrok.EnvironmentAndResources) {
o.Payload = payload o.Payload = payload
} }

View File

@ -360,7 +360,7 @@ paths:
200: 200:
description: ok description: ok
schema: schema:
$ref: "#/definitions/environmentShares" $ref: "#/definitions/environmentAndResources"
401: 401:
description: unauthorized description: unauthorized
404: 404:
@ -718,22 +718,36 @@ definitions:
items: items:
$ref: "#/definitions/environment" $ref: "#/definitions/environment"
environmentSharesList: environmentAndResources:
type: array
items:
$ref: "#/definitions/environmentShares"
environmentShares:
type: object type: object
properties: properties:
environment: environment:
$ref: "#/definitions/environment" $ref: "#/definitions/environment"
frontends:
$ref: "#/definitions/frontends"
shares: shares:
$ref: "#/definitions/shares" $ref: "#/definitions/shares"
errorMessage: errorMessage:
type: string type: string
frontend:
type: object
properties:
shrToken:
type: string
zId:
type: string
createdAt:
type: integer
updatedAt:
type: integer
frontends:
type: array
items:
$ref: "#/definitions/frontend"
inviteTokenGenerateRequest: inviteTokenGenerateRequest:
type: object type: object
properties: properties:
@ -791,7 +805,9 @@ definitions:
accountLimited: accountLimited:
type: boolean type: boolean
environments: environments:
$ref: "#/definitions/environmentSharesList" type: array
items:
$ref: "#/definitions/environmentAndResources"
principal: principal:
type: object type: object

View File

@ -16,7 +16,7 @@ export function getAccountDetail() {
/** /**
* @param {string} envZId * @param {string} envZId
* @return {Promise<module:types.environmentShares>} ok * @return {Promise<module:types.environmentAndResources>} ok
*/ */
export function getEnvironmentDetail(envZId) { export function getEnvironmentDetail(envZId) {
const parameters = { const parameters = {

View File

@ -94,13 +94,24 @@
*/ */
/** /**
* @typedef environmentShares * @typedef environmentAndResources
* @memberof module:types * @memberof module:types
* *
* @property {module:types.environment} environment * @property {module:types.environment} environment
* @property {module:types.frontends} frontends
* @property {module:types.shares} shares * @property {module:types.shares} shares
*/ */
/**
* @typedef frontend
* @memberof module:types
*
* @property {string} shrToken
* @property {string} zId
* @property {number} createdAt
* @property {number} updatedAt
*/
/** /**
* @typedef inviteTokenGenerateRequest * @typedef inviteTokenGenerateRequest
* @memberof module:types * @memberof module:types
@ -148,7 +159,7 @@
* @memberof module:types * @memberof module:types
* *
* @property {boolean} accountLimited * @property {boolean} accountLimited
* @property {module:types.environmentSharesList} environments * @property {module:types.environmentAndResources[]} environments
*/ */
/** /**