def do_purge():
    data2purge = getattr(parsed_args, 'data2purge')
    if data2purge is None:
        print 'you MUST specify what to purge'
        sys.exit(1)
    if os.path.isfile(data2purge):
        f = open(data2purge)
        data2purge = f.read()
        f.close()

    data = JsonObject(data2purge, getattr(parsed_args, 'object_type'),
                      getattr(parsed_args, 'domain'),
                      getattr(parsed_args, 'akamai_action')).get_json()

    do_request_and_handle_response(purge_request_post_uri,
                                   method='POST',
                                   data=data,
                                   original_success=201)
    def build_response_message(self, response, orig_data):
        subject = 'Your Akamai content removal request (%s)' % response.get('purgeId')

        if orig_data.get('type').upper() == 'CPCODE':
            objects = '\n'.join(x + ' (' + JsonObject.transform_cpcode(x) + ')' for x in orig_data.get('objects'))
        else:
            objects = '\n'.join(orig_data.get('objects'))

        msg = 'This message confirms that your Akamai content removal request has been processed by all active servers on our network. Here are the details.\n\n'
        msg += 'ID:                %s\n' % response.get('purgeId')
        msg += 'Domain:            %s\n' % orig_data.get('domain')
        msg += 'Requestor:         %s\n' % response.get('submittedBy')
        msg += 'Submission time:   %s\n' % DateConverter.convert_date(response.get('submissionTime'))
        msg += 'Completion time:   %s\n' % DateConverter.convert_date(response.get('completionTime'))
        msg += '\n'
        msg += 'Content purged:\n\n'
        msg += '%s %s(s)\n\n%s' % (orig_data.get('action'), orig_data.get('type'), objects)

        return subject, msg
def epilog(name):
    return textwrap.dedent(
        '''\
        - file auth must be present and contain a dict with username and password e.g. {'username': '******', 'password': '******'}
        - file cpcode must be present and contain a dict with cpode and human readable name for it e.g. {111: 'FOO', 222: 'BAR'}
        - file email_settings must be present e.g. {'default_sender': '*****@*****.**', 'default_recipient': '*****@*****.**'}
        some examples
        --------------------------------
        %s --do_purge -data testdata.txt (for purging the content of file testdata.txt - since no object_type is given, the content is assumend URLs)
        %s --do_purge -data "www.foo.bar/test1, www.bar.foo/test2?me" (for purging www.foo.bar/test1 and www.bar.foo/test2?me)
        %s --do_purge --object_type cpcode -data 12345 (for purging the content of the cpcode 12345)
        %s --do_purge --object_type cpcode -data 12345 --send_mail_on_success True --email_recipients "*****@*****.**" (for purging the content of the cpcode 12345 and sending the response/result to the given email-address)
        %s --do_purge --object_type cpcode -data FOO --domain staging (for purging the content of the cpcode FOO in staging, where FOO is a mapped cpcode for better reading and understanding)
        %s --do_check_status
        %s --do_check_queues
        valid cpcodes are %s
        for more examples and possibilities refer to https://api.ccu.akamai.com/ccu/v2/docs/index.html#section_Reference and read the optional arguments from this program
    ''' %
        (name, name, name, name, name, name, name, JsonObject.print_cpcode()))
def epilog(name):
    return textwrap.dedent(
        """\
        - file auth must be present and contain a dict with username and password e.g. {'username': '******', 'password': '******'}
        - file cpcode must be present and contain a dict with cpode and human readable name for it e.g. {111: 'FOO', 222: 'BAR'}
        - file email_settings must be present e.g. {'default_sender': '*****@*****.**', 'default_recipient': '*****@*****.**'}
        some examples
        --------------------------------
        %s --do_purge -data testdata.txt (for purging the content of file testdata.txt - since no object_type is given, the content is assumend URLs)
        %s --do_purge -data "www.foo.bar/test1, www.bar.foo/test2?me" (for purging www.foo.bar/test1 and www.bar.foo/test2?me)
        %s --do_purge --object_type cpcode -data 12345 (for purging the content of the cpcode 12345)
        %s --do_purge --object_type cpcode -data 12345 --send_mail_on_success True --email_recipients "*****@*****.**" (for purging the content of the cpcode 12345 and sending the response/result to the given email-address)
        %s --do_purge --object_type cpcode -data FOO --domain staging (for purging the content of the cpcode FOO in staging, where FOO is a mapped cpcode for better reading and understanding)
        %s --do_check_status
        %s --do_check_queues
        valid cpcodes are %s
        for more examples and possibilities refer to https://api.ccu.akamai.com/ccu/v2/docs/index.html#section_Reference and read the optional arguments from this program
    """
        % (name, name, name, name, name, name, name, JsonObject.print_cpcode())
    )
Exemplo n.º 5
0
    def build_response_message(self, response, orig_data):
        subject = 'Your Akamai content removal request (%s)' % response.get(
            'purgeId')

        if orig_data.get('type').upper() == 'CPCODE':
            objects = '\n'.join(x + ' (' + JsonObject.transform_cpcode(x) + ')'
                                for x in orig_data.get('objects'))
        else:
            objects = '\n'.join(orig_data.get('objects'))

        msg = 'This message confirms that your Akamai content removal request has been processed by all active servers on our network. Here are the details.\n\n'
        msg += 'ID:                %s\n' % response.get('purgeId')
        msg += 'Domain:            %s\n' % orig_data.get('domain')
        msg += 'Requestor:         %s\n' % response.get('submittedBy')
        msg += 'Submission time:   %s\n' % DateConverter.convert_date(
            response.get('submissionTime'))
        msg += 'Completion time:   %s\n' % DateConverter.convert_date(
            response.get('completionTime'))
        msg += '\n'
        msg += 'Content purged:\n\n'
        msg += '%s %s(s)\n\n%s' % (orig_data.get('action'),
                                   orig_data.get('type'), objects)

        return subject, msg