from datetime import timedelta
from django.conf import settings
from django.test.signals import setting_changed
from rest_framework.settings import api_settings, APISettings

USER_SETTINGS = getattr(settings, 'REST_KNOX', None)

DEFAULTS = {
    'LOGIN_AUTHENTICATION_CLASSES': api_settings.DEFAULT_AUTHENTICATION_CLASSES,
    'SECURE_HASH_ALGORITHM': 'cryptography.hazmat.primitives.hashes.SHA512',
    'AUTH_TOKEN_CHARACTER_LENGTH': 64,
    'TOKEN_TTL': timedelta(hours=10),
    'USER_SERIALIZER': 'knox.serializers.UserSerializer',
}

IMPORT_STRINGS = {
    'SECURE_HASH_ALGORITHM',
    'USER_SERIALIZER',
}

knox_settings = APISettings(USER_SETTINGS, DEFAULTS, IMPORT_STRINGS)


def reload_api_settings(*args, **kwargs):
    global knox_settings
    setting, value = kwargs['setting'], kwargs['value']
    if setting == 'REST_KNOX':
        knox_settings = APISettings(value, DEFAULTS, IMPORT_STRINGS)

setting_changed.connect(reload_api_settings)


class CONSTANTS:
    '''
    Constants cannot be changed at runtime
    '''
    TOKEN_KEY_LENGTH = 8
    DIGEST_LENGTH = 128
    SALT_LENGTH = 16

    def __setattr__(self, *args, **kwargs):
        raise RuntimeException('''
            Constant values must NEVER be changed at runtime, as they are
            integral to the structure of database tables
            ''')
CONSTANTS = CONSTANTS()

from datetime import timedelta
from django.conf import settings
from django.test.signals import setting_changed
from rest_framework.settings import APISettings

USER_SETTINGS = getattr(settings, 'REST_KNOX', None)

DEFAULTS = {
    'SECURE_HASH_ALGORITHM': 'cryptography.hazmat.primitives.hashes.SHA512',
    'AUTH_TOKEN_CHARACTER_LENGTH': 64,
    'TOKEN_TTL': timedelta(hours=10),
    'USER_SERIALIZER': 'knox.serializers.UserSerializer',
}

IMPORT_STRINGS = {
    'SECURE_HASH_ALGORITHM',
    'USER_SERIALIZER',
}

knox_settings = APISettings(USER_SETTINGS, DEFAULTS, IMPORT_STRINGS)


def reload_api_settings(*args, **kwargs):
    global knox_settings
    setting, value = kwargs['setting'], kwargs['value']
    if setting == 'REST_KNOX':
        knox_settings = APISettings(value, DEFAULTS, IMPORT_STRINGS)

setting_changed.connect(reload_api_settings)


class CONSTANTS:
    '''
    Constants cannot be changed at runtime
    '''
    TOKEN_KEY_LENGTH = 8
    DIGEST_LENGTH = 128
    SALT_LENGTH = 16

    def __setattr__(self, *args, **kwargs):
        raise RuntimeException('''
            Constant values must NEVER be changed at runtime, as they are
            integral to the structure of database tables
            ''')
CONSTANTS = CONSTANTS()

Revert "separate default authentication from the DRF's one"
Revert "separate default authentication from the DRF's one"

This reverts commit 73aef41ffd2be2fbed11cf75f75393a80322bdcb.

  from datetime import timedelta
  from django.conf import settings
  from django.test.signals import setting_changed
