예제 #1
0
파일: test_env.py 프로젝트: kelsoncm/sc4
 def test_env(self):
     os.environ['WRAPPED'] = "'aqui'"
     self.assertEqual("ASDF", env('DUMMY_ENV', 'ASDF'))
     self.assertEqual("'aqui'", env('WRAPPED', 'ASDF'))
     self.assertEqual("aqui", env('WRAPPED', 'ASDF', True))
예제 #2
0
파일: settings.py 프로젝트: suap-ead/app_id
import os
from sc4py.env import env
URL_PATH_PREFIX = env("URL_PATH_PREFIX", "sead/id/")
os.environ.setdefault("URL_PATH_PREFIX", env("", "sead/id/"))
os.environ.setdefault("MY_APPS", "id")
os.environ.setdefault("POSTGRES_DB", env("POSTGRES_DB_ID"))

os.environ.setdefault("DJANGO_AUTH_USER_MODEL", "id.User")
os.environ.setdefault("DJANGO_LOGIN_URL",
                      env("DJANGO_LOGIN_URL", '/%slogin/' % URL_PATH_PREFIX))
os.environ.setdefault("DJANGO_LOGOUT_URL",
                      env("DJANGO_LOGOUT_URL", '/%slogout/' % URL_PATH_PREFIX))
os.environ.setdefault(
    "DJANGO_LOGIN_REDIRECT_URL",
    env("DJANGO_LOGIN_REDIRECT_URL", '/%s' % URL_PATH_PREFIX))
os.environ.setdefault(
    "DJANGO_LOGOUT_REDIRECT_URL",
    env("DJANGO_LOGOUT_REDIRECT_URL", '/%s' % URL_PATH_PREFIX))

from suap_ead.template_settings import *
from sc4py.env import env, env_as_bool, env_as_list

name = "suapintegration"

SOCIAL_AUTH_SUAP_KEY = env('SOCIAL_AUTH_SUAP_KEY', 'changeme')
SOCIAL_AUTH_SUAP_SECRET = env('SOCIAL_AUTH_SUAP_SECRET', 'changeme')
SOCIAL_AUTH_SUAP_AUTHORIZATION_URL = env(
    'SOCIAL_AUTH_SUAP_AUTHORIZATION_URL',
    'https://suap.ifrn.edu.br/o/authorize/')
SOCIAL_AUTH_SUAP_ACCESS_TOKEN_METHOD = env(
    'SOCIAL_AUTH_SUAP_ACCESS_TOKEN_METHOD', 'POST')
SOCIAL_AUTH_SUAP_ACCESS_TOKEN_URL = env('SOCIAL_AUTH_SUAP_ACCESS_TOKEN_URL',
                                        'https://suap.ifrn.edu.br/o/token/')
SOCIAL_AUTH_SUAP_ID_KEY = env('SOCIAL_AUTH_SUAP_ID_KEY', 'identificacao')
SOCIAL_AUTH_SUAP_RESPONSE_TYPE = env('SOCIAL_AUTH_SUAP_RESPONSE_TYPE', 'code')
SOCIAL_AUTH_SUAP_REDIRECT_STATE = env_as_bool(
    'SOCIAL_AUTH_SUAP_REDIRECT_STATE', True)
SOCIAL_AUTH_SUAP_STATE_PARAMETER = env_as_bool(
    'SOCIAL_AUTH_SUAP_STATE_PARAMETER', True)
SOCIAL_AUTH_SUAP_USER_DATA_URL = env('SOCIAL_AUTH_SUAP_USER_DATA_URL',
                                     'https://suap.ifrn.edu.br/api/eu/')
SOCIAL_AUTH_SUAP_AUTO_CREATE = env_as_bool('SOCIAL_AUTH_SUAP_AUTO_CREATE',
                                           False)
SOCIAL_AUTH_SUAP_AUTO_CREATE_AS_STAFF = env_as_bool(
    'SOCIAL_AUTH_SUAP_AUTO_CREATE_AS_STAFF', False)
SOCIAL_AUTH_SUAP_EXTRA_CONTEXT_PROCESSORS = env_as_list(
    'SOCIAL_AUTH_SUAP_EXTRA_CONTEXT_PROCESSORS',
    'social_django.context_processors.backends,'
    'social_django.context_processors.login_redirect')

SUAPINTEGRATION_APPS = env_as_list('SUAPINTEGRATION_APPS',
예제 #4
0
from pathlib import Path
from sc4py.env import env, env_as_bool, env_as_int, env_as_list
import logging.config

BASE_DIR = Path(__file__).resolve().parent

DEBUG = env_as_bool("DJANGO_DEBUG", False)

# Get loglevel from env
LOGLEVEL = env('DJANGO_LOGLEVEL', 'DEBUG').upper()

logging.config.dictConfig({
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'console': {
            'format':
            '%(asctime)s %(levelname)s [%(name)s:%(lineno)s] %(module)s %(process)d %(thread)d %(message)s',
        },
    },
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
            'formatter': 'console',
        },
    },
    'loggers': {
        '': {
            'level': LOGLEVEL,
            'handlers': [
                'console',
예제 #5
0
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'suap_ead.context_processors.suap_ead',
                'django.contrib.messages.context_processors.messages'
            ],
        },
    },
]

