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 logger = logging.getLogger(__name__)
26 def __init__(self, base_url):
27 self.base_url = base_url
29 def create_apikey(self, email, description):
31 headers = {'content-type': 'application/json;charset=UTF-8'}
34 'description': description
36 data = json.JSONEncoder().encode(data)
37 url = self.base_url + "/apiKeys/create"
38 ret = requests.post(url=url, data=data, headers=headers)
39 logger.info('create apiKey, response status_code: %s, body: %s', ret.status_code, ret.json())
40 if ret.status_code != 200:
41 raise DmaapClientException(ret.json())
44 'apiKey': ret.get('key', ''),
45 'apiSecret': ret.get('secret', '')
48 except Exception as e:
49 raise DmaapClientException('create apikey from dmaap failed: ' + e.message)
51 def get_apikey(self, apikey):
53 url = self.base_url + "/apiKeys/%s" % apikey
54 ret = requests.get(url)
55 logger.info('get apiKey, response status_code: %s, body: %s', ret.status_code, ret.json())
56 if ret.status_code != 200:
57 raise DmaapClientException(ret.json())
60 except Exception as e:
61 raise DmaapClientException('get apikey from dmaap failed: ' + e.message)
63 def delete_apikey(self):
66 def update_apikey(self, apikey, email, description):