def _create_secrets(ctx, dot_secret_path):
    if os.path.isfile(dot_secret_path):
        dot_secret = DotEnv(dotenv_path=dot_secret_path)
        secret_config = dot_secret.dict()
        for secret_name, secret_value in secret_config.items():
            ctx.run(
                f"echo {secret_value} | docker secret create {secret_name} -")
Exemple #2
0
def load_env():
    env_path = os.environ.get('ENV_PATH', './.env')
    print(f"* Env Path: {env_path}")

    dotenv = DotEnv(env_path, verbose=False)
    dotenv_dict = dotenv.dict()
    print("* Loaded .env")
    for k, v in dotenv_dict.items():
        print(f'** {k}={v}')
    dotenv.set_as_environment_variables(override=True)
Exemple #3
0
def setup_environment_variables():
    """Called in every notebook to inject credentials to environment"""
    dot_env = DotEnv(find_dotenv())
    dot_env.set_as_environment_variables()
    info = (
        "API credentials have automatically been injected for your active subscriptions.  \n"
        + "The following environment variables are now available:\n" +
        _format_env_list(dot_env.dict().keys()) + "\n")

    user_dot_env_path = "~/custom.env"
    user_dot_env = DotEnv(os.path.expanduser(user_dot_env_path))
    # NOTE: override is not True by default in dotenv
    user_dot_env.set_as_environment_variables()
    user_vars = user_dot_env.dict()
    if user_vars:
        info += (
            f"The following additional environment variables have been loaded from `{user_dot_env_path}`:\n"
            + _format_env_list(user_vars.keys()))

    display(Markdown(info))
Exemple #4
0
def prepare(notebook_id: str, dev: bool = False):
    # Legacy. This will be removed in an upcoming release.

    # actual setup
    dot_env = DotEnv(find_dotenv())
    dot_env.set_as_environment_variables()

    # the rest displays information
    requirement_name_mapping = _get_requirement_name_mapping(dev=dev)
    notebook = _get_notebook(notebook_id, dev=dev)

    requirements = [
        requirement_name_mapping.get(req, req)
        for req in notebook.get("requirements", [])
    ]

    info = dedent(f"""
        ***Notebook Title***  
        {notebook['name']}
        
        ***Notebook Description***  
        {notebook['description']}
        
        """)

    if requirements:
        info += dedent("""
            ***Notebook Dependencies***  
            This notebook requires an active subscription to:
            """)
        info += "".join(f"* {req}\n" for req in requirements)

    info += dedent("""
        ---------
        
        *API credentials have automatically been injected for your active subscriptions.*
        
        The following environment variables are now available:
        """)
    info += "".join(f"* `{k}`\n" for k in dot_env.dict().keys())
    info += "\n-------------\n"

    display(Markdown(info))
with the same user id as your local account, e.g. "--user 1001"
"""

import os, shutil
import json
import csv
import datetime
import collections
import requests
from dotenv.main import find_dotenv, DotEnv
from xcube_geodb.core.geodb import GeoDBClient

dot_env = DotEnv("/working/.env")
dot_env.set_as_environment_variables()
geodb = GeoDBClient()
envs = dot_env.dict()

# Function to fetch all available dates for BYOD collections
# Make sure all appropiate collection ids are set in your docker environment
COLLECTIONS = [
    "N3_CUSTOM",
    "N3_CUSTOM_TSMNN",
    "E12C_NEW_MOTORWAY",
    "E12D_NEW_PRIMARYROADS",
    "ICEYE-E3",
    "ICEYE-E11",
    "ICEYE-E11A",
    "ICEYE-E12B",
    "ICEYE-E13B",
    "N3_CUSTOM_TRILATERAL",
    "N3_CUSTOM_TRILATERAL_TSMNN",
Exemple #6
0
import sys


def env_path():
    from pathlib import Path
    env_path = Path('..') / '.env'
    return env_path


if __name__ == '__main__':
    from dotenv.main import DotEnv

    env_path = env_path()
    print(f"* Env Path: {env_path}")

    dotenv = DotEnv(env_path, verbose=False)
    dotenv_dict = dotenv.dict()
    print("* Loaded .env")
    for k, v in dotenv_dict.items():
        print(f'** {k}={v}')
    dotenv.set_as_environment_variables(override=True)

    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?") from exc
    execute_from_command_line(sys.argv)
def _remove_secrets(ctx, dot_secret_path):
    if os.path.isfile(dot_secret_path):
        dot_secret = DotEnv(dotenv_path=dot_secret_path)
        secret_config = dot_secret.dict()
        for secret_name, secret_value in secret_config.items():
            ctx.run(f"docker secret rm {secret_name}")