# Path: salt_observer/saltapis.py
# class SaltCherrypy(AbstractApi):
# 
#     BASE_URL = '{protocol}://{host}:{port}'.format(**settings.SALT['api']['cherrypy'])
# 
#     def logout(self):
#         return self.request('post', '/logout', headers={'Accept': 'application/json'})
# 
#     def get(self, module, target='*', api_args=[], api_kwargs={}):
#         return self.request(
#             'post',
#             data={
#                 'client': 'local',
#                 'fun': module,
#                 'tgt': target,
#                 'arg': api_args,
#                 'kwarg': api_kwargs
#             },
#             headers={
#                 'Accept': 'application/json',
#             }
#         ).json().get('return')[0]
# 
# class SaltTornado(AbstractApi):
# 
#     BASE_URL = '{protocol}://{host}:{port}'.format(**settings.SALT['api']['tornado'])


from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User
from salt_observer.saltapis import SaltCherrypy, SaltTornado



class RestBackend(ModelBackend):
    ''' Authenticate against salt-api-permissions '''

    def authenticate(self, username=None, password=None, request=None):

        try:

# Path: salt_observer/saltapis.py
# class SaltCherrypy(AbstractApi):
# 
#     BASE_URL = '{protocol}://{host}:{port}'.format(**settings.SALT['api']['cherrypy'])
# 
#     def logout(self):
#         return self.request('post', '/logout', headers={'Accept': 'application/json'})
# 
#     def get(self, module, target='*', api_args=[], api_kwargs={}):
#         return self.request(
#             'post',
#             data={
#                 'client': 'local',
#                 'fun': module,
#                 'tgt': target,
#                 'arg': api_args,
#                 'kwarg': api_kwargs
#             },
#             headers={
#                 'Accept': 'application/json',
#             }
#         ).json().get('return')[0]
# 
# class SaltTornado(AbstractApi):
# 
#     BASE_URL = '{protocol}://{host}:{port}'.format(**settings.SALT['api']['tornado'])


# Path: salt_observer/backends.py
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User
from salt_observer.saltapis import SaltCherrypy, SaltTornado




class RestBackend(ModelBackend):
    ''' Authenticate against salt-api-permissions '''

    def authenticate(self, username=None, password=None, request=None):

        try:

            cherrypy_token = SaltCherrypy(username, password).token