Exemplo n.º 1
0
    def setUp(self):
        Tenant.create(
            name='Test Tenant',
            first_name='John',
            last_name='Doe',
            email='*****@*****.**',
            password='******')

        Integration.create(
            tenant=Tenant.objects.filter(name='Test Tenant').first(),
            name=BASE_TEST_INTEGRATION_NAME,
            notes='Test Notes')

        DeviceKind.objects.create(
            name='OTP',
            module='devices.modules.otp.OTPDeviceKindModule',
            description='OTP Devices',
            configuration={
                'issuer_name': 'pymfa',
                'digits': 6,
                'algorithm': OTPConfiguration.ALGORITHM_SHA1,
                'secret_length': 32,
                'valid_window': 1,
                'interval': 30,
            })

        Module.objects.create(
            name='contrib.communications.DjangoSMTPMailer', configuration={})

        DeviceKind.objects.create(
            name='Email',
            module='devices.modules.email.EmailDeviceKindModule',
            description='Email Devices',
            configuration={
                'from_email': '*****@*****.**',
                'subject': 'Your 2fa access token',
                'message': 'Your 2fa access token is `{token}`',
                'html_message': 'Your 2fa access token is `{token}`',
                'communication_module':
                    'contrib.communications.DjangoSMTPMailer',
                'communication_module_settings': {},
            })
Exemplo n.º 2
0
    def handle(self, *args, **options):
        user = User.objects.filter(username=os.getenv('OSS2FA_ADMIN_USERNAME')).first()

        if user:
            return

        if not user:
            _ = User.objects.create_superuser(
                os.getenv('OSS2FA_ADMIN_USERNAME'),
                os.getenv('OSS2FA_ADMIN_EMAIL'),
                os.getenv('OSS2FA_ADMIN_PASSWORD')
            )

        DeviceKind.objects.create(
            name='OTP',
            module='devices.modules.otp.OTPDeviceKindModule',
            description='OTP Devices',
            configuration={
                'issuer_name': otp.OTPConfiguration.DEFAULT_ISSUER,
                'digits': otp.OTPConfiguration.DEFAULT_DIGITS,
                'algorithm': otp.OTPConfiguration.ALGORITHM_SHA1,
                'secret_length': otp.OTPConfiguration.DEFAULT_SECRET_LENGTH,
                'valid_window': otp.OTPConfiguration.DEFAULT_VALID_WINDOW,
                'interval': otp.OTPConfiguration.DEFAULT_INTERVAL,
            })

        tenant = Tenant.create(
            name=Tenant.DEFAULT_TENANT_NAME,
            email=os.getenv('OSS2FA_ADMIN_EMAIL'),
            password=os.getenv('OSS2FA_ADMIN_PASSWORD'),
        )

        integration = Integration.create(
            tenant=tenant,
            name=Integration.DEFAULT_INTEGRATION_NAME,
            notes='Default Integration'
        )

        message = '''
===> OSS2FA bootstrap complete!
===> To get you started, we have created a default tenant and integration.
===> Integration (name=`{0}`, access_key=`{1}`, secret_key=`{2}`)
'''
        self.stdout.write(
            self.style.SUCCESS(message.format(
                integration.name,
                integration.access_key,
                integration.secret_key
            )))