Remove ca-cert from docker image
[optf/osdf.git] / osdf / adapters / dcae / des.py
1 # -------------------------------------------------------------------------
2 #   Copyright (C) 2020 Wipro Limited.
3 #
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
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15 #
16 # -------------------------------------------------------------------------
17 #
18
19 import requests
20 from requests.exceptions import HTTPError
21
22 from osdf.config.base import osdf_config
23 from osdf.utils.interfaces import RestClient
24
25
26 class DESException(Exception):
27     pass
28
29
30 def extract_data(service_id, request_data):
31     """Extracts data from the data lake via DES.
32
33     param: service_id: kpi data identifier
34     param: request_data: data to send
35     param: osdf_config: osdf config to retrieve api info
36     """
37
38     config = osdf_config.deployment
39     user, password = config['desUsername'], config['desPassword']
40     headers = config["desHeaders"]
41     req_url = config["desUrl"] + config["desApiPath"] + service_id
42     rc = RestClient(userid=user, passwd=password, url=req_url, headers=headers, method="POST")
43
44     try:
45         response_json = rc.request(data=request_data)
46         return response_json.get("result")
47     except requests.RequestException as e:
48         raise DESException("Request exception was encountered {}".format(e))
49     except HTTPError as ex:
50         raise DESException("Response code other than 200. Response code: {}".format(ex.response.status_code))