1 # ============LICENSE_START====================================================
3 # =============================================================================
4 # Copyright (c) 2017-2020 AT&T Intellectual Property. All rights reserved.
5 # Copyright (c) 2020 Pantheon.tech. All rights reserved.
6 # =============================================================================
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 # ============LICENSE_END======================================================
20 ## Get parameters for accessing the DMaaP controller
21 from consulif.consulif import ConsulHandle
22 from cloudify.exceptions import NonRecoverableError
25 os.environ["REQUESTS_CA_BUNDLE"]="/opt/onap/certs/cacert.pem" # This is to handle https request thru plugin
27 CONSUL_HOST = "consul" # Should always be a local consul agent on Cloudify Manager
28 DBCL_KEY_NAME = "dmaap-plugin" # Consul key containing DMaaP data bus credentials
29 # In the ONAP Kubernetes environment, bus controller address is always "dmaap-bc", on port 8080 (http) and 8443 (https)
30 ONAP_SERVICE_ADDRESS = "dmaap-bc"
35 _ch = ConsulHandle("http://{0}:8500".format(CONSUL_HOST), None, None, None)
36 except Exception as e:
37 raise NonRecoverableError("Error getting ConsulHandle when configuring dmaap plugin: {0}".format(e))
40 config = _ch.get_config(DBCL_KEY_NAME)
41 except Exception as e:
42 raise NonRecoverableError("Error getting config for '{0}' from ConsulHandle when configuring dmaap plugin: {1}".format(DBCL_KEY_NAME, e))
45 DMAAP_USER = config['dmaap']['username']
46 except Exception as e:
47 raise NonRecoverableError("Error setting DMAAP_USER while configuring dmaap plugin: {0}".format(e))
50 DMAAP_PASS = config['dmaap']['password']
51 except Exception as e:
52 raise NonRecoverableError("Error setting DMAAP_PASS while configuring dmaap plugin: {0}".format(e))
55 DMAAP_OWNER = config['dmaap']['owner']
56 except Exception as e:
57 raise NonRecoverableError("Error setting DMAAP_OWNER while configuring dmaap plugin: {0}".format(e))
60 if 'protocol' in config['dmaap']:
61 DMAAP_PROTOCOL = config['dmaap']['protocol']
62 service_port = HTTP_PORT
64 DMAAP_PROTOCOL = 'https' # Default to https (service discovery should give us this but doesn't
65 service_port = HTTPS_PORT
66 except Exception as e:
67 raise NonRecoverableError("Error setting DMAAP_PROTOCOL while configuring dmaap plugin: {0}".format(e))
70 if 'path' in config['dmaap']:
71 DMAAP_PATH = config['dmaap']['path']
73 DMAAP_PATH = 'webapi' # SHould come from service discovery but Consul doesn't support it
74 except Exception as e:
75 raise NonRecoverableError("Error setting DMAAP_PATH while configuring dmaap plugin: {0}".format(e))
78 service_address = ONAP_SERVICE_ADDRESS
79 DMAAP_API_URL = '{0}://{1}:{2}/{3}'.format(DMAAP_PROTOCOL, service_address, service_port, DMAAP_PATH)
80 except Exception as e:
81 raise NonRecoverableError("Error setting DMAAP_API_URL while configuring dmaap plugin: {0}".format(e))