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
|
||||
|
||||
import (
|
||||
"github.com/openziti/zrok/controller/limits"
|
||||
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
||||
"time"
|
||||
|
||||
@ -17,12 +18,12 @@ type Config struct {
|
||||
Endpoint *EndpointConfig
|
||||
Email *EmailConfig
|
||||
Influx *InfluxConfig
|
||||
Limits *LimitsConfig
|
||||
Limits *limits.Config
|
||||
Maintenance *MaintenanceConfig
|
||||
Registration *RegistrationConfig
|
||||
ResetPassword *ResetPasswordConfig
|
||||
Store *store.Config
|
||||
Ziti *zrokEdgeSdk.ZitiConfig
|
||||
Ziti *zrokEdgeSdk.Config
|
||||
}
|
||||
|
||||
type AdminConfig struct {
|
||||
@ -76,19 +77,9 @@ type ResetPasswordMaintenanceConfig struct {
|
||||
BatchLimit int
|
||||
}
|
||||
|
||||
const Unlimited = -1
|
||||
|
||||
type LimitsConfig struct {
|
||||
Environments int
|
||||
Shares int
|
||||
}
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
Limits: &LimitsConfig{
|
||||
Environments: Unlimited,
|
||||
Shares: Unlimited,
|
||||
},
|
||||
Limits: limits.DefaultConfig(),
|
||||
Maintenance: &MaintenanceConfig{
|
||||
ResetPassword: &ResetPasswordMaintenanceConfig{
|
||||
ExpirationTimeout: time.Minute * 15,
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/openziti/zrok/controller/limits"
|
||||
"github.com/openziti/zrok/controller/store"
|
||||
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
||||
"github.com/openziti/zrok/rest_model_zrok"
|
||||
@ -14,10 +15,10 @@ import (
|
||||
)
|
||||
|
||||
type enableHandler struct {
|
||||
cfg *LimitsConfig
|
||||
cfg *limits.Config
|
||||
}
|
||||
|
||||
func newEnableHandler(cfg *LimitsConfig) *enableHandler {
|
||||
func newEnableHandler(cfg *limits.Config) *enableHandler {
|
||||
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 {
|
||||
if !principal.Limitless && h.cfg.Environments > Unlimited {
|
||||
if !principal.Limitless && h.cfg.Environments > limits.Unlimited {
|
||||
envs, err := str.FindEnvironmentsForAccount(int(principal.ID), tx)
|
||||
if err != nil {
|
||||
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 (
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/openziti/zrok/controller/limits"
|
||||
"github.com/openziti/zrok/controller/store"
|
||||
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
||||
"github.com/openziti/zrok/rest_model_zrok"
|
||||
@ -12,10 +13,10 @@ import (
|
||||
)
|
||||
|
||||
type shareHandler struct {
|
||||
cfg *LimitsConfig
|
||||
cfg *limits.Config
|
||||
}
|
||||
|
||||
func newShareHandler(cfg *LimitsConfig) *shareHandler {
|
||||
func newShareHandler(cfg *limits.Config) *shareHandler {
|
||||
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 {
|
||||
if !principal.Limitless && h.cfg.Shares > Unlimited {
|
||||
if !principal.Limitless && h.cfg.Shares > limits.Unlimited {
|
||||
total := 0
|
||||
for i := range envs {
|
||||
shrs, err := str.FindSharesForEnvironment(envs[i].Id, tx)
|
||||
|
@ -6,13 +6,13 @@ import (
|
||||
"github.com/openziti/edge/rest_util"
|
||||
)
|
||||
|
||||
type ZitiConfig struct {
|
||||
type Config struct {
|
||||
ApiEndpoint string
|
||||
Username string
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Loading…
Reference in New Issue
Block a user