AddNamedPolicy adds a named policy within the transaction. The policy is buffered and will be applied when the transaction is committed.
(ptype string, params ...interface{})
| 79 | // AddNamedPolicy adds a named policy within the transaction. |
| 80 | // The policy is buffered and will be applied when the transaction is committed. |
| 81 | func (tx *Transaction) AddNamedPolicy(ptype string, params ...interface{}) (bool, error) { |
| 82 | tx.mutex.Lock() |
| 83 | defer tx.mutex.Unlock() |
| 84 | |
| 85 | if err := tx.checkTransactionStatus(); err != nil { |
| 86 | return false, err |
| 87 | } |
| 88 | |
| 89 | rule := tx.buildRuleFromParams(params...) |
| 90 | |
| 91 | // Check if policy already exists in the buffered model. |
| 92 | bufferedModel, err := tx.buffer.ApplyOperationsToModel(tx.buffer.GetModelSnapshot()) |
| 93 | if err != nil { |
| 94 | return false, err |
| 95 | } |
| 96 | |
| 97 | hasPolicy, err := bufferedModel.HasPolicy("p", ptype, rule) |
| 98 | if hasPolicy || err != nil { |
| 99 | return false, err |
| 100 | } |
| 101 | |
| 102 | // Add operation to buffer. |
| 103 | op := persist.PolicyOperation{ |
| 104 | Type: persist.OperationAdd, |
| 105 | Section: "p", |
| 106 | PolicyType: ptype, |
| 107 | Rules: [][]string{rule}, |
| 108 | } |
| 109 | tx.buffer.AddOperation(op) |
| 110 | |
| 111 | return true, nil |
| 112 | } |
| 113 | |
| 114 | // AddPolicies adds multiple policies within the transaction. |
| 115 | func (tx *Transaction) AddPolicies(rules [][]string) (bool, error) { |
no test coverage detected