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
22 from osdf.config.base import osdf_config
25 class DESException(Exception):
29 def extract_data(service_id, request_data):
30 """Extracts data from the data lake via DES.
32 param: service_id: kpi data identifier
33 param: request_data: data to send
34 param: osdf_config: osdf config to retrieve api info
37 config = osdf_config.deployment
38 user, password = config['desUsername'], config['desPassword']
39 auth = HTTPBasicAuth(user, password)
40 headers = config["desHeaders"]
41 req_url = config["desUrl"] + config["desApiPath"] + service_id
44 response = requests.post(req_url, data=request_data, headers=headers, auth=auth, verify=False)
45 except requests.RequestException as e:
46 raise DESException("Request exception was encountered {}".format(e))
48 if response.status_code == 200:
49 return response.json().get("result")
51 raise DESException("Response code other than 200. Response code: {}".format(response.status_code))