def newrelic_get_integration()

in functions/source/cfct_register/cfct_register.py [0:0]


def newrelic_get_integration(access_key, newrelic_account_id):
    nerdGraphEndPoint = os.environ['nerdGraphEndPoint']
    service_query = '''
    {{
      actor 
      {{
        account(id: {0}) 
        {{
          cloud 
          {{
            provider(slug: "aws") 
            {{
              services 
              {{
                slug
              }}
            }}
          }}
        }}
      }}
    }}
    '''.format(newrelic_account_id)
    
    try:
        response = requests.post(nerdGraphEndPoint, headers={'API-Key': access_key}, verify=True, data=service_query)
        temp_list = json.loads(response.text)['data']['actor']['account']['cloud']['provider']['services']
        newrelic_integration_list = []
        for slug in temp_list:
            newrelic_integration_list.append(slug['slug'])
        logger.info('NerdGraph AWS available integrations : {}'.format(newrelic_integration_list))
        return newrelic_integration_list
    except Exception as e:
        logger.error(e)