1 # Copyright (c) 2019, CMCC Technologies. Co., Ltd.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
20 from catalog.pub.Dmaap_lib.pub.exceptions import DmaapClientException
22 requests.packages.urllib3.disable_warnings()
23 logger = logging.getLogger(__name__)
27 def __init__(self, base_url):
28 self.base_url = base_url
30 def create_apikey(self, email, description):
32 headers = {'content-type': 'application/json;charset=UTF-8'}
35 'description': description
37 data = json.JSONEncoder().encode(data)
38 url = self.base_url + "/apiKeys/create"
39 ret = requests.post(url=url, data=data, headers=headers, verify=False)
40 logger.info('create apiKey, response status_code: %s, body: %s', ret.status_code, ret.json())
41 if ret.status_code != 200:
42 raise DmaapClientException(ret.json())
45 'apiKey': ret.get('key', ''),
46 'apiSecret': ret.get('secret', '')
49 except Exception as e:
50 raise DmaapClientException('create apikey from dmaap failed: ' + e.message)
52 def get_apikey(self, apikey):
54 url = self.base_url + "/apiKeys/%s" % apikey
55 ret = requests.get(url)
56 logger.info('get apiKey, response status_code: %s, body: %s', ret.status_code, ret.json())
57 if ret.status_code != 200:
58 raise DmaapClientException(ret.json())
61 except Exception as e:
62 raise DmaapClientException('get apikey from dmaap failed: ' + e.message)
64 def delete_apikey(self):
67 def update_apikey(self, apikey, email, description):