Beispiel #1
0
    def _list_security_roles(
        cls,
        connection: "Connection",
        to_dictionary: bool = False,
        to_dataframe: bool = False,
        limit: int = None,
        **filters
    ) -> Union[List["SecurityRole"], List[Dict[str, Any]], DataFrame]:
        if to_dictionary and to_dataframe:
            helper.exception_handler(
                "Please select either to_dictionary=True or to_dataframe=True, but not both.",
                ValueError)

        objects = helper.fetch_objects(
            connection=connection,
            api=security.get_security_roles,
            limit=limit,
            filters=filters,
        )
        if to_dictionary:
            return objects
        elif to_dataframe:
            return DataFrame(objects)
        else:
            return [
                cls.from_dict(source=obj, connection=connection)
                for obj in objects
            ]
Beispiel #2
0
    def list_privileges(cls, connection: Connection, to_dictionary: bool = False,
                        to_dataframe: bool = False,
                        **filters) -> Union[List["Privilege"], List[dict], DataFrame]:
        """Get list of privilege objects or privilege dicts. Filter the
        privileges by specifying the `filters` keyword arguments.

        Optionally use `to_dictionary` or `to_dataframe` to choose output
        format.

        Args:
            connection: MicroStrategy connection object returned by
                `connection.Connection()`.
            to_dictionary: If `True` returns dict, by default (False) returns
                User objects.
            to_dataframe: If `True`, returns `DataFrame`.
            **filters: Available filter parameters: ['id', 'name',
                'description', 'categories', 'is_project_level_privilege']

        Examples:
            >>> Privilege.list_privileges(connection, to_dataframe=True,
            >>>                           is_project_level_privilege='True',
            >>>                           id=[1,2,3,4,5])
        """
        if to_dictionary and to_dataframe:
            helper.exception_handler(
                "Please select either `to_dictionary=True` or `to_dataframe=True`, but not both.",
                ValueError)
        objects = helper.fetch_objects(connection=connection, api=security.get_privileges,
                                       limit=None, filters=filters)
        if to_dictionary:
            return objects
        elif to_dataframe:
            return DataFrame(objects)
        else:
            return [cls.from_dict(source=obj, connection=connection) for obj in objects]
Beispiel #3
0
 def _list_datasource_instances(
         cls,
         connection: "Connection",
         to_dictionary: Optional[bool] = False,
         limit: Optional[int] = None,
         ids: Optional[list] = None,
         database_types: Optional[list] = None,
         project: Optional[Union["Project", str]] = None,
         **filters) -> Union[List["DatasourceInstance"], List[dict]]:
     objects = helper.fetch_objects(
         connection=connection,
         api=datasources.get_datasource_instances,
         dict_unpack_value="datasources",
         limit=limit,
         filters=filters,
         ids=ids,
         database_types=database_types,
         project=project)
     if to_dictionary:
         return objects
     else:
         return [
             cls.from_dict(source=obj, connection=connection)
             for obj in objects
         ]
 def _list(cls,
           connection: Connection,
           default_connection_map: Optional[bool] = False,
           project: Optional[Union[Project, str]] = None,
           to_dictionary: bool = False,
           limit: Optional[int] = None,
           **filters) -> Union[List["DatasourceMap"], List[dict]]:
     project_id = project.id if isinstance(project, Project) else project
     try:
         mappings = helper.fetch_objects(
             connection=connection,
             api=datasources.get_datasource_mappings,
             default_connection_map=default_connection_map,
             project_id=project_id,
             limit=limit,
             dict_unpack_value="mappings",
             filters=filters)
     except HTTPError as err:
         if err.errno == 404:
             if config.verbose:
                 logger.info('No mapping found.')
             return None
         else:
             raise err
     if to_dictionary:
         return mappings
     else:
         return [
             cls.from_dict(source=elem, connection=connection)
             for elem in mappings
         ]
Beispiel #5
0
def list_schedules(connection: Connection,
                   to_dictionary: bool = False,
                   limit: int = None,
                   **filters) -> Union[List["Schedule"], List[dict]]:
    """List schedule objects or schedule dictionaries. Optionally filter list.

    Args:
        connection(object): MicroStrategy connection object returned by
            'connection.Connection()'
        to_dictionary(bool, optional): if True, return Schedules as
            list of dicts
        limit(int, optional): maximum number of schedules returned.
        **filters: Available filter parameters:['name':,
                                                'id',
                                                'description',
                                                'schedule_type',
                                                'start_date',
                                                'expired']
    Returns:
        Union[List["Schedule"], List[dict]]: [description]
    """

    objects = helper.fetch_objects(connection=connection,
                                   api=schedules.list_schedules,
                                   limit=limit,
                                   filters=filters,
                                   dict_unpack_value='schedules')

    if to_dictionary:
        return objects
    else:
        return [
            Schedule.from_dict(source=obj, connection=connection)
            for obj in objects
        ]
