# By: Riasat Ullah
# This file contains constants, variables and functions for handling SSO.

from utils import s3

# s3 bucket details for retrieving SSO credentials
s3_sso_bucket = 'taskcall-prod-data'
s3_sso_key = 'credentials/sso_credentials.json'


def get_sso_credentials(sso_type):
    '''
    Get the SSO credentials and other necessary information from s3.
    :param sso_type: the type of SSO
    :return: details of the SSO
    '''
    try:
        data = s3.read_json(s3_sso_bucket, s3_sso_key)
        return data[sso_type]
    except KeyError as e:
        err = 'Unknown sso type - ' + sso_type + '\n' + str(e)
        raise KeyError(err)
    except (OSError, IOError) as e:
        err = 'Could not read sso credentials file' + '\n' + str(e)
        raise OSError(err)
