Skip to content

Commit

Permalink
Merge pull request #668 from openziti/limit_classes_label
Browse files Browse the repository at this point in the history
Limit Class Label (#666)
  • Loading branch information
michaelquigley authored Jun 21, 2024
2 parents f47da1c + 3067635 commit 941b296
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
12 changes: 9 additions & 3 deletions controller/store/limitClass.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type BandwidthClass interface {

type LimitClass struct {
Model
Label *string
BackendMode *sdk.BackendMode
Environments int
Shares int
Expand Down Expand Up @@ -111,7 +112,12 @@ func (lc LimitClass) GetLimitAction() LimitAction {
}

func (lc LimitClass) String() string {
out := fmt.Sprintf("LimitClass<#%d", lc.Id)
out := "LimitClass<"
if lc.Label != nil && *lc.Label != "" {
out += "'" + *lc.Label + "'"
} else {
out += fmt.Sprintf("#%d", lc.Id)
}
if lc.BackendMode != nil {
out += fmt.Sprintf(", backendMode: '%s'", *lc.BackendMode)
}
Expand Down Expand Up @@ -149,12 +155,12 @@ func (lc LimitClass) String() string {
var _ BandwidthClass = (*LimitClass)(nil)

func (str *Store) CreateLimitClass(lc *LimitClass, trx *sqlx.Tx) (int, error) {
stmt, err := trx.Prepare("insert into limit_classes (backend_mode, environments, shares, reserved_shares, unique_names, share_frontends, period_minutes, rx_bytes, tx_bytes, total_bytes, limit_action) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) returning id")
stmt, err := trx.Prepare("insert into limit_classes (label, backend_mode, environments, shares, reserved_shares, unique_names, share_frontends, period_minutes, rx_bytes, tx_bytes, total_bytes, limit_action) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) returning id")
if err != nil {
return 0, errors.Wrap(err, "error preparing limit_classes insert statement")
}
var id int
if err := stmt.QueryRow(lc.BackendMode, lc.Environments, lc.Shares, lc.ReservedShares, lc.UniqueNames, lc.ShareFrontends, lc.PeriodMinutes, lc.RxBytes, lc.TxBytes, lc.TotalBytes, lc.LimitAction).Scan(&id); err != nil {
if err := stmt.QueryRow(lc.Label, lc.BackendMode, lc.Environments, lc.Shares, lc.ReservedShares, lc.UniqueNames, lc.ShareFrontends, lc.PeriodMinutes, lc.RxBytes, lc.TxBytes, lc.TotalBytes, lc.LimitAction).Scan(&id); err != nil {
return 0, errors.Wrap(err, "error executing limit_classes insert statement")
}
return id, nil
Expand Down
8 changes: 0 additions & 8 deletions controller/store/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ const (
WarningLimitAction LimitAction = "warning"
)

type LimitScope string

const (
AccountLimitScope LimitScope = "account"
EnvironmentLimitScope LimitScope = "environment"
ShareLimitScope LimitScope = "share"
)

type PermissionMode string

const (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- +migrate Up

alter table limit_classes add column label varchar(32);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- +migrate Up

alter table limit_classes add column label varchar(32);
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Limit classes are created by creating a record in the `limit_classes` table in t
```sql
CREATE TABLE public.limit_classes (
id integer NOT NULL,
label VARCHAR(32),
backend_mode public.backend_mode,
environments integer DEFAULT '-1'::integer NOT NULL,
shares integer DEFAULT '-1'::integer NOT NULL,
Expand Down

0 comments on commit 941b296

Please sign in to comment.