Beispiel #6
0
    def list_connections(self,
                         nodes: Union[str, List[str]] = None,
                         limit: Optional[int] = None,
                         **filters) -> List[Dict[str, Any]]:
        """Get all active database connections. Optionally filter the
         connections by specifying the `filters` keyword arguments.

        Args:
            nodes: Node (server) names on which databases will be disconnected.
            limit: limit the number of elements returned. If `None`, all objects
                are returned.
            **filters: Available filter parameters: ['status',
                'database_instance_name', 'database_instance_id', 'user_name',
                'database_login_name', 'cluster_node', 'id', 'name', 'type']
        """
        if nodes is None:
            all_nodes = Cluster(self.connection).list_nodes(to_dictionary=True)
            nodes = [n['name'] for n in all_nodes if n['status'] == 'running']

        nodes_names = ",".join(nodes) if isinstance(nodes, list) else nodes
        all_databases = helper.fetch_objects(
            connection=self.connection,
            api=monitors.get_database_connections,
            nodes_names=nodes_names,
            dict_unpack_value="dbConnectionInstances",
            limit=limit,
            filters=filters)
        return all_databases
Beispiel #7
0
    def _list_contacts(cls, connection: 'Connection', to_dictionary: bool = False,
                       limit: Optional[int] = None, **filters
                       ) -> Union[List['Contact'], List[dict]]:
        """Get all contacts as list of Contact objects or dictionaries.

        Optionally filter the contacts by specifying filters.

        Args:
            connection: MicroStrategy connection object
            to_dictionary: If True returns a list of contact dicts,
               otherwise returns a list of contact objects
           limit: limit the number of elements returned. If `None` (default),
               all objects are returned.
           **filters: Available filter parameters:
               ['id', 'name', 'description', 'enabled']
        """

        objects = fetch_objects(
            connection=connection,
            api=contacts.get_contacts,
            limit=limit,
            filters=filters,
            dict_unpack_value='contacts'
        )

        if to_dictionary:
            return objects

        return [
            cls.from_dict(source=obj, connection=connection)
            for obj in objects
        ]
Beispiel #8
0
    def _list_available_dbms(cls,
                             connection: "Connection",
                             to_dictionary: bool = False,
                             limit: int = None,
                             **filters) -> Union[List["Dbms"], List[dict]]:

        objects = helper.fetch_objects(connection=connection,
                                       api=datasources.get_available_dbms,
                                       limit=None,
                                       filters=None)
        cls._DBMS_CACHE.update([
            cls.from_dict(source=obj, connection=connection) for obj in objects
        ])

        if limit:
            objects = objects[:limit]
        if filters:
            objects = helper.filter_list_of_dicts(objects, **filters)
        if to_dictionary:
            return objects
        else:
            return [
                cls.from_dict(source=obj, connection=connection)
                for obj in objects
            ]
Beispiel #9
0
 def _list_datasource_logins(cls, connection: "Connection", to_dictionary: bool = False,
                             limit: int = None,
                             **filters) -> Union[List["DatasourceLogin"], List[dict]]:
     objects = helper.fetch_objects(connection=connection,
                                    api=datasources.get_datasource_logins,
                                    dict_unpack_value="logins", limit=limit, filters=filters)
     if to_dictionary:
         return objects
     else:
         return [cls.from_dict(source=obj, connection=connection) for obj in objects]
Beispiel #10
0
 def _list_devices(cls,
                   connection: "Connection",
                   to_dictionary: bool = False,
                   limit: int = None,
                   **filters) -> Union[List["Device"], List[dict]]:
     objects = fetch_objects(
         connection=connection,
         api=devices.get_devices,
         dict_unpack_value="devices",
         limit=limit,
         filters=filters,
     )
     if to_dictionary:
         return objects
     return [
         cls.from_dict(source=obj, connection=connection) for obj in objects
     ]
Beispiel #11
0
def get_shortcuts(connection: Connection,
                  project_id: str,
                  shortcut_ids: List[str],
                  shortcut_info_flag: Union[
                      ShortcutInfoFlags,
                      int] = ShortcutInfoFlags.DssDossierShortcutInfoDefault,
                  to_dictionary: bool = False,
                  limit: Optional[int] = None,
                  **filters) -> Union[List[dict], List[Shortcut]]:
    """Retrieve information about specific published shortcuts
    in specific project.

    Args:
        shortcut_ids: ids of target shortcuts
        project_id: id of project that the shortcuts are in
        shortcut_info_flag: a single ShortcutInfoFlags that describes what
          exact info are to be fetched
        to_dictionary: parameter describing output format
        limit (int): limit the number of elements returned. If `None` (default),
            all objects are returned.
    Return:
        list of dictionaries or Shortcut objects,
          depending on `to_dictionary` parameter
    """

    shortcuts = fetch_objects(
        connection=connection,
        api=browsing.get_shortcuts,
        dict_unpack_value="shortcuts",
        limit=limit,
        filters=filters,
        body=[{
            "projectId": project_id,
            "shortcutIds": shortcut_ids
        }],
        shortcut_info_flag=get_enum_val(shortcut_info_flag, ShortcutInfoFlags),
    )

    if to_dictionary:
        return shortcuts
    else:
        return [
            Shortcut.from_dict(source=short, connection=connection)
            for short in shortcuts
        ]
Beispiel #12
0
    def _list_transmitters(
            cls,
            connection: "Connection",
            to_dictionary: bool = False,
            limit: Optional[int] = None,
            **filters) -> Union[List["Transmitter"], List[dict]]:
        """Helper method for listing transmitters."""
        objects = fetch_objects(
            connection=connection,
            api=transmitters.get_transmitters,
            limit=limit,
            filters=filters,
            dict_unpack_value="transmitters",
        )

        if to_dictionary:
            return objects
        return [
            Transmitter.from_dict(source=obj, connection=connection)
            for obj in objects
        ]