Ejemplo n.º 1
0
def _srv_env(conn, path):
    mapping = {}

    with tempfile.NamedTemporaryFile() as f:
        conn.get(path, f.name)
        speckenv.read_speckenv(f.name, mapping=mapping)

    return lambda *a, **kw: speckenv.env(*a, **kw, mapping=mapping)
Ejemplo n.º 2
0
def default_env(*args, **kwargs):
    if not getattr(default_env, "_loaded", False):
        path = os.path.join(os.path.expanduser("~"), ".box.env")
        if os.path.isfile(path):
            speckenv.read_speckenv(path)

        default_env._loaded = True

    return speckenv.env(*args, **kwargs)
Ejemplo n.º 3
0
def remote_env(*args, **kwargs):
    global REMOTE_ENV

    if REMOTE_ENV is None:
        REMOTE_ENV = {}
        with TemporaryDirectory() as d:
            get("%(box_domain)s/.env" % env, d)
            speckenv.read_speckenv(os.path.join(d, ".env"), mapping=REMOTE_ENV)

    kwargs["mapping"] = REMOTE_ENV
    return speckenv.env(*args, **kwargs)
Ejemplo n.º 4
0
def default_env(*args, **kwargs):
    if not getattr(default_env, '_loaded', False):
        path = os.path.join(
            os.path.expanduser('~'),
            '.box.env',
        )
        if os.path.isfile(path):
            speckenv.read_speckenv(path)

        default_env._loaded = True

    return speckenv.env(*args, **kwargs)
Ejemplo n.º 5
0
    def test_custom_mapping(self):
        mapping = {}
        with tempfile.NamedTemporaryFile() as f:
            f.write(b"""
CUSTOM_MAPPING=yes
""")

            f.seek(0)

            speckenv.read_speckenv(f.name, mapping=mapping)

        self.assertNotIn("CUSTOM_MAPPING", os.environ)

        self.assertEqual(speckenv.env("CUSTOM_MAPPING", mapping=mapping),
                         "yes")
Ejemplo n.º 6
0
    def test_no_file(self):
        i = 0
        while True:
            filename = f"env-{i}"
            if not os.path.exists(filename):
                break
            i = i + 1  # pragma: no cover

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            speckenv.read_speckenv(filename)

            self.assertEqual(len(w), 1)
            self.assertIn(
                f"{filename} not a file, not reading anything",
                f"{w[0].message}",
            )
Ejemplo n.º 7
0
    def setUp(self):
        with tempfile.NamedTemporaryFile() as f:
            f.write(b"""
DATABASE_URL=postgres://localhost:5432/example_com
ALLOWED_HOSTS=['*']

# COMMENTED=yes
COMMENTED=no
COMMENTED=ignored

COMMENT_STR=value  # TEST
COMMENT_STR_QUOTED="value  # TEST"
COMMENT_INT=42  # TEST

NO_EQUAL_SIGN
""")

            f.seek(0)

            speckenv.read_speckenv(f.name)
Ejemplo n.º 8
0
import os

from django.core.wsgi import get_wsgi_application

import speckenv

speckenv.read_speckenv(filename=os.environ.get("DOTENV", ".env"))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "workbench.settings")
application = get_wsgi_application()
Ejemplo n.º 9
0
from datetime import datetime
import re
import requests
from speckenv import read_speckenv, env

read_speckenv()
token = env('TOKEN', required=True)
groups = [group.split(':') for group in env('GROUPS', required=True).split()]


def users():
    response = requests.get(
        'https://slack.com/api/users.list',
        params={
            'token': token,
            'limit': 1000,
            'presence': 'false',
        },
    ).json()

    return {member['id']: member['name'] for member in response['members']}


def fetch(channel):
    response = requests.get(
        'https://slack.com/api/conversations.history',
        params={
            'token': token,
            'channel': channel,
            'count': 1000,
            'oldest': datetime.now().timestamp() - 86400 - 3600,
Ejemplo n.º 10
0
#!/usr/bin/env python
import os
import sys

import speckenv


if __name__ == "__main__":  # pragma: no branch
    BASE_DIR = os.path.dirname(__file__)

    speckenv.read_speckenv(
        filename=os.path.join(BASE_DIR, os.environ.get("DOTENV", ".env"))
    )
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "workbench.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)
Ejemplo n.º 11
0
def _local_env(path=".env"):
    mapping = {}
    speckenv.read_speckenv(config.base / path, mapping=mapping)

    return lambda *a, **kw: speckenv.env(*a, **kw, mapping=mapping)