Exemplo n.º 1
0
    def __init__(self, base_url=None, username=None, password=None, project_name=None, project_id=None, login_mode=1,
                 ssl_verify=True, certificate_path=None, proxies=None, identity_token=None, verbose=True):
        """Establish a connection with MicroStrategy REST API.

        Args:
            base_url (str, optional): URL of the MicroStrategy REST API server.
                Typically of the form:
                    "https://<mstr_env>.com/MicroStrategyLibrary/api"
            username (str, optional): Username
            password (str, optional): Password
            project_name (str, optional): Name of the project you intend to
                connect to.Case-sensitive. You should provide either Project ID
                or Project Name.
            project_id (str, optional): Id of the project you intend to connect
                to. Case-sensitive. You should provide either Project ID
                or Project Name.
            login_mode (int, optional): Specifies the authentication mode to
                use. Supported authentication modes are: Standard (1)
                (default) or LDAP (16)
            ssl_verify (bool, optional): If True (default), verifies the
                server's SSL certificates with each request
            certificate_path (str, optional): Path to SSL certificate file, if
                None and ssl_verify is True then the certificate will be looked
                for in current working directory
            proxies (dict, optional): Dictionary mapping protocol or protocol
                and host to the URL of the proxy (e.g. {'http': 'foo.bar:3128',
                'http://host.name': 'foo.bar:4012'})
            identity_token (str, optional): Identity token for delegated
                session. Used for connection initialized by GUI.
            verbose (bool, optional): True by default. Controls the amount of
                feedback from the I-Server.
        """

        config.verbose = True if verbose and config.verbose else False    # set the verbosity globally
        self.base_url = helper.url_check(base_url)
        self.username = username
        self.password = password
        self.login_mode = login_mode
        self.web_version = None
        self.iserver_version = None
        self.certificate_path = certificate_path
        self.identity_token = identity_token
        self.session = self.__configure_session(ssl_verify, certificate_path, proxies)

        if self.__check_version():
            # save the version of IServer in config file
            config.iserver_version = self.iserver_version
            # delegate identity token or connect and create new sesssion
            self.delegate() if self.identity_token else self.connect()
            self.select_project(project_id=project_id, project_name=project_name)
        else:
            print("""This version of mstrio is only supported on MicroStrategy 11.1.0400 or higher.
                     \rCurrent Intelligence Server version: {}
                     \rCurrent MicroStrategy Web version: {}
                     """.format(self.iserver_version, self.web_version))
            helper.exception_handler(msg="MicroStrategy Version not supported.",
                                     exception_type=exceptions.VersionException)
        self.user_id = self.__get_user_info()['id']
Exemplo n.º 2
0
    def __init__(self,
                 base_url=None,
                 username=None,
                 password=None,
                 project_name=None,
                 project_id=None,
                 login_mode=1,
                 ssl_verify=True):
        """
        Establishes a connection with MicroStrategy REST API

        Args:
            base_url (str, optional): URL of the MicroStrategy REST API server. Typically of the form
            https://<mstr_env>.com/MicroStrategyLibrary/api
            username (str, optional): Username
            password (str, optional): Password
            project_name (str, optional): Name of the project you intend to connect to.Case-sensitive.
                            You should provide either Project ID or Project Name.
            project_id (str, optional): Id of the project you intend to connect to. Case-sensitive.
                            You should provide either Project ID or Project Name.
            login_mode (int, optional): Specifies the authentication mode to use. Supported authentication modes are:
                            Standard (1) (default) or LDAP (16)
            ssl_verify (bool, optional): If True (default), verifies the server's SSL certificates with each request
        """

        self.base_url = helper.url_check(base_url)
        self.username = username
        self.password = password
        if project_id is not None and project_name is not None:
            helper.exception_handler(
                msg="Provide either Project ID or Project Name.",
                exception_type=ValueError)
        else:
            self.project_id = project_id
            self.project_name = project_name
        self.login_mode = login_mode
        self.ssl_verify = ssl_verify
        self.web_version = None
        self.iserver_version = None
