# Path: cloudify/constants.py
# BROKER_PORT_SSL = 5671
# 
# BROKER_PORT_NO_SSL = 5672


import json
import os
import ssl
from cloudify.constants import BROKER_PORT_SSL, BROKER_PORT_NO_SSL
#    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    * See the License for the specific language governing permissions and
#    * limitations under the License.

# AMQP broker configuration for agents and manager
# Primarily used by celery, so provided with variables it understands
from __future__ import absolute_import



workdir_path = os.getenv('CELERY_WORK_DIR')
if workdir_path is None:
    # We are not in an appropriately configured celery environment
    config = {}
else:
    conf_file_path = os.path.join(workdir_path, 'broker_config.json')
    if os.path.isfile(conf_file_path):
        with open(conf_file_path) as conf_handle:
            conf_file = conf_handle.read()
            config = json.loads(conf_file)
    else:
        config = {}

# Provided as variables for retrieval by amqp_client and logger as required
broker_cert_path = config.get('broker_cert_path', '')
broker_username = config.get('broker_username', 'guest')
broker_password = config.get('broker_password', 'guest')
broker_hostname = config.get('broker_hostname', 'localhost')
broker_vhost = config.get('broker_vhost', '/')
broker_ssl_enabled = config.get('broker_ssl_enabled', False)

# Path: cloudify/constants.py
# BROKER_PORT_SSL = 5671
# 
# BROKER_PORT_NO_SSL = 5672


# Path: cloudify/broker_config.py
import json
import os
import ssl
from cloudify.constants import BROKER_PORT_SSL, BROKER_PORT_NO_SSL

#    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    * See the License for the specific language governing permissions and
#    * limitations under the License.

# AMQP broker configuration for agents and manager
# Primarily used by celery, so provided with variables it understands
from __future__ import absolute_import



workdir_path = os.getenv('CELERY_WORK_DIR')
if workdir_path is None:
    # We are not in an appropriately configured celery environment
    config = {}
else:
    conf_file_path = os.path.join(workdir_path, 'broker_config.json')
    if os.path.isfile(conf_file_path):
        with open(conf_file_path) as conf_handle:
            conf_file = conf_handle.read()
            config = json.loads(conf_file)
    else:
        config = {}

# Provided as variables for retrieval by amqp_client and logger as required
broker_cert_path = config.get('broker_cert_path', '')
broker_username = config.get('broker_username', 'guest')
broker_password = config.get('broker_password', 'guest')
broker_hostname = config.get('broker_hostname', 'localhost')
broker_vhost = config.get('broker_vhost', '/')
broker_ssl_enabled = config.get('broker_ssl_enabled', False)

broker_port = BROKER_PORT_SSL if broker_ssl_enabled else BROKER_PORT_NO_SSL