1 # -------------------------------------------------------------------------
2 # Copyright (C) 2020 Wipro Limited.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # -------------------------------------------------------------------------
20 from requests.auth import HTTPBasicAuth
21 from requests import RequestException
24 class AAIException(Exception):
28 def get_aai_data(request_json, osdf_config):
30 """Get the response from AAI
32 :param request_json: requestjson
33 :param osdf_config: configuration specific to OSDF app
34 :return:response body from AAI
37 "X-TransactionId": "9999",
39 "Accept": "application/json",
40 "Content-Type": "application/json",
42 nxi_id = request_json["NxIId"]
43 config = osdf_config.deployment
44 aai_url = config["aaiUrl"]
45 aai_req_url = aai_url + config["aaiServiceInstanceUrl"] + nxi_id + "?depth=2"
48 response = requests.get(aai_req_url, headers=aai_headers, auth=HTTPBasicAuth("AAI", "AAI"), verify=False)
49 except RequestException as e:
50 raise AAIException("Request exception was encountered {}".format(e))
52 if response.status_code == 200:
53 return response.json()
55 raise AAIException("Error response recieved from AAI for the request {}".format(aai_req_url))