Ejemplo n.º 1
0
def list_folders(connection: Connection,
                 project_id: Optional[str] = None,
                 offset: int = 0,
                 limit: int = 5000,
                 error_msg: Optional[str] = None):
    """Get a list of folders.

    Args:
        connection: MicroStrategy REST API connection object
        project_id (string, optional): id of project
        offset (int, optional): Starting point within the collection of returned
            results. Used to control paging behavior. Default is 0.
        limit (int, optional): Maximum number of items returned for a single
            request. Used to control paging behavior. Use -1 for no limit.
            Default is 5000.

    Returns:
        Complete HTTP response object.
    """
    return connection.get(url=f"{connection.base_url}/api/folders",
                          headers={'X-MSTR-ProjectID': project_id},
                          params={
                              'offset': offset,
                              'limit': limit
                          })
Ejemplo n.º 2
0
def get_predefined_folder_contents(connection: Connection,
                                   folder_type: int,
                                   project_id: Optional[str] = None,
                                   offset: int = 0,
                                   limit: int = 5000,
                                   error_msg: Optional[str] = None):
    """Get contents of a pre-defined folder.

    Args:
        connection: MicroStrategy REST API connection object
        folder_type (int): predefined folder type, from `EnumDSSXMLFolderNames`
        project_id (string, optional): id of project
        offset (int, optional): Starting point within the collection of returned
            results. Used to control paging behavior. Default is 0.
        limit (int, optional): Maximum number of items returned for a single
            request. Used to control paging behavior. Use -1 for no limit.
            Default is 5000.

    Returns:
        Complete HTTP response object.
    """
    if project_id is None:
        connection._validate_project_selected()
        project_id = connection.project_id

    return connection.get(
        url=f"{connection.base_url}/api/folders/preDefined/{folder_type}",
        headers={'X-MSTR-ProjectID': project_id},
        params={
            'offset': offset,
            'limit': limit
        })
Ejemplo n.º 3
0
def get_package_holder(connection: Connection,
                       id: str,
                       project_id: Optional[str] = None,
                       show_content: bool = True,
                       error_msg: Optional[str] = None) -> requests.Response:
    """Get definition of a package, including package status and its detail
    content.

    Args:
        connection (Connection): Object representation of connection to
            MSTR Server.
        id (str): ID of the package to be retrieved.
        project_id (Optional[str]): Optional ID of a project. Defaults to None.
        show_content (bool, optional): Show package content or not. Defaults to
        False.
        error_msg (Optional[str]): Optional error message. Defaults to None.

    Returns:
        requests.Response: Response object containing all of the information
        returned by the server.
    """
    project_id = project_id if project_id is not None else connection.project_id

    return connection.get(url=f'{connection.base_url}/api/packages/{id}',
                          headers={'X-MSTR-ProjectID': project_id},
                          params={'showContent': show_content})
Ejemplo n.º 4
0
def get_device(connection: Connection, id: str, error_msg: Optional[str] = None):
    """Get device by a specific id.

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

    Returns:
        Complete HTTP response object. Expected status is 200.
    """
    url = f"{connection.base_url}/api/v2/devices/{id}"
    return connection.get(url=url)
Ejemplo n.º 5
0
def get_datasource_logins(connection: Connection,
                          error_msg: Optional[str] = None):
    """Get information for all datasource logins.

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

    Returns:
        Complete HTTP response object. Expected status is 200.
    """
    url = f"{connection.base_url}/api/datasources/logins"
    return connection.get(url=url)
Ejemplo n.º 6
0
def get_devices(connection: Connection, device_type: Optional[str] = None,
                fields: Optional[str] = None, error_msg: Optional[str] = None):
    """Get information for all devices.

    Args:
        connection: MicroStrategy REST API connection object
        fields(list, optional): Comma separated top-level field whitelist. This
            allows client to selectively retrieve part of the response model.
        device_type (str, optional): Device type, Supported values are: email,
            file, ftp, printer, ipad, iphone, android, all.
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object. Expected status is 200.
    """
    url = f"{connection.base_url}/api/v2/devices/"
    params = {'fields': fields, 'deviceType': device_type}
    return connection.get(url=url, params=params)
Ejemplo n.º 7
0
def get_my_personal_objects_contents(connection: Connection,
                                     project_id: Optional[str] = None):
    """Get contents of My Personal Objects folder.

    Args:
        connection: MicroStrategy REST API connection object
        project_id (string, optional): id of project

    Returns:
         Complete HTTP response object.
    """
    if project_id is None:
        connection._validate_project_selected()
        project_id = connection.project_id

    return connection.get(
        url=f"{connection.base_url}/api/folders/myPersonalObjects",
        headers={'X-MSTR-ProjectID': project_id})
