(idx int, cachedExprEnv map[string]any, logger *log.Entry, debug bool)
| 99 | } |
| 100 | |
| 101 | func (rs *RuntimeStash) Apply(idx int, cachedExprEnv map[string]any, logger *log.Entry, debug bool) { |
| 102 | var ( |
| 103 | key string |
| 104 | value string |
| 105 | ) |
| 106 | |
| 107 | if rs.ValueExpression == nil { |
| 108 | logger.Warningf("Stash %d has no value expression, skipping", idx) |
| 109 | return |
| 110 | } |
| 111 | |
| 112 | if rs.KeyExpression == nil { |
| 113 | logger.Warningf("Stash %d has no key expression, skipping", idx) |
| 114 | return |
| 115 | } |
| 116 | // collect the data |
| 117 | output, err := exprhelpers.Run(rs.ValueExpression, cachedExprEnv, logger, debug) |
| 118 | if err != nil { |
| 119 | logger.Warningf("Error while running stash val expression: %v", err) |
| 120 | } |
| 121 | // can we expect anything else than a string ? |
| 122 | switch output := output.(type) { |
| 123 | case string: |
| 124 | value = output |
| 125 | default: |
| 126 | logger.Warningf("unexpected type %T (%v) while running %q", output, output, rs.Config.Value) |
| 127 | return |
| 128 | } |
| 129 | |
| 130 | // collect the key |
| 131 | output, err = exprhelpers.Run(rs.KeyExpression, cachedExprEnv, logger, debug) |
| 132 | if err != nil { |
| 133 | logger.Warningf("Error while running stash key expression: %v", err) |
| 134 | } |
| 135 | // can we expect anything else than a string ? |
| 136 | switch output := output.(type) { |
| 137 | case string: |
| 138 | key = output |
| 139 | default: |
| 140 | logger.Warningf("unexpected type %T (%v) while running %q", output, output, rs.Config.Key) |
| 141 | return |
| 142 | } |
| 143 | |
| 144 | if err = cache.SetKey(rs.Config.Name, key, value, &rs.TTLVal); err != nil { |
| 145 | logger.Warningf("failed to store data in cache: %s", err.Error()) |
| 146 | } |
| 147 | } |
no test coverage detected