def fetch(stdout=True) -> Inventory: args = parser.parse_args() formatter = Formatter( project=from_env("DO_PROJECT"), env=from_env("DO_ENV"), ssh_dir=from_env("DO_SSH_DIR"), ) manager = Manager( token=from_env("DO_ACCESS_TOKEN"), private_ips=args.private_ips, formatter=formatter, ) inventory = Inventory( lst=args.list, host=args.host, manager=manager, debug=args.debug, ) if stdout: print(inventory) return inventory
def update_projects(): owner = from_env("GITHUB_HANDLE") names = lambda x: {i.name if hasattr(i, "name") else i["name"] for i in x} try: projects = fetch_public_projects(owner) existing = Project.objects.filter(Q(name__in=names(projects))) former = Project.objects.filter(~Q(name__in=names(projects))) logger.info({ "retrieved": names(projects), "create": names(projects) - names(existing), "update": names(existing), "delete": names(former), }) for i in projects: Project.objects.update_or_create(name=i["name"], defaults=i) former.delete() except Exception as e: logger.critical(e)
from safe_environ import from_env from .base import * DEBUG = False SECRET_KEY = from_env("SECRET_KEY") ALLOWED_HOSTS = [from_env("ALLOWED_HOST")] SESSION_COOKIE_SECURE = True CSRF_COOKIE_SECURE = True DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql_psycopg2", "NAME": from_env("POSTGRES_NAME"), "USER": from_env("POSTGRES_USER"), "PASSWORD": from_env("POSTGRES_PASSWORD"), "HOST": from_env("POSTGRES_HOST"), "PORT": from_env("POSTGRES_PORT"), } } REST_FRAMEWORK["DEFAULT_RENDERER_CLASSES"] = ( "rest_framework.renderers.JSONRenderer", )
MIDDLEWARE += [ "silk.middleware.SilkyMiddleware", "debug_toolbar.middleware.DebugToolbarMiddleware", ] INTERNAL_IPS = [ "127.0.0.1", ] DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql_psycopg2", "NAME": "postgres", "USER": "******", "PASSWORD": from_env("POSTGRES_PASSWORD"), "HOST": "127.0.0.1", "PORT": "5432", } } LOGGING = { "version": 1, "disable_existing_loggers": False, "handlers": { "console": { "class": "logging.StreamHandler", }, }, "root": { "handlers": ["console"],
from safe_environ import from_env from .base import * DEBUG = False SECRET_KEY = from_env("SECRET_KEY") ALLOWED_HOSTS = [from_env("ALLOWED_HOST")] SESSION_COOKIE_SECURE = True CSRF_COOKIE_SECURE = True DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql_psycopg2", "NAME": from_env("POSTGRES_NAME"), "USER": from_env("POSTGRES_USER"), "PASSWORD": from_env("POSTGRES_PASSWORD"), "HOST": from_env("POSTGRES_HOST"), "PORT": from_env("POSTGRES_PORT"), } } memcached_host = (from_env("MEMCACHED_HOST"), ) memcached_port = (from_env("MEMCACHED_PORT"), ) CACHES = { "default": { "BACKEND": "django.core.cache.backends.memcached.MemcachedCache", "LOCATION": f"{memcached_host}{memcached_port}", } }