Ejemplo n.º 1
0
    def get_global_rules(self) -> list:
        """List of existing rules

        Example:

        [{'action': 'block',
         'description': '',
         'id': 34,
         'last_updated': 1580783107664,
         'last_updated_administrator': 34,
         'sha256': '7F83B1657FF1FC53B92DC18148A1D65DFC2D4B1FA3D677284ADDD200126D9069'},
         {'action': 'block',
         'description': 'demo',
         'id': 35,
         'last_updated': 1580783365699,
         'last_updated_administrator': 34,
         'sha256': '7F83B1657FF1FC53B92DC18148A1D65DFC2D4B1FA3D677284ADDD200126D9068'},
         {'action': 'block',
         'description': 'demo',
         'id': 36,
         'last_updated': 1580783934705,
         'last_updated_administrator': 100,
         'sha256': '7F83B1657FF1FC53B92DC18148A1D65DFC2D4B1FA3D677284ADDD200126D9022'},
         {'action': 'block',
         'description': 'demo',
         'id': 37,
         'last_updated': 1580784663099,
         'last_updated_administrator': 100,
         'sha256': '7F83B1657FF1FC53B92DC18148A1D65DFC2D4B1FA3D677284ADDD200126D9023'}]

        :return: List of <class 'deepsecurity.models.application_control_global_rule.ApplicationControlGlobalRule'>
        """

        print('Reading existing rules from Deep Security...')

        try:
            global_rules_api = api.GlobalRulesApi(self.api_client)
            api_response = global_rules_api.list_global_rules(self.api_version)
            extracted_rules = api_response.application_control_global_rules

            if extracted_rules:
                pprint(extracted_rules)

            else:
                print('There are no existing rules')

            return extracted_rules

        except ApiException as e:
            self._format_exception(e)
Ejemplo n.º 2
0
    def delete_global_rules(self, rules):
        global_rules_api = api.GlobalRulesApi(self.api_client)

        for rule in rules:
            print(f'Deleting rule ID: {rule}')

            try:
                api_response = global_rules_api.delete_global_rule(
                    rule, self.api_version)

                if api_response:
                    pprint(api_response)

                else:
                    print('Done')

            except ApiException as e:
                self._format_exception(e)
Ejemplo n.º 3
0
    def create_global_rules(
        self, rules_array
    ) -> api.models.application_control_global_rules.ApplicationControlGlobalRules:
        """Creates global rules on Deep Security

        Example:

        [{'action': 'block',
         'description': '',
         'id': 34,
         'last_updated': 1580783107664,
         'last_updated_administrator': 34,
         'sha256': '7F83B1657FF1FC53B92DC18148A1D65DFC2D4B1FA3D677284ADDD200126D9069'},
         {'action': 'block',
         'description': 'demo',
         'id': 35,
         'last_updated': 1580783365699,
         'last_updated_administrator': 34,
         'sha256': '7F83B1657FF1FC53B92DC18148A1D65DFC2D4B1FA3D677284ADDD200126D9068'},
         {'action': 'block',
         'description': 'demo',
         'id': 36,
         'last_updated': 1580783934705,
         'last_updated_administrator': 100,
         'sha256': '7F83B1657FF1FC53B92DC18148A1D65DFC2D4B1FA3D677284ADDD200126D9022'},
         {'action': 'block',
         'description': 'demo',
         'id': 37,
         'last_updated': 1580784663099,
         'last_updated_administrator': 100,
         'sha256': '7F83B1657FF1FC53B92DC18148A1D65DFC2D4B1FA3D677284ADDD200126D9023'},
         {'action': 'block',
         'description': 'demo_1',
         'id': 67,
         'last_updated': 1580867088483,
         'last_updated_administrator': 100,
         'sha256': '7F83B1657FF1FC53B92DC18148A1D65DFC2D4B1FA3D677284ADDD200126D9011'},
         {'action': 'block',
         'description': 'demo_3',
         'id': 68,
         'last_updated': 1580867088495,
         'last_updated_administrator': 100,
         'sha256': '7F83B1657FF1FC53B92DC18148A1D65DFC2D4B1FA3D677284ADDD200126D9033'},
         {'action': 'block',
         'description': 'demo_4',
         'id': 69,
         'last_updated': 1580867188053,
         'last_updated_administrator': 100,
         'sha256': '7F83B1657FF1FC53B92DC18148A1D65DFC2D4B1FA3D677284ADDD200126D9044'},
         {'action': 'block',
         'description': 'demo_5',
         'id': 70,
         'last_updated': 1580867476445,
         'last_updated_administrator': 100,
         'sha256': '7F83B1657FF1FC53B92DC18148A1D65DFC2D4B1FA3D677284ADDD200126D9055'},
         {'action': 'block',
         'description': 'demo_6',
         'id': 71,
         'last_updated': 1580867996552,
         'last_updated_administrator': 100,
         'sha256': '7F83B1657FF1FC53B92DC18148A1D65DFC2D4B1FA3D677284ADDD200126D9066'},
         {'action': 'block',
         'description': 'demo_7',
         'id': 72,
         'last_updated': 1580868101929,
         'last_updated_administrator': 100,
         'sha256': '7F83B1657FF1FC53B92DC18148A1D65DFC2D4B1FA3D677284ADDD200126D9077'},
         {'action': 'block',
         'description': 'demo_8',
         'id': 73,
         'last_updated': 1580868415308,
         'last_updated_administrator': 100,
         'sha256': '7F83B1657FF1FC53B92DC18148A1D65DFC2D4B1FA3D677284ADDD200126D9088'},
         {'action': 'block',
         'description': 'demo_9',
         'id': 74,
         'last_updated': 1580868604360,
         'last_updated_administrator': 100,
         'sha256': '7F83B1657FF1FC53B92DC18148A1D65DFC2D4B1FA3D677284ADDD200126D9099'}]

        """

        global_rules_api = api.GlobalRulesApi(self.api_client)
        rules_list = api.ApplicationControlGlobalRules()
        rules_list.application_control_global_rules = rules_array

        try:
            global_rules_api.add_global_rules(rules_list, self.api_version)
            api_response = global_rules_api.list_global_rules(self.api_version)
            global_rules = api_response.application_control_global_rules

            print('\nUpdated Deep Security global rule list:')
            pprint(global_rules)

            return global_rules

        except ApiException as e:
            self._format_exception(e)