Example #1
0
def create_folder(connection: Connection,
                  name: str,
                  parent_id: str,
                  description: Optional[str] = None,
                  project_id: Optional[str] = None):
    """Create a folder.

    Note:
        When `project_id` is provided then folder will be created in this
        project. Otherwise it will be created in a project selected within
        `connection` object.

    Args:
        connection: MicroStrategy REST API connection object
        name (string): name of folder to create
        parent_id (string): id of folder in which new folder will be created
        description (string, optional): description of folder to create
        project_id (string, optional): id of project

    Returns:
        Complete HTTP response object.
    """
    project_id = project_id if project_id is not None else connection.project_id
    body = {
        "name": name,
        "description": description,
        "parent": parent_id,
    }
    return connection.post(url=connection.base_url + '/api/folders',
                           headers={'X-MSTR-ProjectID': project_id},
                           json=body)
Example #2
0
def create_device(connection: Connection, body: dict, error_msg: Optional[str] = None):
    """Create a new device.

    Args:
        connection: MicroStrategy REST API connection object
        body: Device creation info.
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object. Expected status is 201.
    """
    url = f"{connection.base_url}/api/v2/devices/"
    return connection.post(url=url, json=body)
Example #3
0
def create_datasource_login(connection: Connection,
                            body,
                            error_msg: Optional[str] = None):
    """Create a new datasource login.

    Args:
        connection: MicroStrategy REST API connection object
        body: Datasource login creation info.
        error_msg (string, optional): Custom Error Message for Error Handling

    Returns:
        Complete HTTP response object. Expected status is 201.
    """
    url = f"{connection.base_url}/api/datasources/logins"
    return connection.post(url=url, json=body)
Example #4
0
def create_package_holder(
        connection: Connection,
        project_id: Optional[str] = None,
        error_msg: Optional[str] = None) -> requests.Response:
    """Create a new in-memory metadata package holder.

    Args:
        connection (Connection): Object representation of connection to
            MSTR Server.
        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.post(url=f'{connection.base_url}/api/packages',
                           headers={'X-MSTR-ProjectID': project_id})
Example #5
0
def create_import(connection: Connection,
                  id: str,
                  project_id: Optional[str] = None,
                  generate_undo: bool = False,
                  error_msg: Optional[str] = None) -> requests.Response:
    """Create a package import process.

    Args:
        connection (Connection): Object representation of connection to
            MSTR Server.
        id (str): ID of the package for which import process will be
        created.
        generate_undo (bool, optional): Generate undo package or not. Defaults
        to False.
        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.
    """

    # TODO: Change to a parameter when any other values are supported
    prefer = 'respond-async'

    project_id = project_id if project_id is not None else connection.project_id
    return connection.post(
        url=f'{connection.base_url}/api/packages/imports',
        headers={
            'X-MSTR-ProjectID': project_id,
            'Prefer': prefer
        },
        params={
            'packageId': id,
            'generateUndo': generate_undo
        },
    )