# Database
DATABASES = {
    'default': {
        'ENGINE': env('POSTGRES_ENGINE',
                      'django.db.backends.postgresql_psycopg2'),
        'HOST': env('POSTGRES_HOST', 'db'),
        'PORT': env('POSTGRES_PORT', '5432'),
        'NAME': env('POSTGRES_DB', None),
        'USER': env('POSTGRES_USER', 'postgres'),
        'PASSWORD': env('POSTGRES_PASSWORD', 'postgres'),
    }
}

# Routing
WSGI_APPLICATION = env('DJANGO_WSGI_APPLICATION', 'suap_ead.wsgi.application')
ALLOWED_HOSTS = env_as_list('DJANGO_ALLOWED_HOSTS', '*' if DEBUG else '')
USE_X_FORWARDED_HOST = True
ROOT_URLCONF = env('DJANGO_ROOT_URLCONF', 'urls')
URL_PATH_PREFIX = env('URL_PATH_PREFIX', 'sead/id/')
STATIC_URL = env('DJANGO_STATIC_URL', "/%s%s" % (URL_PATH_PREFIX, 'static/'))
예제 #6
0
INSTALLED_APPS = MY_APPS + SUAPINTEGRATION_APPS + THIRD_APPS + DJANGO_APPS

# Middleware
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'social_django.middleware.SocialAuthExceptionMiddleware',  # <-
]

# Routing
WSGI_APPLICATION = env('DJANGO_WSGI_APPLICATION', 'wsgi.application')
ALLOWED_HOSTS = env_as_list('DJANGO_ALLOWED_HOSTS', '*' if DEBUG else '')
USE_X_FORWARDED_HOST = env_as_bool('DJANGO_USE_X_FORWARDED_HOST', False)
SECURE_PROXY_SSL_HEADER = env_as_list('DJANGO_SECURE_PROXY_SSL_HEADER', '')
ROOT_URLCONF = env('DJANGO_ROOT_URLCONF', 'urls')
URL_PATH_PREFIX = env('URL_PATH_PREFIX', '/sead/agendamento/')
STATIC_URL = env('DJANGO_STATIC_URL', URL_PATH_PREFIX + 'static/')
STATIC_ROOT = env('DJANGO_STATIC_ROOT', "/static" + URL_PATH_PREFIX)
MEDIA_URL = env('DJANGO_MEDIA_URL', URL_PATH_PREFIX + 'media/')
MEDIA_ROOT = env('DJANGO_MEDIA_ROOT', '/media' + URL_PATH_PREFIX)
MARKDOWNX_URLS_PATH = env('MARKDOWNX_URLS_PATH',
                          URL_PATH_PREFIX + 'markdownx/markdownify/')
MARKDOWNX_UPLOAD_URLS_PATH = env('MARKDOWNX_UPLOAD_URLS_PATH',
                                 URL_PATH_PREFIX + 'markdownx/upload/')

