Stéphan Taljaard

    Stéphan Taljaard

    4 months ago
    Hi. How do you save (and read) dollar signs in a secret? I'm on Prefect Server, implemented in GCP. The secret comes from Google Secret Manager. I have a custom secret function that, in development, pulls the secret from my PC's environment variables. I develop on Windows. I now have a DB with a password containing dollar signs. Because of this line, I can't read the password out correctly. Thoughts? Example:
    import os
    from prefect.client import Secret
    
    secret_name = 'JSON_SECRET'
    # os.environ[
    #     f"PREFECT__CONTEXT__SECRETS__{secret_name}"
    # ] = '{"db1": {"password": "password", "user": "userA"}, "db2": {"password": "P@$$w0rd", "user": "userB"}}'
    
    secret_value = Secret(secret_name).get()
    print(secret_value['db2']['password'])
    # This prints 'P@$w0rd', not 'P@$$w0rd'
    I have another function that then takes the username and password and creates a SQLAlchemy connection string:
    def create_conn_str(
        username: str, password: str, host: str, database: str, port=None, dialect="mssql", driver="pymssql"
    ) -> str:
        """Create a SQLAlchemy database URL connection string"""
        username_ = quote_plus(username)
        password_ = quote_plus(password)
        port_ = f":{port}" if port else ""
        return f"{dialect}+{driver}://{username_}:{password_}@{host}{port_}/{database}"
    Is my best option to save the value in the secret already url encoded (i.e.
    'P%40%24%24w0rd'
    ), and then edit my
    create_conn_str
    to not "double encode" a string?
    Kevin Kho

    Kevin Kho

    3 months ago
    Yikes that does seem like a pain. First time I’ve bumped into it. I think your suggestion with already saving it as URL encoded is the best I can think of for now.
    Stéphan Taljaard

    Stéphan Taljaard

    3 months ago
    Yeah same. Feels almost strange that this only came out now. It was actually someone else in my team discovering it. He first thought he's saving it wrong inside Windows env vars. Debugged for him and voila.
    Kevin Kho

    Kevin Kho

    3 months ago
    I don’t know though if we can have both dollar signs and the interpolation though. Feel free to open an issue.