- from rest_framework.settings import api_settings, APISettings
+ from rest_framework.settings import APISettings
  
  USER_SETTINGS = getattr(settings, 'REST_KNOX', None)
  
  DEFAULTS = {
-     'LOGIN_AUTHENTICATION_CLASSES': api_settings.DEFAULT_AUTHENTICATION_CLASSES,
      'SECURE_HASH_ALGORITHM': 'cryptography.hazmat.primitives.hashes.SHA512',
      'AUTH_TOKEN_CHARACTER_LENGTH': 64,
      'TOKEN_TTL': timedelta(hours=10),
      'USER_SERIALIZER': 'knox.serializers.UserSerializer',
  }
  
  IMPORT_STRINGS = {
      'SECURE_HASH_ALGORITHM',
      'USER_SERIALIZER',
  }
  
  knox_settings = APISettings(USER_SETTINGS, DEFAULTS, IMPORT_STRINGS)
  
  
  def reload_api_settings(*args, **kwargs):
      global knox_settings
      setting, value = kwargs['setting'], kwargs['value']
      if setting == 'REST_KNOX':
          knox_settings = APISettings(value, DEFAULTS, IMPORT_STRINGS)
  
  setting_changed.connect(reload_api_settings)
  
  
  class CONSTANTS:
      '''
      Constants cannot be changed at runtime
      '''
      TOKEN_KEY_LENGTH = 8
      DIGEST_LENGTH = 128
      SALT_LENGTH = 16
  
      def __setattr__(self, *args, **kwargs):
          raise RuntimeException('''
              Constant values must NEVER be changed at runtime, as they are
              integral to the structure of database tables
              ''')
  CONSTANTS = CONSTANTS()
  
Revert "separate default authentication from the DRF's one"
## Code Before:
from datetime import timedelta
from django.conf import settings
from django.test.signals import setting_changed
from rest_framework.settings import api_settings, APISettings

USER_SETTINGS = getattr(settings, 'REST_KNOX', None)

DEFAULTS = {
    'LOGIN_AUTHENTICATION_CLASSES': api_settings.DEFAULT_AUTHENTICATION_CLASSES,
    'SECURE_HASH_ALGORITHM': 'cryptography.hazmat.primitives.hashes.SHA512',
    'AUTH_TOKEN_CHARACTER_LENGTH': 64,
    'TOKEN_TTL': timedelta(hours=10),
    'USER_SERIALIZER': 'knox.serializers.UserSerializer',
}

IMPORT_STRINGS = {
    'SECURE_HASH_ALGORITHM',
    'USER_SERIALIZER',
}

knox_settings = APISettings(USER_SETTINGS, DEFAULTS, IMPORT_STRINGS)


def reload_api_settings(*args, **kwargs):
    global knox_settings
    setting, value = kwargs['setting'], kwargs['value']
    if setting == 'REST_KNOX':
        knox_settings = APISettings(value, DEFAULTS, IMPORT_STRINGS)

setting_changed.connect(reload_api_settings)


class CONSTANTS:
    '''
    Constants cannot be changed at runtime
    '''
    TOKEN_KEY_LENGTH = 8
    DIGEST_LENGTH = 128
    SALT_LENGTH = 16

    def __setattr__(self, *args, **kwargs):
        raise RuntimeException('''
            Constant values must NEVER be changed at runtime, as they are
            integral to the structure of database tables
            ''')
CONSTANTS = CONSTANTS()

## Instruction:
Revert "separate default authentication from the DRF's one"
## Code After:
from datetime import timedelta
from django.conf import settings
from django.test.signals import setting_changed
from rest_framework.settings import APISettings

USER_SETTINGS = getattr(settings, 'REST_KNOX', None)

DEFAULTS = {
    'SECURE_HASH_ALGORITHM': 'cryptography.hazmat.primitives.hashes.SHA512',
    'AUTH_TOKEN_CHARACTER_LENGTH': 64,
    'TOKEN_TTL': timedelta(hours=10),
    'USER_SERIALIZER': 'knox.serializers.UserSerializer',
}

IMPORT_STRINGS = {
    'SECURE_HASH_ALGORITHM',
    'USER_SERIALIZER',
}

knox_settings = APISettings(USER_SETTINGS, DEFAULTS, IMPORT_STRINGS)


def reload_api_settings(*args, **kwargs):
    global knox_settings
    setting, value = kwargs['setting'], kwargs['value']
    if setting == 'REST_KNOX':
        knox_settings = APISettings(value, DEFAULTS, IMPORT_STRINGS)

setting_changed.connect(reload_api_settings)


class CONSTANTS:
    '''
    Constants cannot be changed at runtime
    '''
    TOKEN_KEY_LENGTH = 8
    DIGEST_LENGTH = 128
    SALT_LENGTH = 16

    def __setattr__(self, *args, **kwargs):
        raise RuntimeException('''
            Constant values must NEVER be changed at runtime, as they are
            integral to the structure of database tables
            ''')
CONSTANTS = CONSTANTS()
