resources: Parse YAML infinity specifications correctly
This makes it easier to specify an infinite rate.
This commit is contained in:
13
examples/file5.yaml
Normal file
13
examples/file5.yaml
Normal file
@@ -0,0 +1,13 @@
|
||||
---
|
||||
graph: mygraph
|
||||
resources:
|
||||
file:
|
||||
- name: file1
|
||||
meta:
|
||||
limit: .inf
|
||||
burst: 0
|
||||
path: "/tmp/mgmt/hello"
|
||||
content: |
|
||||
i am a file
|
||||
state: exists
|
||||
edges: []
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
"path"
|
||||
"sync"
|
||||
@@ -272,7 +273,8 @@ func (obj *BaseUID) Reversed() bool {
|
||||
|
||||
// Validate reports any problems with the struct definition.
|
||||
func (obj *BaseRes) Validate() error {
|
||||
if obj.Meta().Burst == 0 && !(obj.Meta().Limit == rate.Inf) { // blocked
|
||||
isInf := obj.Meta().Limit == rate.Inf || math.IsInf(float64(obj.Meta().Limit), 1)
|
||||
if obj.Meta().Burst == 0 && !isInf { // blocked
|
||||
return fmt.Errorf("Permanently limited (rate != Inf, burst: 0)")
|
||||
}
|
||||
return nil
|
||||
@@ -291,6 +293,9 @@ func (obj *BaseRes) Init() error {
|
||||
if obj.Meta().Burst == 0 && obj.Meta().Limit == 0 { // blocked
|
||||
obj.Meta().Limit = rate.Inf
|
||||
}
|
||||
if math.IsInf(float64(obj.Meta().Limit), 1) { // yaml `.inf` -> rate.Inf
|
||||
obj.Meta().Limit = rate.Inf
|
||||
}
|
||||
|
||||
//dir, err := obj.VarDir("")
|
||||
//if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user