# Template engine
예제 #7
0
파일: init_dev.py 프로젝트: suap-ead/app_id
    def handle(self, *args, **options):
        if not settings.DEBUG:
            print("init_dev are project to dev environment")
            return

        su=User.objects.filter(is_superuser=True).first()
        if su is None:
            yn=input('do you wanna create a admin:admin superuser (y/N)?')
            if yn in ['Y', 'y']:
                su = User.objects.create(
                    username='******',
                    cpf='12345678901',

                    active='Ativo',
                    is_staff=True,
                    is_superuser=True,

                    social_name='Social name',
                    first_name='First name',
                    last_name='Last name',

                    campus='Campus',
                    department='Department',
                    title='Officer',
                    carrer='Carrer',
                    job='Job',
                    polo='Polo',

                    course='Course name',
                    course_code='0000',

                    email='*****@*****.**',
                    enterprise_email='*****@*****.**',
                    academic_email='*****@*****.**',
                    scholar_email='*****@*****.**',

                    first_access=make_aware(datetime.datetime.now()),
                    last_access=make_aware(datetime.datetime.now()),
                    deleted=None,

                    created_at=make_aware(datetime.datetime.now()),
                    changed_at=make_aware(datetime.datetime.now()),
                    password_set_at=make_aware(datetime.datetime.now()),
                    last_access_at=make_aware(datetime.datetime.now()),

                    photo_url='https://suap.ifrn.edu.br/media/alunos/150x200/170685.jpg')
                su.set_password('admin')
                su.save()
                print("User created")

        if su is None:
            print("superuser dont exists")
            return

        allowed_callback_urls = ''
        allowed_web_origins = ''
        allowed_logout_urls = ''
        for host in ['sead', 'localhost'] + options['myip']:
            for service in ['id', 'dashboard']:
                allowed_callback_urls += 'http://%s/sead/%s/jwt/complete/\n' % (host, service)
                allowed_web_origins += 'http://%s/sead/%s/jwt/login/\n' % (host, service)
                allowed_logout_urls += 'http://%s/sead/%s/jwt/logout/\n' % (host, service)

        app = Application.objects.filter(client_id=env('SUAP_EAD_ID_JWT_CLIENT_ID'),
                                         secret=env('SUAP_EAD_ID_JWT_SECRET')).first()
        if app is None:
            print("creating app...\n")
            app = Application()
        else:
            print("application always exists\n")

        app.owner = su
        app.name = 'SUAP_EAD_ID'
        app.description = 'some description'
        app.client_id = env('SUAP_EAD_ID_JWT_CLIENT_ID')
        app.secret = env('SUAP_EAD_ID_JWT_SECRET')
        app.logo = None
        app.allowed_callback_urls = allowed_callback_urls
        app.allowed_web_origins = allowed_web_origins
        app.allowed_logout_urls = allowed_logout_urls
        app.expiration = 600
        app.created_at = datetime.datetime.now()
        app.deleted_at = None
        app.save()

        print("application client_id=%s" % env('SUAP_EAD_ID_JWT_CLIENT_ID'))
        print("application secret=%s" % env('SUAP_EAD_ID_JWT_SECRET'))
        print("\nDone.")
예제 #8
0
import os
from sc4py.env import env
os.environ.setdefault("URL_PATH_PREFIX", env("", "ege/perfil/"))
os.environ.setdefault("MY_APPS", "ege_perfil")
os.environ.setdefault("POSTGRES_DB", env("POSTGRES_DB_PERFIL"))

os.environ.setdefault(
    "SUAP_EAD_UTILS_AUTH_JWT_BACKEND",
    env("SUAP_EAD_UTILS_AUTH_JWT_BACKEND",
        'suap_ead.auth.CreateNewUserJwtBackend'))

from suap_ead.template_settings import *
예제 #9
0
from pathlib import Path
from sc4py.env import env, env_as_bool, env_as_int, env_as_list
import logging.config

BASE_DIR = Path(__file__).resolve().parent

DEBUG = env_as_bool("DJANGO_DEBUG", False)

# Get loglevel from env
LOGLEVEL = env('DJANGO_LOGLEVEL', 'DEBUG').upper()

logging.config.dictConfig({
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'console': {
            'format':
            '%(asctime)s %(levelname)s [%(name)s:%(lineno)s] %(module)s %(process)d %(thread)d %(message)s',
        },
    },
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
            'formatter': 'console',
        },
    },
    'loggers': {
        '': {
            'level': LOGLEVEL,
            'handlers': [
                'console',
예제 #10
0
import os
from sc4py.env import env
os.environ.setdefault("URL_PATH_PREFIX", env("", "sead/dashboard/"))
os.environ.setdefault("MY_APPS", "dashboard")
os.environ.setdefault("POSTGRES_DB", env("POSTGRES_DB_DASHBOARD", 'sead_dashboard'))

os.environ.setdefault("SUAP_EAD_UTILS_AUTH_JWT_BACKEND", env("SUAP_EAD_UTILS_AUTH_JWT_BACKEND", 'suap_ead.auth.CreateNewUserJwtBackend'))

from suap_ead.template_settings import *
예제 #11
0
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'ege_utils.context_processors.ege',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

# Database
DATABASES = {
    'default': {
        'ENGINE': env('POSTGRES_ENGINE',
                      'django.db.backends.postgresql_psycopg2'),
        'HOST': env('POSTGRES_HOST', 'db'),
        'PORT': env('POSTGRES_PORT', '5432'),
        'NAME': env('POSTGRES_DB', None),
        'USER': env('POSTGRES_USER', 'postgres'),
        'PASSWORD': env('POSTGRES_PASSWORD', 'postgres'),
    }
}

# Routing
WSGI_APPLICATION = env('DJANGO_WSGI_APPLICATION', 'ege_utils.wsgi.application')
ALLOWED_HOSTS = env_as_list('DJANGO_ALLOWED_HOSTS', '*' if DEBUG else '')
USE_X_FORWARDED_HOST = True
ROOT_URLCONF = env('DJANGO_ROOT_URLCONF', 'urls')
URL_PATH_PREFIX = env('URL_PATH_PREFIX', 'ege/perfil/')
STATIC_URL = env('DJANGO_STATIC_URL', "/%s%s" % (URL_PATH_PREFIX, 'static/'))