|
10 | 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
11 | 11 | # ANY KIND, either express or implied. See the License for the specific
|
12 | 12 | # language governing permissions and limitations under the License.
|
13 |
| -"""Decorators for use with caching library """ |
| 13 | +"""Decorators for use with caching library""" |
| 14 | + |
14 | 15 | import json
|
15 | 16 |
|
16 | 17 |
|
@@ -40,12 +41,12 @@ def __call__(self, func):
|
40 | 41 | :return The function with the injected argument.
|
41 | 42 | """
|
42 | 43 |
|
43 |
| - secret = self.cache.get_secret_string(secret_id=self.secret_id) |
44 |
| - |
45 | 44 | def _wrapped_func(*args, **kwargs):
|
46 | 45 | """
|
47 | 46 | Internal function to execute wrapped function
|
48 | 47 | """
|
| 48 | + secret = self.cache.get_secret_string(secret_id=self.secret_id) |
| 49 | + |
49 | 50 | return func(secret, *args, **kwargs)
|
50 | 51 |
|
51 | 52 | return _wrapped_func
|
@@ -82,22 +83,26 @@ def __call__(self, func):
|
82 | 83 | :return The original function with injected keyword arguments
|
83 | 84 | """
|
84 | 85 |
|
85 |
| - try: |
86 |
| - secret = json.loads(self.cache.get_secret_string(secret_id=self.secret_id)) |
87 |
| - except json.decoder.JSONDecodeError: |
88 |
| - raise RuntimeError('Cached secret is not valid JSON') from None |
89 |
| - |
90 |
| - resolved_kwargs = {} |
91 |
| - for orig_kwarg, secret_key in self.kwarg_map.items(): |
92 |
| - try: |
93 |
| - resolved_kwargs[orig_kwarg] = secret[secret_key] |
94 |
| - except KeyError: |
95 |
| - raise RuntimeError(f'Cached secret does not contain key {secret_key}') from None |
96 |
| - |
97 | 86 | def _wrapped_func(*args, **kwargs):
|
98 | 87 | """
|
99 | 88 | Internal function to execute wrapped function
|
100 | 89 | """
|
| 90 | + try: |
| 91 | + secret = json.loads( |
| 92 | + self.cache.get_secret_string(secret_id=self.secret_id) |
| 93 | + ) |
| 94 | + except json.decoder.JSONDecodeError: |
| 95 | + raise RuntimeError("Cached secret is not valid JSON") from None |
| 96 | + |
| 97 | + resolved_kwargs = {} |
| 98 | + for orig_kwarg, secret_key in self.kwarg_map.items(): |
| 99 | + try: |
| 100 | + resolved_kwargs[orig_kwarg] = secret[secret_key] |
| 101 | + except KeyError: |
| 102 | + raise RuntimeError( |
| 103 | + f"Cached secret does not contain key {secret_key}" |
| 104 | + ) from None |
| 105 | + |
101 | 106 | return func(*args, **resolved_kwargs, **kwargs)
|
102 | 107 |
|
103 | 108 | return _wrapped_func
|
0 commit comments