
import logging

from pecan import expose, response, conf
from pecan.rest import RestController

from cauth.controllers import base, github, introspection
from cauth.utils.common import LOGOUT_MSG


logger = logging.getLogger(__name__)


class LogoutController(RestController):
    @expose(template='login.html')
    def get(self, **kwargs):
        response.delete_cookie('auth_pubtkt', domain=conf.app.cookie_domain)
        return dict(back='/', message=LOGOUT_MSG)


class RootController(object):
    login = base.BaseLoginController()
    login.github = github.GithubController()
    login.githubAPIkey = github.PersonalAccessTokenGithubController()
    about = introspection.IntrospectionController()

    logout = LogoutController()


import logging

from pecan import expose, response, conf
from pecan.rest import RestController

from cauth.auth import base as exceptions
from cauth.controllers import base, github, introspection
from cauth.utils.common import LOGOUT_MSG


logger = logging.getLogger(__name__)


class LogoutController(RestController):
    @expose(template='login.html')
    def get(self, **kwargs):
        response.delete_cookie('auth_pubtkt', domain=conf.app.cookie_domain)
        return dict(back='/', message=LOGOUT_MSG)


class RootController(object):
    login = base.BaseLoginController()
    try:
        login.github = github.GithubController()
        login.githubAPIkey = github.PersonalAccessTokenGithubController()
    except exceptions.AuthProtocolNotAvailableError as e:
        logger.error("%s - skipping callback endpoint" % e.message)
    about = introspection.IntrospectionController()

    logout = LogoutController()

Fix app crashing at startup if some auth methods are not configured
Fix app crashing at startup if some auth methods are not configured

Change-Id: I201dbc646c6da39c5923a086a0498b7ccb854982

  
  import logging
  
  from pecan import expose, response, conf
  from pecan.rest import RestController
  
+ from cauth.auth import base as exceptions
  from cauth.controllers import base, github, introspection
  from cauth.utils.common import LOGOUT_MSG
  
  
  logger = logging.getLogger(__name__)
  
  
  class LogoutController(RestController):
      @expose(template='login.html')
      def get(self, **kwargs):
          response.delete_cookie('auth_pubtkt', domain=conf.app.cookie_domain)
          return dict(back='/', message=LOGOUT_MSG)
  
  
  class RootController(object):
      login = base.BaseLoginController()
+     try:
-     login.github = github.GithubController()
+         login.github = github.GithubController()
-     login.githubAPIkey = github.PersonalAccessTokenGithubController()
+         login.githubAPIkey = github.PersonalAccessTokenGithubController()
+     except exceptions.AuthProtocolNotAvailableError as e:
+         logger.error("%s - skipping callback endpoint" % e.message)
      about = introspection.IntrospectionController()
  
      logout = LogoutController()
  
Fix app crashing at startup if some auth methods are not configured
## Code Before:

import logging

from pecan import expose, response, conf
from pecan.rest import RestController

from cauth.controllers import base, github, introspection
from cauth.utils.common import LOGOUT_MSG


logger = logging.getLogger(__name__)


class LogoutController(RestController):
    @expose(template='login.html')
    def get(self, **kwargs):
        response.delete_cookie('auth_pubtkt', domain=conf.app.cookie_domain)
        return dict(back='/', message=LOGOUT_MSG)


class RootController(object):
    login = base.BaseLoginController()
    login.github = github.GithubController()
    login.githubAPIkey = github.PersonalAccessTokenGithubController()
    about = introspection.IntrospectionController()

    logout = LogoutController()

## Instruction:
Fix app crashing at startup if some auth methods are not configured
## Code After:

import logging

from pecan import expose, response, conf
from pecan.rest import RestController

from cauth.auth import base as exceptions
from cauth.controllers import base, github, introspection
from cauth.utils.common import LOGOUT_MSG


logger = logging.getLogger(__name__)


class LogoutController(RestController):
    @expose(template='login.html')
    def get(self, **kwargs):
        response.delete_cookie('auth_pubtkt', domain=conf.app.cookie_domain)
        return dict(back='/', message=LOGOUT_MSG)


class RootController(object):
    login = base.BaseLoginController()
    try:
        login.github = github.GithubController()
        login.githubAPIkey = github.PersonalAccessTokenGithubController()
    except exceptions.AuthProtocolNotAvailableError as e:
        logger.error("%s - skipping callback endpoint" % e.message)
    about = introspection.IntrospectionController()

    logout = LogoutController()
