airbytehq / airbyte

The leading data integration platform for ETL / ELT data pipelines from APIs, databases & files to data warehouses, data lakes & data lakehouses. Both self-hosted and Cloud-hosted.
https://airbyte.com
Other
15.77k stars 4.04k forks source link

Low code connectors: Implement Base64Authenticator #12974

Closed girarda closed 2 years ago

girarda commented 2 years ago

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 (eg latin1 or utf-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:

girarda commented 2 years ago

grooming notes:

girarda commented 2 years ago

notes on how this can be done if we do the encoding/decoding directly in jinja:

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']) }}"