1 # -------------------------------------------------------------------------
2 # Copyright (c) 2015-2017 AT&T Intellectual Property
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 # -------------------------------------------------------------------------
21 from osdf import auth_groups, userid_suffix, passwd_suffix
24 def dmaap_creds(dmaap_file="/etc/dcae/dmaap.conf"):
25 """Get DMaaP credentials from DCAE for publish and subscribe"""
27 dmaap_creds = _get_dmaap_creds(dmaap_file)
33 def _get_dmaap_creds(dmaap_file):
34 """Get DMaaP credentials from DCAE for publish and subscribe"""
35 streams = json.load(open(dmaap_file, 'r'))
36 pubs = [x for x in streams
37 if x['dmaapStreamId'] == 'requests' and x['dmaapAction'] == 'publish']
38 subs = [x for x in streams
39 if x['dmaapStreamId'] == 'responses' and x['dmaapAction'] == 'subscribe']
41 def get_dmaap_info(x):
42 """Get DMaaP credentials from dmaap_object 'x'"""
43 return dict(url=x.get('dmaapUrl'), userid=x.get('dmaapUserName'), passwd=x.get('dmaapPassword'))
45 return {'pub': get_dmaap_info(pubs[0]), 'sub': get_dmaap_info(subs[0])}
48 def load_credentials(osdf_config):
49 """Get credentials as dictionaries grouped by auth_group (e.g. creds["Placement"]["user1"] = "pass1")"""
50 creds = dict((x, dict()) for x in auth_groups) # each auth group has userid, passwd dict
51 suffix_start = len(userid_suffix)
53 config = osdf_config.deployment
55 for element, username in config.items():
57 if element.startswith("osdf" + x) and element.endswith(userid_suffix):
58 passwd = config[element[:-suffix_start] + passwd_suffix]
59 creds[x][username] = passwd