Example #1
0
    def __init__(self,
                 username,
                 host,
                 password=None,
                 access_hash=None,
                 ssl=True,
                 cpanel=False):
        """
        Constructs a new instance of the whmclient.Client class.  It can only
        accept a `password` or `access_hash`, but not both.

        The `cpanel` flag will send requests to cPanel ports instead of WHM.
        If that option is used, access_hash authentication is not supported.
        """
        self.username = username
        self.host = host

        if not password and not access_hash:
            raise exceptions.MissingCredentials()
        elif (password and access_hash) or (cpanel and access_hash):
            raise exceptions.InvalidCredentials()
        elif access_hash:
            self.auth = AccessHashAuth(username, access_hash)
        elif password:
            self.auth = (username, password)

        self.protocol = 'https' if ssl else 'http'
        self.port = 2082 if cpanel else 2086
        if ssl:
            self.port = 2083 if cpanel else 2087
Example #2
0
 def get_default(cls, credentials_type):
     if credentials_type not in cls.TYPES:
         raise exceptions.InvalidCredentials()
     creds = cls._get_default(credentials_type)
     if not creds.is_valid():
         raise exceptions.InvalidConfiguration()
     return creds
Example #3
0
def get_configured_credentials(credential_type,
                               fill_in=True,
                               identity_version=None):
    identity_version = identity_version or CONF.identity.auth_version
    if identity_version not in ('v2', 'v3'):
        raise exceptions.InvalidConfiguration('Unsupported auth version: %s' %
                                              identity_version)
    if credential_type not in CREDENTIAL_TYPES:
        raise exceptions.InvalidCredentials()
    conf_attributes = ['username', 'password', 'tenant_name']
    if identity_version == 'v3':
        conf_attributes.append('domain_name')
    # Read the parts of credentials from config
    params = DEFAULT_PARAMS.copy()
    section, prefix = CREDENTIAL_TYPES[credential_type]
    for attr in conf_attributes:
        _section = getattr(CONF, section)
        if prefix is None:
            params[attr] = getattr(_section, attr)
        else:
            params[attr] = getattr(_section, prefix + "_" + attr)
    # Build and validate credentials. We are reading configured credentials,
    # so validate them even if fill_in is False
    credentials = get_credentials(fill_in=fill_in,
                                  identity_version=identity_version,
                                  **params)
    if not fill_in:
        if not credentials.is_valid():
            msg = ("The %s credentials are incorrectly set in the config file."
                   " Double check that all required values are assigned" %
                   credential_type)
            raise exceptions.InvalidConfiguration(msg)
    return credentials
Example #4
0
 def get_default(cls, credentials_type):
     if credentials_type not in cls.TYPES:
         raise exceptions.InvalidCredentials()
     creds = cls._get_default(credentials_type)
     if not creds.is_valid():
         msg = ("The %s credentials are incorrectly set in the config file."
                " Double check that all required values are assigned" %
                credentials_type)
         raise exceptions.InvalidConfiguration(msg)
     return creds