Exemplo n.º 3
0
 def test_url_check(self):
     with self.assertRaises(Exception):
         helper.url_check('www.no_https_prefix.com')
     with self.assertRaises(Exception):
         helper.url_check('htpt://no_https_prefix.com')
     with self.assertRaises(Exception):
         helper.url_check('no_https_prefix.com')
     helper.url_check('https://env-myenv.com/path')
     helper.url_check('https://env-myenv.com/api')
     helper.url_check('https://env-myenv.com/')
     helper.url_check('https://env-myenv.com')
Exemplo n.º 4
0
    def __init__(self, base_url, username=None, password=None, application_name=None,
                 application_id=None, project_name=None, project_id=None, login_mode=1,
                 ssl_verify=True, certificate_path=None, proxies=None, identity_token=None,
                 verbose=True):
        """Establish a connection with MicroStrategy REST API.

        You can establish connection by either providing set of values
        (`username`, `password`, `login_mode`) or just `identity_token`.

        When both `application_id` and `application_name` are `None`,
        application selection is cleared. When both `application_id`
        and `application_name` are provided, `application_name` is ignored.

        Args:
            base_url (str): URL of the MicroStrategy REST API server.
                Typically of the form:
                "https://<mstr_env>.com/MicroStrategyLibrary/api"
            username (str, optional): Username
            password (str, optional): Password
            project_name (str, optional): this argument will be deprecated, use
                application_name instead
            project_id (str, optional): this argument will be deprecated, use
                application_id instead
            application_name (str, optional): Name of the application you intend
                to connect to (case-sensitive). Provide either Application ID
                or Application Name.
            application_id (str, optional): Id of the application you intend to
                connect to (case-sensitive). Provide either Application ID
                or Application Name.
            login_mode (int, optional): Specifies the authentication mode to
                use. Supported authentication modes are: Standard (1)
                (default) or LDAP (16)
            ssl_verify (bool, optional): If True (default), verifies the
                server's SSL certificates with each request
            certificate_path (str, optional): Path to SSL certificate file, if
                None and ssl_verify is True then the certificate will be looked
                for in current working directory
            proxies (dict, optional): Dictionary mapping protocol or protocol
                and host to the URL of the proxy (e.g. {'http': 'foo.bar:3128',
                'http://host.name': 'foo.bar:4012'})
            identity_token (str, optional): Identity token for delegated
                session. Used for connection initialized by GUI.
            verbose (bool, optional): True by default. Controls the amount of
                feedback from the I-Server.
        """
        # set the verbosity globally
        config.verbose = True if verbose and config.verbose else False
        self.base_url = helper.url_check(base_url)
        self.username = username
        self.login_mode = login_mode
        self.certificate_path = certificate_path
        self.identity_token = identity_token
        self.session = self.__configure_session(ssl_verify, certificate_path, proxies)
        self._web_version = None
        self._iserver_version = None
        self._user_id = None
        self._user_full_name = None
        self._user_initials = None
        self.__password = password
        application_id = project_id if project_id else application_id
        application_name = project_name if project_name else application_name

        if project_id or project_name:
            deprecation_warning("`project_id` and `project_name`",
                                "`application_id` or `application_name`", "11.3.2.101")

        if self.__check_version():
            # save the version of IServer in config file
            config.iserver_version = self.iserver_version
            # delegate identity token or connect and create new sesssion
            self.delegate() if self.identity_token else self.connect()
            self.select_application(application_id=application_id,
                                    application_name=application_name)
        else:
            print("""This version of mstrio is only supported on MicroStrategy 11.1.0400 or higher.
                     \rCurrent Intelligence Server version: {}
                     \rCurrent MicroStrategy Web version: {}
                     """.format(self.iserver_version, self.web_version))
            helper.exception_handler(msg="MicroStrategy Version not supported.",
                                     exception_type=exceptions.VersionException)