def __init__(self, **kafka_config): """Constructor which parses the kafka config.""" super(KafkaConfig, self).__init__(**kafka_config) self.hostname = self._parse_string('hostname') self.port = self._parse_positive_int('port') self.topic = self._parse_string('topic') # protocol and checks, plain and ssl only self.security_protocol = self._parse_string('security_protocol').upper() if self.security_protocol not in ['SSL', 'PLAINTEXT']: msg = 'Invalid security protocol specified, use one on [PLAIN, SSL] only' _logger.error(msg) raise ConfigParseException(msg) # if security protocol is set to SSL then verify the required options if self.security_protocol == 'SSL': self.client_certificate = self._parse_file_path('client_certificate', ext='.pem') self.client_key = self._parse_file_path('client_key', ext='.pem') self.caroot_certificate = self._parse_file_path('caroot_certificate', ext='.pem') self.skip_tls_verifications = self._parse_bool('skip_tls_verifications') if self.skip_tls_verifications is True: _logger.warning('TLS verifications should only be turned off in DEV Env, ' 'not recommended for production environment') # if security protocol is set to PLAIN show warning else: _logger.warning('Security protocol in broker config is set to PLAIN, which is not recommended ' 'in production environment')
def __init__(self, **operator_config): """Constructor which parses the operator config.""" super(OperatorConfig, self).__init__(**operator_config) self.id = self._parse_string('id', max_len=16) if self.id != self.id.lower(): _logger.warning('operator_id: {0} has been changed to ' 'lower case: {1}'.format(self.id, self.id.lower())) self.id = self.id.lower() # Check that operator_ids contains only letters, underscores and digits(0-9) bad_symbol_error_message = 'Operator_id {0} must contain only letters, underscores or digits(0-9)!' parse_alphanum(self.id, bad_symbol_error_message) self.name = self._parse_string('name') if self.id == self.COUNTRY_OPERATOR_NAME: msg = "Invalid use of reserved operator name \'__all__\' in config!" _logger.error(msg) raise ConfigParseException(msg) # Make sure mcc_mnc key is there and is a list if 'mcc_mnc_pairs' not in operator_config or type( operator_config['mcc_mnc_pairs']) is not list: msg = 'Missing (or non-list) {0} in config for operator ID {1}!'.format( 'mcc_mnc_pairs', self.id) _logger.error(msg) raise ConfigParseException(msg) # Validate each MCC/MNC pair for mcc_mnc in self.raw_config['mcc_mnc_pairs']: for key in ['mcc', 'mnc']: try: int(mcc_mnc[key]) except (ValueError, KeyError): msg = 'Non-existent or non integer {0} in config for operator ID {1}!'.format( key, self.id) _logger.error(msg) raise ConfigParseException(msg) # Make sure we stringify mcc and mnc values in case they were interpreted as ints by YAML parser self.mcc_mnc_pairs = \ [{'mcc': str(x['mcc']), 'mnc': str(x['mnc'])} for x in self.raw_config['mcc_mnc_pairs']] if self.mcc_mnc_pairs is None or len(self.mcc_mnc_pairs) <= 0: msg = 'At least one valid MCC-MNC pair must be provided for operator ID {0}.'.format( self.id) _logger.error(msg) raise ConfigParseException(msg)
def __init__(self, **operator_config): """Constructor which parses the operator config.""" super(BrokerOperatorConfig, self).__init__(**operator_config) self.id = self._parse_string('id', max_len=16) if self.id != self.id.lower(): _logger.warning('operator_id: {0} has been changed to ' 'lower case: {1}'.format(self.id, self.id.lower())) self.id = self.id.lower() # Check that operator_ids contains only letters, underscores and digits(0-9) bad_symbol_error_message = 'Operator_id {0} must contain only letters, underscores or digits(0-9)!' parse_alphanum(self.id, bad_symbol_error_message) self.name = self._parse_string('name') if self.id == self.COUNTRY_OPERATOR_NAME: msg = "Invalid use of reserved operator name \'__all__\' in config!" _logger.error(msg) raise ConfigParseException(msg) self.topic = self._parse_string('topic')