|
| 1 | +/* |
| 2 | +Copyright 2025 HAProxy Technologies |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package actions |
| 18 | + |
| 19 | +import ( |
| 20 | + stderrors "errors" |
| 21 | + "strings" |
| 22 | + |
| 23 | + "github.com/haproxytech/client-native/v6/config-parser/common" |
| 24 | + "github.com/haproxytech/client-native/v6/config-parser/errors" |
| 25 | + "github.com/haproxytech/client-native/v6/config-parser/types" |
| 26 | +) |
| 27 | + |
| 28 | +type Pause struct { |
| 29 | + Pause common.Expression |
| 30 | + Cond string |
| 31 | + CondTest string |
| 32 | + Comment string |
| 33 | +} |
| 34 | + |
| 35 | +func (f *Pause) Parse(parts []string, parserType types.ParserType, comment string) error { |
| 36 | + if comment != "" { |
| 37 | + f.Comment = comment |
| 38 | + } |
| 39 | + if len(parts) >= 3 { |
| 40 | + command, condition := common.SplitRequest(parts[2:]) |
| 41 | + if len(command) == 0 { |
| 42 | + return errors.ErrInvalidData |
| 43 | + } |
| 44 | + pauseExpr := common.Expression{} |
| 45 | + if err := pauseExpr.Parse(command); err != nil { |
| 46 | + return stderrors.New("not enough params") |
| 47 | + } |
| 48 | + f.Pause = pauseExpr |
| 49 | + if len(condition) > 1 { |
| 50 | + f.Cond = condition[0] |
| 51 | + f.CondTest = strings.Join(condition[1:], " ") |
| 52 | + } |
| 53 | + return nil |
| 54 | + } |
| 55 | + return stderrors.New("not enough params") |
| 56 | +} |
| 57 | + |
| 58 | +func (f *Pause) String() string { |
| 59 | + var result strings.Builder |
| 60 | + result.WriteString("pause ") |
| 61 | + result.WriteString(f.Pause.String()) |
| 62 | + if f.Cond != "" { |
| 63 | + result.WriteString(" ") |
| 64 | + result.WriteString(f.Cond) |
| 65 | + result.WriteString(" ") |
| 66 | + result.WriteString(f.CondTest) |
| 67 | + } |
| 68 | + return result.String() |
| 69 | +} |
| 70 | + |
| 71 | +func (f *Pause) GetComment() string { |
| 72 | + return f.Comment |
| 73 | +} |
0 commit comments