Exemplo n.º 1
0
    def __init__(self):
        self.session = requests.Session()
        self.debug = False
        self.verbose = False
        self.section_name = "papi"

        # If all parameters are set already, use them.  Otherwise
        # use the config
        self.config = EdgeGridConfig({}, self.section_name)

        if hasattr(self.config, "debug") and self.config.debug:
            self.debug = True

        if hasattr(self.config, "verbose") and self.config.verbose:
            self.verbose = True

        # Set the config options
        self.session.auth = EdgeGridAuth(
            client_token=self.config.client_token,
            client_secret=self.config.client_secret,
            access_token=self.config.access_token)

        if hasattr(self.config, 'headers'):
            self.session.headers.update(self.config.headers)

        self.baseurl = '%s://%s/' % ('https', self.config.host)
        self.httpCaller = EdgeGridHttpCaller(self.session, self.debug,
                                             self.verbose, self.baseurl)
Exemplo n.º 2
0
def lambda_handler(event, context):
    invalidation_items = event['invalidation_items']
    if event['source'] == "Akamai":
        import requests, json
        from http_calls import EdgeGridHttpCaller
        from akamai.edgegrid import EdgeGridAuth
        creds = event['credentials']

        session = requests.Session()
        debug = False
        verbose = False
        section_name = "default"

        # Set the config options
        session.auth = EdgeGridAuth(client_token=creds['client_token'],
                                    client_secret=creds['client_secret'],
                                    access_token=creds['access_token'])

        baseurl = '%s://%s/' % ('https', creds['host'])
        httpCaller = EdgeGridHttpCaller(session, debug, verbose, baseurl)

        purge_obj = {
            "objects": invalidation_items,
            "hostname": "",
            "action": "remove",
            "type": "arl",
            "domain": "production"
        }
        purge_post_result = httpCaller.postResult('/ccu/v3/invalidate/url',
                                                  json.dumps(purge_obj))
        return {"success": True, "message": purge_post_result}

    else:
        if "distribution_id" in event and "credentials" in event:
            distribution_id = event['distribution_id']
            quantity = event['quantity']

            creds = event['credentials']

            if distribution_id:
                client = boto3.client(
                    'cloudfront',
                    aws_access_key_id=creds["aws_access_key_id"],
                    aws_secret_access_key=creds['aws_secret_access_key'])
                invalidation = client.create_invalidation(
                    DistributionId=distribution_id,
                    InvalidationBatch={
                        'Paths': {
                            'Quantity': quantity,
                            'Items': invalidation_items
                        },
                        'CallerReference': str(time.time())
                    })
        return {"success": True, "message": invalidation}
Exemplo n.º 3
0
    def __init__(self, logLevel=logging.INFO):

        ## initialize logging as well
        FORMAT = '%(asctime)-15s %(message)s'
        logging.basicConfig(format=FORMAT)
        # logging.basicConfig()
        self.logger = logging.getLogger('gtm_audit')
        self.logger.setLevel(logLevel)
        ## completed log initialization

        self.session = requests.Session()
        self.debug = False
        self.verbose = False
        self.section_name = "papi"

        # If all parameters are set already, use them.  Otherwise
        # use the config
        self.config = EdgeGridConfig({}, self.section_name)

        if hasattr(self.config, "debug") and self.config.debug:
            self.debug = True

        if hasattr(self.config, "verbose") and self.config.verbose:
            self.verbose = True

        # Set the config options
        self.session.auth = EdgeGridAuth(
            client_token=self.config.client_token,
            client_secret=self.config.client_secret,
            access_token=self.config.access_token)

        if hasattr(self.config, 'headers'):
            self.session.headers.update(self.config.headers)

        self.baseurl = '%s://%s/' % ('https', self.config.host)
        self.httpCaller = EdgeGridHttpCaller(self.session, self.debug,
                                             self.verbose, self.baseurl)
Exemplo n.º 4
0
#config = EdgeGridConfig({"verbose":False},section_name)
#baseurl = '%s://%s/' % ('https', config.host)
baseurl = 'https://%s' % edgerc.get(section_name, 'host')

s = requests.Session()
t = requests.Session()
#s.auth = EdgeGridAuth(
#            client_token=config.client_token,
#            client_secret=config.client_secret,
#            access_token=config.access_token
#)

s.auth = EdgeGridAuth.from_edgerc(edgerc, section_name)

httpCaller = EdgeGridHttpCaller(s, debug, verbose, baseurl)

result = httpCaller.getResult(
    urljoin(baseurl, '/diagnostic-tools/v2/ghost-locations/available'))

location_list = []
for item in result['locations']:
    location_list.append(item['id'])

print location_list

print "[*] There are %s places that we could resolve from" % (
    len(location_list))

location = random.choice(location_list)
 def __init__(self, config):
     self.http_caller = EdgeGridHttpCaller(config, False, False)