Closed girarda closed 2 years ago
grooming notes:
notes on how this can be done if we do the encoding/decoding directly in jinja:
"{{ base64(encode(config['username'] + ':' + config['password'], 'latin1'), 'ascii') }}"
"{{ base64(encode(config['token'] + ':', 'utf8'), 'utf8') }}"
"{{ base64(encode(config['username'] + ':' + config['password'], 'latin1'), 'ascii') }}"
(same as amplitude)"{{ base64(encode(config['token'] + ':', 'utf8'), 'utf8') }}"
(same as chartmogul)"{{ base64(encode(config['username'] + ':' + config['password'], 'utf8'), 'utf8') }}"
refresh_access_token_headers
:
{"Authorization": "{{ 'Basic' + {{ base64(encode(config['username'] + ':' + config['password'], 'ascii'), 'ascii') }}" }"{{ base64(encode(config['token'] + ':', 'utf8'), 'ascii') }}"
(note that this would probably work with decoding to uft-8)"{{ base64(encode(config['username'] + ':' + config['password'], 'latin1'), 'ascii') }}"
(same as amplitude)"{{ base64(encode(config['username'] + ':' + config['password'], 'utf8'), 'utf8') }}"
"{{ base64(encode(config['token'] + ':', 'utf8'), 'utf8') }}"
(same as freshservice)I ran a few tests and the base64 form is the same with utf8, ascii, and latin1, so it should be safe to always default to utf8. The template string could then look like:
"{{ base64(config['username'] + ':' + config['password']) }}"
where we'll do the encoding/decoding behind the scene.
The function should look like
self._environment.globals["base64"] = lambda s: b64encode(s.encode("utf8")).decode("utf8")
and the config like:
authenticator:
class_name: TokenAuthenticator
token: "{{ base64(config['username'] + ':' + config['password']) }}"
What
Some sources (eg amplitude) need a TokenAuthenticator where the token is the base64 representation of
"{username}:{password}"
where the username and password are encoded in specified encoding (eglatin1
orutf-8
)As it currently stands, this encoding is done in the connector's package, but the logic is always the same, so we should move it to a common package. A simple solution would be to wrap the authenticators with a configurable encoding layer. The authenticators to wrap would be
Here are the instances: