示例#1
0
def update_datasource_instance(connection, id, body, error_msg=None):
    """Update a specific database source based on id.

    Args:
        connection: MicroStrategy REST API connection object
        id (string): ID
        body: update operation info
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object. HTTP STATUS 200/400
    """
    url = f"{connection.base_url}/api/datasources/{id}"
    response = connection.session.patch(url=url, json=body)
    if not response.ok:
        if error_msg is None:
            error_msg = f"Error updating Datasource Instance with ID: {id}"
        response_handler(response, error_msg)
    return response
示例#2
0
def get_project_settings_config(connection, id, error_msg=None):
    """Get project settings configurations.

    Args:
        connection: MicroStrategy REST API connection object
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object.
    """
    response = connection.session.get(
        url=connection.base_url + f'/api/v2/projects/{id}/settings/config',
        headers={'X-MSTR-ProjectID': None},
    )
    if not response.ok:
        if error_msg is None:
            error_msg = "Error fetching settings configuration"
        response_handler(response, error_msg)
    return response
示例#3
0
def projects(connection, error_msg=None, verbose=False):
    """
    Args:
        connection: MicroStrategy REST API connection object
        verbose (bool, optional): Verbosity of server responses; defaults to False.
    Returns:
        Complete HTTP response object
    """

    response = requests.get(url=connection.base_url + '/api/projects',
                            headers={'X-MSTR-AuthToken': connection.auth_token},
                            cookies=connection.cookies, verify=connection.ssl_verify)
    if verbose:
        print(response.url)
    if not response.ok:
        if error_msg is None:
            error_msg = "Error connecting to project. Check project name and try again."
        response_handler(response, error_msg)
    return response
示例#4
0
def get_privilege_categories(connection, error_msg=None):
    """Get the set of available privilege categories for the platform.

    Args:
        connection: MicroStrategy REST API connection object
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object.
    """
    response = connection.session.get(
        url=connection.base_url + '/api/iserver/privileges/categories',
        headers={'X-MSTR-ProjectID': None},
    )
    if not response.ok:
        if error_msg is None:
            error_msg = "Error getting privilege categories"
        response_handler(response, error_msg)
    return response
示例#5
0
def get_info_for_authenticated_user(connection, error_msg=None):
    """Get information for the authenticated user.

    Args:
        connection: MicroStrategy REST API connection object
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object.
    """
    url = connection.base_url + "/api/sessions/userInfo"
    token = connection.session.headers['X-MSTR-AuthToken']
    headers = {"X-MSTR-AuthToken": token}
    response = connection.session.get(url=url, headers=headers)
    if not response.ok:
        if error_msg is None:
            error_msg = "Error getting info for authenticated user"
        response_handler(response, error_msg)
    return response
示例#6
0
def upload_session(connection, id, body):
    """Create a multi-table dataset upload session.

    Args:
        connection (object): MicroStrategy connection object returned by
            `connection.Connection()`.
        id (str): Identifier of a pre-existing dataset. Used when
            updating a pre-existing dataset.
        body (dict): JSON-formatted payload containing the body of the request.

    Returns:
        HTTP response object returned by the MicroStrategy REST server.
    """
    connection._validate_application_selected()
    response = connection.session.post(
        url=connection.base_url + '/api/datasets/' + id + '/uploadSessions', json=body)
    if not response.ok:
        response_handler(response, "Error creating new data upload session.")
    return response
示例#7
0
def get_datasource_connections(connection, error_msg=None):
    """Get information for all datasource connections.

    Args:
        connection: MicroStrategy REST API connection object
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object. HTTP STATUS 200/400
    """
    url = f"{connection.base_url}/api/datasources/connections"

    response = connection.get(url=url)
    if not response.ok:
        if error_msg is None:
            error_msg = "Error getting Datasource Connections"
        response_handler(response, error_msg)
    response = alter_conn_list_resp(response)
    return response
示例#8
0
def get_datasource_instance(connection, id, error_msg=None):
    """Get information for a specific database source.

    Args:
        connection: MicroStrategy REST API connection object
        id (string): ID
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object. HTTP STATUS 200/400
    """
    url = f"{connection.base_url}/api/datasources/{id}"
    response = connection.get(url=url)
    if not response.ok:
        if error_msg is None:
            error_msg = f"Error getting Datasource Instance with ID: {id}"
        response_handler(response, error_msg)
    response = alter_instance_resp(response)
    return response
示例#9
0
def get_document_definition(connection, id, error_msg=None):
    """Get the hierarchy of a specific dossier in a specific project.

    Args:
        connection: MicroStrategy REST API connection object
        id (string): Dossier ID
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object.
    """
    url = f"{connection.base_url}/api/v2/documents/{id}"
    response = connection.session.get(url=url,
                                      headers={'X-MSTR-ProjectID': None})
    if not response.ok:
        if error_msg is None:
            error_msg = f"Error getting definition of document {id}"
        response_handler(response, error_msg)
    return response
示例#10
0
    def upload_status(self, connection, dataset_id, session_id):
        """Check the status of data that was uploaded to a dataset.

        Args:
            connection: MicroStrategy connection object returned by
                `connection.Connection()`.
            dataset_id (str): Identifier of a pre-existing dataset.
            session_id (str): Identifier of the server session used for
                collecting uploaded data.
        """
        response = datasets.publish_status(connection=connection,
                                           id=dataset_id,
                                           session_id=session_id)

        helper.response_handler(
            response=response,
            msg="Publication status for dataset with ID: '{}':".format(
                dataset_id),
            throw_error=False)
示例#11
0
def get_cube_status(connection, id):
    """Get the status of a specific cube in a specific project.

    Args:
        connection: MicroStrategy REST API connection object.
        id (str): Unique ID of the cube you wish to extract information
            from.

    Returns:
        Complete HTTP response object.
    """
    response = connection.session.head(url=connection.base_url +
                                       '/api/cubes/' + id)

    if not response.ok:
        response_handler(
            response,
            "Error getting cube metadata information. Check Cube ID.")
    return response
示例#12
0
def get_cubes_used_by_document(connection, document_id, error_msg=None):
    """Get the cubes used by a document in a specific project, either directly
    or indirectly.

    Args:
        connection: MicroStrategy REST API connection object
        document_id (string): Document ID
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object.
    """
    url = f"{connection.base_url}/api/documents/{document_id}/cubes"
    response = connection.session.get(url=url)
    if not response.ok:
        if error_msg is None:
            error_msg = f"Error getting cubes used by document {document_id}"
        response_handler(response, error_msg)
    return response
示例#13
0
    def upload_status(self, connection: Connection, id: str, session_id: str):
        """Check the status of data that was uploaded to a super cube.

        Args:
            connection: MicroStrategy connection object returned by
                `connection.Connection()`.
            id (str): Identifier of a pre-existing super cube.
            session_id (str): Identifier of the server session used for
                collecting uploaded data.
        """
        # TODO not sure why we have this functionality twice
        response = datasets.publish_status(connection=connection,
                                           id=id,
                                           session_id=session_id)

        helper.response_handler(
            response=response,
            msg=f"Publication status for super cube with ID: '{id}':",
            throw_error=False)
示例#14
0
def get_users_info(connection,
                   name_begins,
                   abbreviation_begins,
                   offset=0,
                   limit=-1,
                   fields=None,
                   error_msg=None):
    """Get information for a set of users.

    Args:
        connection(object): MicroStrategy connection object returned by
            `connection.Connection()`.
        name_begins(string): Characters that the user name must begin with.
        abbreviation_begins(string): Characters that the user abbreviation must
            begin with.
        offset(int): Starting point within the collection of returned search
            results. Used to control paging behavior.
        limit(int): Maximum number of items returned for a single search
            request. Used to control paging behavior. Use -1 (default ) for no
            limit (subject to governing settings).
        fields(list, optional): Comma separated top-level field whitelist. This
            allows client to selectively retrieve part of the response model.
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        HTTP response object returned by the MicroStrategy REST server.
    """
    response = connection.session.get(url=connection.base_url + '/api/users/',
                                      params={
                                          'nameBegins': name_begins,
                                          'abbreviationBegins':
                                          abbreviation_begins,
                                          'offset': offset,
                                          'limit': limit,
                                          'fields': fields
                                      },
                                      headers={'X-MSTR-ProjectID': None})

    if not response.ok:
        if error_msg is None:
            error_msg = "Error getting information for a set of users."
        response_handler(response, error_msg)
    return response
示例#15
0
def get_security_role(connection, id, error_msg=None):
    """Get information for a security role with security role Id.

    Args:
        connection: MicroStrategy REST API connection object
        id (string): Security role ID
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object.
    """
    response = connection.session.get(url=connection.base_url +
                                      '/api/securityRoles/' + id,
                                      headers={'X-MSTR-ProjectID': None})
    if not response.ok:
        if error_msg is None:
            error_msg = "Error getting role information"
        response_handler(response, error_msg)
    return response
示例#16
0
    def __get_attr_elements_async(self, limit=50000):
        """Get attribute elements.

        Implements GET /cubes/<cube_id>/attributes/<attribute_id>/elements.
        """

        attr_elements = []
        if self.attributes:
            threads = helper.get_parallel_number(len(self.attributes))
            with FuturesSessionWithRenewal(connection=self._connection,
                                           max_workers=threads) as session:
                # Fetch first chunk of attribute elements.
                futures = self.__fetch_attribute_elements_chunks(session, limit)
                pbar = tqdm(futures, desc="Loading attribute elements", leave=False,
                            disable=(not self._progress_bar))
                for i, future in enumerate(pbar):
                    attr = self.attributes[i]
                    response = future.result()
                    if not response.ok:
                        helper.response_handler(
                            response, "Error getting attribute " + attr["name"] + " elements")
                    elements = response.json()
                    # Get total number of rows from headers.
                    total = int(response.headers['x-mstr-total-count'])
                    for _offset in range(limit, total, limit):
                        response = cubes.cube_single_attribute_elements(
                            connection=self._connection,
                            cube_id=self._id,
                            attribute_id=attr["id"],
                            offset=_offset,
                            limit=limit,
                        )
                        elements.extend(response.json())
                    # Append attribute data to the list of attributes.
                    attr_elements.append({
                        "attribute_name": attr['name'],
                        "attribute_id": attr['id'],
                        "elements": elements
                    })
                pbar.close()

            return attr_elements
示例#17
0
def cube_single_attribute_elements(connection,
                                   cube_id,
                                   attribute_id,
                                   offset=0,
                                   limit=200000,
                                   verbose=False):
    """
    Get elements of a specific attribute of a specific cube.

    Args:
        connection: MicroStrategy REST API connection object.
        cube_id (str): Unique ID of the cube you wish to extract information from.
        attribute_id (str): Unique ID of the attribute in the cube.
        verbose (bool): Verbosity of request response; defaults to False.

    Returns:
        Complete HTTP response object.
    """
    res_ok = False
    tries = 0
    while not res_ok and tries < 2:
        response = requests.get(url=connection.base_url + '/api/cubes/' +
                                cube_id + '/attributes/' + attribute_id +
                                '/elements',
                                headers={
                                    'X-MSTR-AuthToken': connection.auth_token,
                                    'X-MSTR-ProjectID': connection.project_id
                                },
                                cookies=connection.cookies,
                                params={
                                    'offset': offset,
                                    'limit': limit
                                },
                                verify=connection.ssl_verify)
        res_ok = response.ok
        tries += 1
    if verbose:
        print(response.url)
    if not response.ok:
        response_handler(
            response, "Error getting attribute " + attribute_id + " elements")
    return response
示例#18
0
def set_vldb_settings(connection,
                      id,
                      type,
                      name,
                      body,
                      project_id=None,
                      error_msg=None):
    """Set vldb settings for one property set in one object.

    Args:
        connection(object): MicroStrategy connection object returned by
            `connection.Connection()`.
        id (str): Object ID
        type (int): DssXmlTypeReportDefinition(3) for Dataset and
            DssXmlTypeDocumentDefinition(55) for document/dossier
        name: property set name
        project_id: project ID
        body: [{"name": "string",
                "value": {}}]
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        HTTP response object returned by the MicroStrategy REST server
    """
    headers = {}
    if project_id:
        headers = {'X-MSTR-ProjectID': project_id}
    else:
        connection._validate_project_selected()
        headers = {'X-MSTR-ProjectID': connection.project_id}

    response = connection.session.put(
        url=f"{connection.base_url}/api/objects/{id}/vldb/propertySets/{name}",
        params={'type': type},
        headers=headers,
        json=body)
    if not response.ok:
        if error_msg is None:
            error_msg = "Error setting vldb settings for object '{}'".format(
                id)
        response_handler(response, error_msg)
    return response
