HEX
Server: Apache
System: Linux sg241.singhost.net 2.6.32-896.16.1.lve1.4.51.el6.x86_64 #1 SMP Wed Jan 17 13:19:23 EST 2018 x86_64
User: honghock (909)
PHP: 8.0.30
Disabled: passthru,system,shell_exec,show_source,exec,popen,proc_open
Upload Files
File: //usr/lib/python2.7/site-packages/salt/auth/keystone.py
# -*- coding: utf-8 -*-
'''
Provide authentication using OpenStack Keystone

:depends:   - keystoneclient Python module
'''

from __future__ import absolute_import, print_function, unicode_literals
try:
    from keystoneclient.v2_0 import client
    from keystoneclient.exceptions import AuthorizationFailure, Unauthorized
except ImportError:
    pass


def get_auth_url():
    '''
    Try and get the URL from the config, else return localhost
    '''
    try:
        return __opts__['keystone.auth_url']
    except KeyError:
        return 'http://localhost:35357/v2.0'


def auth(username, password):
    '''
    Try and authenticate
    '''
    try:
        keystone = client.Client(username=username, password=password,
                                 auth_url=get_auth_url())
        return keystone.authenticate()
    except (AuthorizationFailure, Unauthorized):
        return False


if __name__ == '__main__':
    __opts__ = {}
    if auth('test', 'test'):
        print("Authenticated")
    else:
        print("Failed to authenticate")