Barski-lab / cwl-airflow

Python package to extend Airflow functionality with CWL1.1 support
https://barski-lab.github.io/cwl-airflow
Apache License 2.0
185 stars 32 forks source link

Possible bug when uncompressing workflow content #62

Closed michael-kotliar closed 2 years ago

michael-kotliar commented 3 years ago

Added + b'=='

def get_uncompressed(data_str, parse_as_yaml=None):
    """
    Converts character string "data_str" as "utf-8" into bytes, then
    decodes it as "base64" and decompress with gzip/zlib. The resulted
    "bytes" are converted again into standard for Python3 "utf-8"
    string. Raises zlib.error or binascii.Error if something went
    wrong. If "parse_as_yaml" is True, try to load uncompressed
    content with "load_yaml". The latter may raise ValueError or
    YAMLError if something went wrong. Need to use zlib to make it
    backward compatible with the zlib compressed DAGs
    """

    parse_as_yaml = False if parse_as_yaml is None else parse_as_yaml
    try:
        uncompressed = gzip.decompress(
            base64.b64decode(
                data_str.encode("utf-8") + b'=='
            )
        ).decode("utf-8")
    except Exception:
        uncompressed = zlib.decompress(
            base64.b64decode(
                data_str.encode("utf-8") + b'=='
            )
        ).decode("utf-8")
    return load_yaml(uncompressed) if parse_as_yaml else uncompressed