示例#19
0
def get_objects(connection,
                search_id,
                offset=0,
                limit=-1,
                get_tree=False,
                error_msg=None):
    """Get list of objects from metadata.

    Args:
        connection(object): MicroStrategy connection object returned by
            `connection.Connection()`.
        search_id: ID for the results of a previous search stored in I-Server
            memory
        offset: starting point within the collection of returned results. Used
            to control paging behavior.
        limit: maximum number of items returned for a single request. Used to
            control paging behavior
        get_tree: specifies that the search results should be displayed in
            a tree structure instead of a list. The ancestors of the searched
            objects are the nodes and the searched objects are the leaves of
            the tree.
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        HTTP response returned by the MicroStrategy REST server
    """
    connection._validate_application_selected
    response = connection.session.get(
        url=f"{connection.base_url}/api/objects",
        headers={'X-MSTR-ProjectID': connection.project_id},
        params={
            'searchId': search_id,
            'offset': offset,
            'limit': limit,
            'getTree': get_tree
        },
    )
    if not response.ok:
        if error_msg is None:
            error_msg = "Error getting objects."
        response_handler(response, error_msg)
    return response
示例#20
0
def create_search_objects_instance(connection,
                                   name=None,
                                   pattern=4,
                                   domain=2,
                                   root=None,
                                   object_type=None,
                                   error_msg=None):
    """Create a search instance.

    Args:
        connection(object): MicroStrategy connection object returned by
            `connection.Connection()`.
        name: expression used with the pattern to do the search
        pattern: specifies the nature of the search. Possible values are defined
            in the EnumDSSXMLSearchTypes javadoc
        domain: search domain. specifies the domain/scope of the search.
            Possible values are defined in the EnumDSSXMLSearchDomain javadoc
        root: folder ID of the root in which the search is done
        object_type: specifies the type of objects to be searched. Possible
            values are defined in the EnumDSSObjectType javadoc
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        HTTP response returned by the MicroStrategy REST server
    """
    connection._validate_application_selected()
    response = connection.session.post(
        url=f"{connection.base_url}/api/objects",
        headers={'X-MSTR-ProjectID': connection.project_id},
        params={
            'name': name,
            'pattern': pattern,
            'domain': domain,
            'root': root,
            'type': object_type
        },
    )
    if not response.ok:
        if error_msg is None:
            error_msg = "Error getting objects."
        response_handler(response, error_msg)
    return response
示例#21
0
def get_user_group_info(connection, id, error_msg=None):
    """Get information for a specific user group.

    Args:
        connection: MicroStrategy REST API connection object
        id (string): ID of usergroup containing your required privileges
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object.
    """

    response = connection.session.get(url=connection.base_url +
                                      '/api/usergroups/' + id,
                                      headers={'X-MSTR-ProjectID': None})
    if not response.ok:
        if error_msg is None:
            error_msg = "Error getting user group information. Check usergroup id and try again."
        response_handler(response, error_msg)
    return response
示例#22
0
def get_top_level(connection, error_msg=None):
    """Get information for all of the user groups that exist at the level of
    the MicroStrategy Everyone user group.

    Args:
        connection: MicroStrategy REST API connection object
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object.
    """

    response = connection.session.get(url=connection.base_url +
                                      '/api/usergroups/topLevel',
                                      headers={'X-MSTR-ProjectID': None})
    if not response.ok:
        if error_msg is None:
            error_msg = "Error getting user groups top level. Check your privilages and try again."
        response_handler(response, error_msg)
    return response
示例#23
0
def update_iserver_configuration_settings(connection, body, error_msg=None):
    """Update Intelligence Server configuration settings.

    Args:
        connection: MicroStrategy REST API connection object
        body: object with settings to set
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object.
    """
    response = connection.session.put(url=connection.base_url + '/api/admin/restServerSettings/iServer',
                                      headers={'X-MSTR-ProjectID': None,
                                               'Authorization': connection._get_authorization()},
                                      json=body)
    if not response.ok:
        if error_msg is None:
            error_msg = "Error updating Intelligence Server configuration settings."
        response_handler(response, error_msg)
    return response
