@@ -22,57 +22,36 @@ func (a Action) IsChildResource() bool {
2222 return len (items ) == 4
2323}
2424
25- type ActionType int
25+ type ActionType string
2626
2727// Actions are ordered in increasing severity.
2828// If case of several options, action with highest severity wins.
2929// Note, Create/Delete are handled explicitly and never compared.
3030const (
31- ActionTypeUndefined ActionType = iota
32- ActionTypeSkip
33- ActionTypeResize
34- ActionTypeUpdate
35- ActionTypeUpdateWithID
36- ActionTypeCreate
37- ActionTypeRecreate
38- ActionTypeDelete
31+ Undefined ActionType = ""
32+ Skip ActionType = "skip"
33+ Resize ActionType = "resize"
34+ Update ActionType = "update"
35+ UpdateWithID ActionType = "update_id"
36+ Create ActionType = "create"
37+ Recreate ActionType = "recreate"
38+ Delete ActionType = "delete"
3939)
4040
41- const (
42- ActionTypeUndefinedString = ""
43- ActionTypeSkipString = "skip"
44- ActionTypeResizeString = "resize"
45- ActionTypeUpdateString = "update"
46- ActionTypeUpdateWithIDString = "update_id"
47- ActionTypeCreateString = "create"
48- ActionTypeRecreateString = "recreate"
49- ActionTypeDeleteString = "delete"
50- )
51-
52- var actionName = map [ActionType ]string {
53- ActionTypeSkip : ActionTypeSkipString ,
54- ActionTypeResize : ActionTypeResizeString ,
55- ActionTypeUpdate : ActionTypeUpdateString ,
56- ActionTypeUpdateWithID : ActionTypeUpdateWithIDString ,
57- ActionTypeCreate : ActionTypeCreateString ,
58- ActionTypeRecreate : ActionTypeRecreateString ,
59- ActionTypeDelete : ActionTypeDeleteString ,
60- }
61-
62- var nameToAction = map [string ]ActionType {}
63-
64- func init () {
65- for k , v := range actionName {
66- if _ , ok := nameToAction [v ]; ok {
67- panic ("duplicate action string: " + v )
68- }
69- nameToAction [v ] = k
70- }
41+ var actionOrder = map [ActionType ]int {
42+ Undefined : 0 ,
43+ Skip : 1 ,
44+ Resize : 2 ,
45+ Update : 3 ,
46+ UpdateWithID : 4 ,
47+ Create : 5 ,
48+ Recreate : 6 ,
49+ Delete : 7 ,
7150}
7251
7352func (a ActionType ) KeepsID () bool {
7453 switch a {
75- case ActionTypeCreate , ActionTypeUpdateWithID , ActionTypeRecreate , ActionTypeDelete :
54+ case Create , UpdateWithID , Recreate , Delete :
7655 return false
7756 default :
7857 return true
@@ -81,30 +60,15 @@ func (a ActionType) KeepsID() bool {
8160
8261// StringShort short version of action string, without suffix
8362func (a ActionType ) StringShort () string {
84- items := strings .SplitN (actionName [ a ] , "_" , 2 )
63+ items := strings .SplitN (string ( a ) , "_" , 2 )
8564 return items [0 ]
8665}
8766
88- // String returns the string representation of the action type.
89- func (a ActionType ) String () string {
90- return actionName [a ]
91- }
92-
93- func ActionTypeFromString (s string ) ActionType {
94- actionType , ok := nameToAction [s ]
95- if ! ok {
96- return ActionTypeUndefined
97- }
98- return actionType
99- }
100-
101- // Filter returns actions that match the specified action type
102- func Filter (changes []Action , actionType ActionType ) []Action {
103- var result []Action
104- for _ , action := range changes {
105- if action .ActionType == actionType {
106- result = append (result , action )
107- }
67+ // GetHigherAction returns the action with higher severity between a and b.
68+ // Actions are ordered by severity in actionOrder map.
69+ func GetHigherAction (a , b ActionType ) ActionType {
70+ if actionOrder [a ] > actionOrder [b ] {
71+ return a
10872 }
109- return result
73+ return b
11074}
0 commit comments