@@ -8,23 +8,49 @@ import "fmt"
88type Operation int
99
1010func (op Operation ) String () string {
11- if (int (op ) < 0 ) || (int (op ) == len (OperationNames )) {
12- return fmt .Sprintf ("UnknownOperation(%d)" , op )
11+ switch op {
12+ case OpViewClient :
13+ return OpViewClientStr
14+ case OpUpdateClient :
15+ return OpUpdateClientStr
16+ case OpUpdateClientTags :
17+ return OpUpdateClientTagsStr
18+ case OpUpdateClientSecret :
19+ return OpUpdateClientSecretStr
20+ case OpEnableClient :
21+ return OpEnableClientStr
22+ case OpDisableClient :
23+ return OpDisableClientStr
24+ case OpDeleteClient :
25+ return OpDeleteClientStr
26+ case OpSetParentGroup :
27+ return OpSetParentGroupStr
28+ case OpRemoveParentGroup :
29+ return OpRemoveParentGroupStr
30+ case OpConnectToChannel :
31+ return OpConnectToChannelStr
32+ case OpDisconnectFromChannel :
33+ return OpDisconnectFromChannelStr
34+ case OpCreateClient :
35+ return OpCreateClientStr
36+ case OpListClients :
37+ return OpListClientsStr
38+ case OpListUserClients :
39+ return OpListUserClientsStr
40+ default :
41+ return fmt .Sprintf ("unknown operation: %d" , op )
1342 }
14- return OperationNames [op ]
1543}
1644
1745type OperationPerm struct {
1846 opPerm map [Operation ]Permission
1947 expectedOps []Operation
20- opNames []string
2148}
2249
23- func newOperationPerm (expectedOps []Operation , opNames [] string ) OperationPerm {
50+ func newOperationPerm (expectedOps []Operation ) OperationPerm {
2451 return OperationPerm {
2552 opPerm : make (map [Operation ]Permission ),
2653 expectedOps : expectedOps ,
27- opNames : opNames ,
2854 }
2955}
3056
@@ -87,24 +113,42 @@ func (p Permission) String() string {
87113
88114type ExternalOperation int
89115
90- func (op ExternalOperation ) String (operations []string ) string {
91- if (int (op ) < 0 ) || (int (op ) == len (operations )) {
92- return fmt .Sprintf ("UnknownOperation(%d)" , op )
116+ // func (op ExternalOperation) String(operations []string) string {
117+ // if (int(op) < 0) || (int(op) == len(operations)) {
118+ // return fmt.Sprintf("UnknownOperation(%d)", op)
119+ // }
120+ // return operations[op]
121+ // }
122+
123+ func (op ExternalOperation ) String () string {
124+ switch op {
125+ case DomainOpCreateClient :
126+ return DomainOpCreateClientStr
127+ case DomainOpListClients :
128+ return DomainOpListClientsStr
129+ case GroupOpSetChildClient :
130+ return GroupOpSetChildClientStr
131+ case GroupsOpRemoveChildClient :
132+ return GroupsOpRemoveChildClientStr
133+ case ChannelsOpConnectChannel :
134+ return ChannelsOpConnectChannelStr
135+ case ChannelsOpDisconnectChannel :
136+ return ChannelsOpDisconnectChannelStr
137+ default :
138+ return fmt .Sprintf ("unknown external operation: %d" , op )
93139 }
94- return operations [op ]
95140}
96141
97142type ExternalOperationPerm struct {
98143 opPerm map [ExternalOperation ]Permission
99144 expectedOps []ExternalOperation
100- opNames []string
145+ // opNames []string
101146}
102147
103- func newExternalOperationPerm (expectedOps []ExternalOperation , opNames [] string ) ExternalOperationPerm {
148+ func newExternalOperationPerm (expectedOps []ExternalOperation ) ExternalOperationPerm {
104149 return ExternalOperationPerm {
105150 opPerm : make (map [ExternalOperation ]Permission ),
106151 expectedOps : expectedOps ,
107- opNames : opNames ,
108152 }
109153}
110154
@@ -121,7 +165,7 @@ func (eopp ExternalOperationPerm) AddOperationPermissionMap(eopMap map[ExternalO
121165 // First iteration check all the keys are valid, If any one key is invalid then no key should be added.
122166 for eop := range eopMap {
123167 if ! eopp .isKeyRequired (eop ) {
124- return fmt .Errorf ("%v is not a valid external operation" , eop .String (eopp . opNames ))
168+ return fmt .Errorf ("%v is not a valid external operation" , eop .String ())
125169 }
126170 }
127171 for eop , perm := range eopMap {
@@ -133,12 +177,12 @@ func (eopp ExternalOperationPerm) AddOperationPermissionMap(eopMap map[ExternalO
133177func (eopp ExternalOperationPerm ) Validate () error {
134178 for eop := range eopp .opPerm {
135179 if ! eopp .isKeyRequired (eop ) {
136- return fmt .Errorf ("ExternalOperationPerm: \" %s\" is not a valid external operation" , eop .String (eopp . opNames ))
180+ return fmt .Errorf ("ExternalOperationPerm: \" %s\" is not a valid external operation" , eop .String ())
137181 }
138182 }
139183 for _ , eeo := range eopp .expectedOps {
140184 if _ , ok := eopp .opPerm [eeo ]; ! ok {
141- return fmt .Errorf ("ExternalOperationPerm: \" %s\" external operation is missing" , eeo .String (eopp . opNames ))
185+ return fmt .Errorf ("ExternalOperationPerm: \" %s\" external operation is missing" , eeo .String ())
142186 }
143187 }
144188 return nil
@@ -148,5 +192,5 @@ func (eopp ExternalOperationPerm) GetPermission(eop ExternalOperation) (Permissi
148192 if perm , ok := eopp .opPerm [eop ]; ok {
149193 return perm , nil
150194 }
151- return "" , fmt .Errorf ("external operation \" %s\" doesn't have any permissions" , eop .String (eopp . opNames ))
195+ return "" , fmt .Errorf ("external operation \" %s\" doesn't have any permissions" , eop .String ())
152196}
0 commit comments