示例#24
0
def get_iserver_node_settings(connection, node, error_msg=None):
    """Get Intelligence Server configuration settings for a given server node
    within a cluster.

    Args:
        connection: MicroStrategy REST API connection object
        node: Intelligence Server host name
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object.
    """
    response = connection.session.get(url=connection.base_url + '/api/admin/restServerSettings/iServer/' +
                                      node, headers={'X-MSTR-ProjectID': None,
                                                     'Authorization': connection._get_authorization()})
    if not response.ok:
        if error_msg is None:
            error_msg = "Error getting I-Server node settings."
        response_handler(response, error_msg)
    return response
示例#25
0
def update_iserver_settings_OLD(connection, body, error_msg=None):
    """Update some I-Server governing settings.

    Example:
        {"settings": [
            {
            "id": 0,
            "dataType": 0,
            "value": "string"
            }
        ]}
    """
    response = connection.session.put(url=connection.base_url + '/api/iserver/settings',
                                      headers={'X-MSTR-ProjectID': None},
                                      json=body)
    if not response.ok:
        if error_msg is None:
            error_msg = "Error updating I-Server settings"
        response_handler(response, error_msg)
    return response
示例#26
0
def check_iserver_web_trust(connection, error_msg=None):
    """Check to see if there is a trust relationship between the Web Server and
    the Intelligence Server.

    Args:
        connection: MicroStrategy REST API connection object
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object.
    """
    response = connection.session.get(url=connection.base_url +
                                      '/api/admin/restServerSettings/iServer/trustRelationship',
                                      headers={'X-MSTR-ProjectID': None,
                                               'Authorization': connection._get_authorization()})
    if not response.ok:
        if error_msg is None:
            error_msg = "Error checking intelligence server - web server trust relationship"
        response_handler(response, error_msg)
    return response
示例#27
0
def get_rest_configs(connection, error_msg=None):
    """Get configuration settings for the current REST Server, including
    settings for authentication, the Collaboration Server, Google Analytics,
    and the Intelligence Server.

    Args:
        connection: MicroStrategy REST API connection object
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object.
    """
    response = connection.session.get(url=connection.base_url + '/api/admin/restServerSettings',
                                      headers={'X-MSTR-ProjectID': None,
                                               'Authorization': connection._get_authorization()})
    if not response.ok:
        if error_msg is None:
            error_msg = "Error getting rest configurations"
        response_handler(response, error_msg)
    return response
示例#28
0
def stop_ldap_batch_import(connection, error_msg=None):
    """Stop the LDAP batch import if it exists. This operation will be ignored
    if there is no undergoing LDAP batch import.

    Args:
        connection: MicroStrategy REST API connection object
        body: JSON-formatted definition of the dataset. Generated by
            `utils.formjson()`.
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object.
    """
    response = connection.session.put(url=connection.base_url + '/api/iserver/ldap/import',
                                      headers={'X-MSTR-ProjectID': None})
    if not response.ok:
        if error_msg is None:
            error_msg = "Error stopping LDAP batch import"
        response_handler(response, error_msg)
    return response
示例#29
0
def get_ldap_batch_import_status(connection, error_msg=None):
    """Get LDAP batch import status. You can get the progress of LDAP batch
    import, including its status (e.g. failed, stopped, undergoing, and
    canceled). If there is LDAP batch import undergoing, you can also get the
    number of users and groups which have already been imported.

    Args:
        connection: MicroStrategy REST API connection object
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object.
    """
    response = connection.session.get(url=connection.base_url + '/api/iserver/ldap/import',
                                      headers={'X-MSTR-ProjectID': None})
    if not response.ok:
        if error_msg is None:
            error_msg = "Error getting LDAP batch import status"
        response_handler(response, error_msg)
    return response
示例#30
0
def user_privileges(connection):
    """Get the list of privileges for the authenticated user.

    The response includes the name, ID, and description of each
    privilege and specifies which projects the privileges are valid for.

    Args:
        connection: MicroStrategy REST API connection object

    Returns:
        Complete HTTP response object.
    """
    response = connection.session.get(url=connection.base_url +
                                      '/api/sessions/privileges')

    if config.debug:
        print(response.url)
    if not response.ok:
        response_handler(response, "Error getting priviliges list")
    return response