1 # Copyright (c) 2019, CMCC Technologies Co., Ltd.
2 # Licensed under the Apache License, Version 2.0 (the "License")
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at
5 # http://www.apache.org/licenses/LICENSE-2.0
6 # Unless required by applicable law or agreed to in writing, software
7 # distributed under the License is distributed on an "AS IS" BASIS,
8 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9 # See the License for the specific language governing permissions and
10 # limitations under the License.
17 from ..pub.exceptions import DmaapClientException
19 logger = logging.getLogger(__name__)
23 def __init__(self, host):
26 def create_apikey(self, email, description):
28 headers = {'content-type': 'application/json;charset=UTF-8'}
31 'description': description
33 data = json.JSONEncoder().encode(data)
34 url = "http://%s/apiKeys/create" % (self.host)
35 ret = requests.post(url=url, data=data, headers=headers)
36 logger.info('create apiKey, response status_code: %s, body: %s', ret.status_code, ret.json())
37 if ret.status_code != 200:
38 raise DmaapClientException(ret.json())
41 'apiKey': ret.get('key', ''),
42 'apiSecret': ret.get('secret', '')
45 except Exception as e:
46 raise DmaapClientException('create apikey from dmaap failed: ' + e.message)