Skip to main content

ENDPOINT

    @staticmethod
    def delete_autodomains():
        '''
        Checks if there are domains starting with
        autodomain and disables them
        '''

        API_ENDPOINT = "https://billing.iriscrm.com/api/disable/clients"
        API_TOKEN = config['token']
        clients = client.Model.get_all(fields=['id', 'name'], only_active=True)
        clients_to_delete = []

        for c in clients:
            if c['id'].startswith('autotestdomain'):
                cli = client.Model.get_by_id(c['id'])
                print("cli.id: " + cli.id + " cli.name: " + cli.name)
                clients_to_delete.append(cli.id)
        if clients_to_delete:
            clients_ids = ','.join(clients_to_delete)
            logging.info('%s clients to delete: %s' % (sys.argv[1], clients_ids))
            params = {'clients': clients_ids,
                      'token': API_TOKEN}
            try:
                r = requests.post(url=API_ENDPOINT, params=params)
                response = r.status_code
                if response == 200:
                    result = json.loads(r.text)
                    if result['code'] == 1:
                        logging.info('%s clients: %s - OK' % (sys.argv[1], clients_ids))
                    else:
                        logging.warning('%s clients: %s - failed: status_code is not 1' % (sys.argv[1], clients_ids))
                else:
                    logging.warning('%s clients: %s - %s' % (sys.argv[1], clients_ids, response))
            except requests.exceptions.RequestException as e:
                logging.warning('%s clients: %s - %s' % (sys.argv[1], clients_ids, e))
                print(e)
        else:
            logging.info('%s nothing found' % (sys.argv[1]))