mirror of
https://github.com/openziti/zrok.git
synced 2025-01-03 04:29:19 +01:00
roughed in limits model that incorporates bandwidth limit specs (#235)
This commit is contained in:
parent
86380d1836
commit
83ab21f00c
@ -1,6 +1,7 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/openziti/zrok/controller/limits"
|
||||||
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -17,12 +18,12 @@ type Config struct {
|
|||||||
Endpoint *EndpointConfig
|
Endpoint *EndpointConfig
|
||||||
Email *EmailConfig
|
Email *EmailConfig
|
||||||
Influx *InfluxConfig
|
Influx *InfluxConfig
|
||||||
Limits *LimitsConfig
|
Limits *limits.Config
|
||||||
Maintenance *MaintenanceConfig
|
Maintenance *MaintenanceConfig
|
||||||
Registration *RegistrationConfig
|
Registration *RegistrationConfig
|
||||||
ResetPassword *ResetPasswordConfig
|
ResetPassword *ResetPasswordConfig
|
||||||
Store *store.Config
|
Store *store.Config
|
||||||
Ziti *zrokEdgeSdk.ZitiConfig
|
Ziti *zrokEdgeSdk.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminConfig struct {
|
type AdminConfig struct {
|
||||||
@ -76,19 +77,9 @@ type ResetPasswordMaintenanceConfig struct {
|
|||||||
BatchLimit int
|
BatchLimit int
|
||||||
}
|
}
|
||||||
|
|
||||||
const Unlimited = -1
|
|
||||||
|
|
||||||
type LimitsConfig struct {
|
|
||||||
Environments int
|
|
||||||
Shares int
|
|
||||||
}
|
|
||||||
|
|
||||||
func DefaultConfig() *Config {
|
func DefaultConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
Limits: &LimitsConfig{
|
Limits: limits.DefaultConfig(),
|
||||||
Environments: Unlimited,
|
|
||||||
Shares: Unlimited,
|
|
||||||
},
|
|
||||||
Maintenance: &MaintenanceConfig{
|
Maintenance: &MaintenanceConfig{
|
||||||
ResetPassword: &ResetPasswordMaintenanceConfig{
|
ResetPassword: &ResetPasswordMaintenanceConfig{
|
||||||
ExpirationTimeout: time.Minute * 15,
|
ExpirationTimeout: time.Minute * 15,
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/go-openapi/runtime/middleware"
|
"github.com/go-openapi/runtime/middleware"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
|
"github.com/openziti/zrok/controller/limits"
|
||||||
"github.com/openziti/zrok/controller/store"
|
"github.com/openziti/zrok/controller/store"
|
||||||
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
||||||
"github.com/openziti/zrok/rest_model_zrok"
|
"github.com/openziti/zrok/rest_model_zrok"
|
||||||
@ -14,10 +15,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type enableHandler struct {
|
type enableHandler struct {
|
||||||
cfg *LimitsConfig
|
cfg *limits.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func newEnableHandler(cfg *LimitsConfig) *enableHandler {
|
func newEnableHandler(cfg *limits.Config) *enableHandler {
|
||||||
return &enableHandler{cfg: cfg}
|
return &enableHandler{cfg: cfg}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ func (h *enableHandler) Handle(params environment.EnableParams, principal *rest_
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *enableHandler) checkLimits(principal *rest_model_zrok.Principal, tx *sqlx.Tx) error {
|
func (h *enableHandler) checkLimits(principal *rest_model_zrok.Principal, tx *sqlx.Tx) error {
|
||||||
if !principal.Limitless && h.cfg.Environments > Unlimited {
|
if !principal.Limitless && h.cfg.Environments > limits.Unlimited {
|
||||||
envs, err := str.FindEnvironmentsForAccount(int(principal.ID), tx)
|
envs, err := str.FindEnvironmentsForAccount(int(principal.ID), tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Errorf("unable to find environments for account '%v': %v", principal.Email, err)
|
return errors.Errorf("unable to find environments for account '%v': %v", principal.Email, err)
|
||||||
|
51
controller/limits/model.go
Normal file
51
controller/limits/model.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package limits
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
const Unlimited = -1
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Environments int
|
||||||
|
Shares int
|
||||||
|
Bandwidth *BandwidthConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
type BandwidthConfig struct {
|
||||||
|
PerAccount *BandwidthPerPeriod
|
||||||
|
PerEnvironment *BandwidthPerPeriod
|
||||||
|
PerShare *BandwidthPerPeriod
|
||||||
|
}
|
||||||
|
|
||||||
|
type BandwidthPerPeriod struct {
|
||||||
|
Period time.Duration
|
||||||
|
Rx int64
|
||||||
|
Tx int64
|
||||||
|
Total int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func DefaultConfig() *Config {
|
||||||
|
return &Config{
|
||||||
|
Environments: Unlimited,
|
||||||
|
Shares: Unlimited,
|
||||||
|
Bandwidth: &BandwidthConfig{
|
||||||
|
PerAccount: &BandwidthPerPeriod{
|
||||||
|
Period: 365 * (24 * time.Hour),
|
||||||
|
Rx: Unlimited,
|
||||||
|
Tx: Unlimited,
|
||||||
|
Total: Unlimited,
|
||||||
|
},
|
||||||
|
PerEnvironment: &BandwidthPerPeriod{
|
||||||
|
Period: 365 * (24 * time.Hour),
|
||||||
|
Rx: Unlimited,
|
||||||
|
Tx: Unlimited,
|
||||||
|
Total: Unlimited,
|
||||||
|
},
|
||||||
|
PerShare: &BandwidthPerPeriod{
|
||||||
|
Period: 365 * (24 * time.Hour),
|
||||||
|
Rx: Unlimited,
|
||||||
|
Tx: Unlimited,
|
||||||
|
Total: Unlimited,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"github.com/go-openapi/runtime/middleware"
|
"github.com/go-openapi/runtime/middleware"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
|
"github.com/openziti/zrok/controller/limits"
|
||||||
"github.com/openziti/zrok/controller/store"
|
"github.com/openziti/zrok/controller/store"
|
||||||
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
||||||
"github.com/openziti/zrok/rest_model_zrok"
|
"github.com/openziti/zrok/rest_model_zrok"
|
||||||
@ -12,10 +13,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type shareHandler struct {
|
type shareHandler struct {
|
||||||
cfg *LimitsConfig
|
cfg *limits.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func newShareHandler(cfg *LimitsConfig) *shareHandler {
|
func newShareHandler(cfg *limits.Config) *shareHandler {
|
||||||
return &shareHandler{cfg: cfg}
|
return &shareHandler{cfg: cfg}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +145,7 @@ func (h *shareHandler) Handle(params share.ShareParams, principal *rest_model_zr
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *shareHandler) checkLimits(principal *rest_model_zrok.Principal, envs []*store.Environment, tx *sqlx.Tx) error {
|
func (h *shareHandler) checkLimits(principal *rest_model_zrok.Principal, envs []*store.Environment, tx *sqlx.Tx) error {
|
||||||
if !principal.Limitless && h.cfg.Shares > Unlimited {
|
if !principal.Limitless && h.cfg.Shares > limits.Unlimited {
|
||||||
total := 0
|
total := 0
|
||||||
for i := range envs {
|
for i := range envs {
|
||||||
shrs, err := str.FindSharesForEnvironment(envs[i].Id, tx)
|
shrs, err := str.FindSharesForEnvironment(envs[i].Id, tx)
|
||||||
|
@ -6,13 +6,13 @@ import (
|
|||||||
"github.com/openziti/edge/rest_util"
|
"github.com/openziti/edge/rest_util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ZitiConfig struct {
|
type Config struct {
|
||||||
ApiEndpoint string
|
ApiEndpoint string
|
||||||
Username string
|
Username string
|
||||||
Password string `cf:"+secret"`
|
Password string `cf:"+secret"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func Client(cfg *ZitiConfig) (*rest_management_api_client.ZitiEdgeManagement, error) {
|
func Client(cfg *Config) (*rest_management_api_client.ZitiEdgeManagement, error) {
|
||||||
caCerts, err := rest_util.GetControllerWellKnownCas(cfg.ApiEndpoint)
|
caCerts, err := rest_util.GetControllerWellKnownCas(cfg.ApiEndpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user