Ejemplo n.º 8
0
def get_datasource_mapping(connection: Connection,
                           id=str,
                           default_connection_map: Optional[bool] = False,
                           project_id: Optional[str] = None,
                           error_msg: Optional[str] = None):
    """Get information about specific datasource_mapping.

    Args:
        connection: MicroStrategy REST API connection object
        id: ID of the mapping
        default_connection_map (bool, optional): If True will get the default
            connection map for a project. Requires `project_id`
            parameter. Default False.
        project_id: The project_id, required only for default connection
            map.
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object. Expected status is 200.
    """
    url = f"{connection.base_url}/api/datasources/mappings"
    response = connection.get(url=url,
                              params={
                                  "defaultConnectionMap":
                                  default_connection_map,
                                  "projectId": project_id
                              })

    # Faking get single resource endpoint. Only 'list all' available on REST
    if response.ok:
        response_json = response.json()
        if 'mappings' in response_json.keys():
            mappings = [
                mapping for mapping in response_json['mappings']
                if mapping["id"] == id
            ]
            if len(mappings) > 0:
                response_json = mappings[0]
                response_json['ds_connection'] = response_json.pop(
                    'connection')
        response.encoding, response._content = 'utf-8', json.dumps(
            response_json).encode('utf-8')
    return response
Ejemplo n.º 9
0
def get_contacts(connection: Connection, offset: int = 0, limit: int = -1,
                 fields: Optional[str] = None, error_msg: Optional[str] = None):
    """Get information for all contacts.

    Args:
        connection: MicroStrategy REST API connection object
        fields(list, optional): Comma separated top-level field whitelist. This
            allows client to selectively retrieve part of the response model.
        offset (integer, optional): Starting point within the collection of
            returned search results. Used to control paging behavior.
        limit (integer, optional): Maximum number of items returned for a single
            search request. Used to control paging behavior. Use -1 for no limit
            (subject to governing settings).
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object. Expected status is 200.
    """
    url = f"{connection.base_url}/api/contacts/"
    params = {'fields': fields, 'offset': offset, 'limit': limit}
    return connection.get(url=url, params=params)
Ejemplo n.º 10
0
def download_package(connection: Connection,
                     id: str,
                     project_id: Optional[str] = None,
                     error_msg: Optional[str] = None) -> requests.Response:
    """Download a package binary.

    Args:
        connection (Connection): Object representation of connection to
            MSTR Server.
        id (str): ID of the package to be downloaded.
        project_id (Optional[str]): Optional ID of a project. Defaults to None.
        error_msg (Optional[str]): Optional error message. Defaults to None.

    Returns:
        requests.Response: Response object containing all of the information
        returned by the server.
    """
    project_id = project_id if project_id is not None else connection.project_id
    return connection.get(
        url=f'{connection.base_url}/api/packages/{id}/binary',
        headers={'X-MSTR-ProjectID': project_id})
Ejemplo n.º 11
0
def get_import(connection: Connection,
               id: str,
               project_id: Optional[str] = None,
               error_msg: Optional[str] = None) -> requests.Response:
    """Get result of a package import process.

    Args:
        connection (Connection): Object representation of connection to
            MSTR Server.
        id (str): Import process ID.
        project_id (Optional[str]): Optional ID of a project. Defaults to None.
        error_msg (Optional[str]): Optional error message. Defaults to None.

    Returns:
        requests.Response: Response object containing all of the information
        returned by the server.
    """
    project_id = project_id if project_id is not None else connection.project_id
    return connection.get(
        url=f'{connection.base_url}/api/packages/imports/{id}',
        headers={'X-MSTR-ProjectID': project_id})
Ejemplo n.º 12
0
def get_datasource_mappings(connection: Connection,
                            default_connection_map: Optional[bool] = False,
                            project_id: Optional[str] = None,
                            error_msg: Optional[str] = None):
    """Get information for all datasource connection mappings.

    Args:
        connection: MicroStrategy REST API connection object
        default_connection_map (bool, optional): If True will get the default
            connection map for an project. Requires `project_id`
            parameter. Default False.
        project_id: The project_id, required only for default connection
            map.
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object. Expected status is 200.
    """
    url = f"{connection.base_url}/api/datasources/mappings"
    return connection.get(url=url,
                          params={
                              "defaultConnectionMap": default_connection_map,
                              "projectId": project_id
                          })