@@ -9,11 +9,12 @@ import (
99
1010// Validation errors returned by create or update operations.
1111var (
12- ErrNoName = errors .New ("Policy name cannot by empty." )
13- ErrNoArgs = errors .New ("Args cannot be nil for schedule policies." )
12+ ErrNoName = errors .New ("Policy name cannot be empty." )
13+ ErrNoSchedule = errors .New ("Schedule cannot be nil for schedule policies." )
1414 ErrCooldownRange = errors .New ("Cooldown is out of range (0, 86400)." )
1515 ErrUnknownType = errors .New ("Unknown policy type." )
1616 ErrUnknownAdjustment = errors .New ("Unknown adjustment type." )
17+ ErrEmptyCron = errors .New ("Cron argument cannot be empty." )
1718)
1819
1920// List returns all scaling policies for a group.
@@ -57,8 +58,9 @@ type CreateOpt struct {
5758 // an integer.
5859 AdjustmentValue float64
5960
60- // Additional configuration options for some types of policy.
61- Args map [string ]interface {}
61+ // Value determining Schedule policy behavior, or nil for Webhook policies.
62+ // This should be an appropriately configured Cron or an At value.
63+ Schedule ScheduleArgs
6264}
6365
6466// ToPolicyCreateMap converts a slice of CreateOpt structs into a map for use
@@ -71,8 +73,8 @@ func (opts CreateOpts) ToPolicyCreateMap() ([]map[string]interface{}, error) {
7173 return nil , ErrNoName
7274 }
7375
74- if o .Type == Schedule && o .Args == nil {
75- return nil , ErrNoArgs
76+ if o .Type == Schedule && o .Schedule == nil {
77+ return nil , ErrNoSchedule
7678 }
7779
7880 if ok := validateType (o .Type ); ! ok {
@@ -95,8 +97,14 @@ func (opts CreateOpts) ToPolicyCreateMap() ([]map[string]interface{}, error) {
9597 return nil , err
9698 }
9799
98- if o .Args != nil {
99- policy ["args" ] = o .Args
100+ if o .Schedule != nil {
101+ args , err := o .Schedule .ToPolicyArgs ()
102+
103+ if err != nil {
104+ return nil , err
105+ }
106+
107+ policy ["args" ] = args
100108 }
101109
102110 policies = append (policies , policy )
@@ -161,8 +169,9 @@ type UpdateOpts struct {
161169 // an integer.
162170 AdjustmentValue float64
163171
164- // Additional configuration options for some types of policy.
165- Args map [string ]interface {}
172+ // Value determining Schedule policy behavior, or nil for Webhook policies.
173+ // This should be an appropriately configured Cron or an At value.
174+ Schedule ScheduleArgs
166175}
167176
168177// ToPolicyUpdateMap converts an UpdateOpts struct into a map for use as the
@@ -172,8 +181,8 @@ func (opts UpdateOpts) ToPolicyUpdateMap() (map[string]interface{}, error) {
172181 return nil , ErrNoName
173182 }
174183
175- if opts .Type == Schedule && opts .Args == nil {
176- return nil , ErrNoArgs
184+ if opts .Type == Schedule && opts .Schedule == nil {
185+ return nil , ErrNoSchedule
177186 }
178187
179188 if ok := validateType (opts .Type ); ! ok {
@@ -196,8 +205,14 @@ func (opts UpdateOpts) ToPolicyUpdateMap() (map[string]interface{}, error) {
196205 return nil , err
197206 }
198207
199- if opts .Args != nil {
200- policy ["args" ] = opts .Args
208+ if opts .Schedule != nil {
209+ args , err := opts .Schedule .ToPolicyArgs ()
210+
211+ if err != nil {
212+ return nil , err
213+ }
214+
215+ policy ["args" ] = args
201216 }
202217
203218 return policy , nil
0 commit comments