Skip to content

Commit ab891ec

Browse files
committed
Added b64 encode/decode filters
1 parent 4a361ba commit ab891ec

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

ecs_files_composer/input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# generated by datamodel-codegen:
22
# filename: ecs-files-input.json
3-
# timestamp: 2023-02-28T08:48:36+00:00
3+
# timestamp: 2023-04-03T09:06:05+00:00
44

55
from __future__ import annotations
66

ecs_files_composer/jinja2_filters/__init__.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
import json
88
import re
9+
from base64 import b64decode, b64encode
910
from os import environ
1011

1112
import requests
@@ -144,6 +145,19 @@ def to_json(value, indent=2):
144145
return json.dumps(value, indent=indent)
145146

146147

148+
def base64encode(value: str):
149+
"""Return value base64 encoded"""
150+
try:
151+
return b64encode(value).decode("utf-8")
152+
except TypeError:
153+
return b64encode(value.encode("utf-8")).decode("utf-8")
154+
155+
156+
def base64decode(value) -> bytes:
157+
"""Decodes base64 encoded value"""
158+
return b64decode(value)
159+
160+
147161
def env_var(key, value=None):
148162
return environ.get(key, value)
149163

@@ -206,4 +220,10 @@ def hostname(alternative_value: str = None) -> str:
206220
"hostname": hostname,
207221
}
208222

209-
JINJA_FILTERS = {"to_yaml": to_yaml, "to_json": to_json, "env_override": env_override}
223+
JINJA_FILTERS = {
224+
"to_yaml": to_yaml,
225+
"to_json": to_json,
226+
"env_override": env_override,
227+
"base64encode": base64encode,
228+
"base64decode": base64decode,
229+
}

0 commit comments

Comments
 (0)