def load_config(self, config_file, default_log_level, logObserverFactory): """ Load the configuration for this provisioner and initialize it. """ log = Logger(observer=logObserverFactory("ERROR")) try: # Load config. scp = load_config(config_file, defaults=self.get_config_defaults()) section = "PROVISIONER" config = section2dict(scp, section) self.config = config # Start logger. log_level = config.get('log_level', default_log_level) log = Logger(observer=logObserverFactory(log_level)) self.log = log log.info("Initializing provisioner.", event_type='init_provisioner') provider_config = section2dict(scp, "SLACK") # Load configuration. try: self.endpoint_s = config.get("endpoint", None) self.load_provider_config(provider_config) except KeyError as ex: raise OptionMissingError( "A require option was missing: '{0}:{1}'.".format( section, ex.args[0])) # Create the web client. self.make_web_client() # Initialize the provider. self.init_provider() except Exception as ex: d = self.reactor.callLater(0, self.reactor.stop) log.failure("Provisioner failed to initialize: {0}".format(ex)) raise return defer.succeed(None)
def get_config_opt(config, section, opt): """ Return the config option from the mapping `config` or raise `OptionMissingError`. """ try: return config[opt] except KeyError as ex: raise OptionMissingError( "A require option was missing: '{0}:{1}'.".format( section, ex.args[0]))
def load_config(self, config_file, default_log_level, logObserverFactory): """ Load the configuration for this provisioner and initialize it. """ log = Logger(observer=logObserverFactory("ERROR")) try: # Load config. scp = load_config(config_file, defaults=self.get_config_defaults()) section = "PROVISIONER" config = section2dict(scp, section) self.config = config # Start logger. log_level = config.get('log_level', default_log_level) log = Logger(observer=logObserverFactory(log_level)) self.log = log log.info("Initializing Orgsync RESTful API provisioner.", event_type='init_provisioner') # Load API configuration info-- endpoint info, URL, API key. try: self.diagnostic_mode = bool( config.get("diagnostic_mode", False)) self.endpoint_s = config.get("endpoint", None) self.url_prefix = config["url_prefix"] self.api_key = config["api_key"] self.max_per_day = config.get("max_per_day", 20) self.account_query = jinja2.Template(config['account_query']) self.account_update = jinja2.Template(config['account_update']) self.account_delete = jinja2.Template(config['account_delete']) self.account_add = jinja2.Template(config['account_add']) account_template_path = config['account_template'] attrib_map_path = config["attribute_map"] except KeyError as ex: raise OptionMissingError( "A require option was missing: '{0}:{1}'.".format( section, ex.args[0])) # Start the daiy countdown timer. self.daily_reset = LoopingCall(self.reset_daily_countdown) d = self.daily_reset.start(60 * 60 * 24, now=True) # Create the web client. self.make_web_client() # Create the attribute map. self.make_attribute_map(attrib_map_path) # Create the account template. self.make_account_template(account_template_path) except Exception as ex: d = self.reactor.callLater(0, self.reactor.stop) log.failure("Provisioner failed to initialize: {0}".format(ex)) raise return defer.succeed(None)
def load_config(self, config_file, default_log_level, logObserverFactory): """ Load the configuration for this provisioner and initialize it. """ log = Logger(observer=logObserverFactory("ERROR")) try: # Load config. scp = load_config(config_file, defaults=self.get_config_defaults()) section = "PROVISIONER" config = section2dict(scp, section) self.config = config # Start logger. log_level = config.get('log_level', default_log_level) log = Logger(observer=logObserverFactory(log_level)) self.log = log log.info("Initializing provisioner.", event_type='init_provisioner') # Load configuration info-- endpoint info, credentials, base DN, etc. try: self.provision_group = config["provision_group"].lower() self.endpoint_s = config["endpoint"] self.use_starttls = bool(config.get("use_starttls", True)) self.starttls_hostname = config.get("starttls_hostname", "localhost") starttls_trust_anchor = config.get('starttls_trust_anchor', None) self.bind_dn = config["bind_dn"] self.bind_passwd = config["bind_passwd"] self.base_dn = config["base_dn"] self.search_filter = config.get('filter', None) self.account_template_path = config["account_template"] self.page_size = int(config.get('page_size', 100)) except KeyError as ex: raise OptionMissingError( "A required option was missing: '{}:{}'.".format( section, ex.args[0])) self.parse_account_template_() self.load_starttls_trust_anchor(starttls_trust_anchor) except Exception as ex: d = self.reactor.callLater(0, self.reactor.stop) log.failure("Provisioner failed to initialize: {}".format(ex)) raise return defer.succeed(None)
def load_config(self, config_file, default_log_level, logObserverFactory): """ Load the configuration for this provisioner and initialize it. """ log = Logger(observer=logObserverFactory("ERROR")) try: # Load config. scp = load_config(config_file, defaults=self.get_config_defaults()) section = "PROVISIONER" config = section2dict(scp, section) self.config = config # Start logger. log_level = config.get('log_level', default_log_level) log = Logger(observer=logObserverFactory(log_level)) self.log = log log.info("Initializing provisioner.", event_type='init_provisioner') # Load API configuration info-- endpoint info, URL, API key. try: self.diagnostic_mode = bool( int(config.get("diagnostic_mode", 0))) self.unmanaged_logins = set( login.lower() for login in config.get("unmanaged_logins", "").split()) self.provision_group = config.get("provision_group", None) if self.provision_group is not None: self.provision_group = self.provision_group.lower() workroom_map_path = config.get("workroom_map", None) self.endpoint_s = config.get("endpoint", None) self.url_prefix = config["url_prefix"] self.api_key = config["api_key"] self.cache_size = int(config["cache_size"]) self.authenticate = config['authenticate'] self.accounts_query = config['accounts_query'] self.max_page = int(config.get('max_page', 100)) self.local_computed_match_template = jinja2.Template( config['local_computed_match_template']) if self.provision_group: self.account_update = jinja2.Template( config['account_update']) self.account_delete = jinja2.Template( config['account_delete']) self.account_add = config['account_add'] account_template_path = config['account_template'] attrib_map_path = config["attribute_map"] if workroom_map_path: self.workrooms_query = config['workrooms_query'] self.workroom_members = jinja2.Template( config['workroom_members']) self.workroom_subject = jinja2.Template( config['workroom_subject']) self.workroom_cache_size = int( config.get("workroom_cache_size", 100)) self.workroom_retry_delay = int( config.get("workroom_retry_delay", 20)) except KeyError as ex: raise OptionMissingError( "A require option was missing: '{0}:{1}'.".format( section, ex.args[0])) if self.provision_group is None and workroom_map_path is None: raise OptionMissingError( "Must provide at least one of `provision_group` (account " "provisioning) or `workroom_map` (workroom mapping).") # Create the web client. self.make_default_web_client() self.__workroom_cache = None if self.provision_group: # Create the attribute map. self.make_attribute_map(attrib_map_path) # Create the account template. self.make_account_template(account_template_path) if workroom_map_path: # Create the workroom cache. self.__workroom_cache = pylru.lrucache( self.workroom_cache_size) # Create the workroom map. self.make_workroom_map(workroom_map_path) # Create account cache. self.__account_cache = pylru.lrucache(self.cache_size) # Initialize access token. self.__auth_token = None log.info("Diagnostic mode: {diagnostic}", diagnostic=self.diagnostic_mode) except Exception as ex: d = self.reactor.callLater(0, self.reactor.stop) log.failure("Provisioner failed to initialize: {0}".format(ex)) raise return defer.succeed(None)
def load_config(self, config_file, default_log_level, logObserverFactory): """ Load the configuration for this provisioner and initialize it. """ log = Logger(observer=logObserverFactory("ERROR")) try: # Load config. scp = load_config(config_file, defaults=self.get_config_defaults()) section = "PROVISIONER" config = section2dict(scp, section) self.config = config # Start logger. log_level = config.get('log_level', default_log_level) log = Logger(observer=logObserverFactory(log_level)) self.log = log log.info("Initializing provisioner.", event_type='init_provisioner') # Load API configuration info-- endpoint info, URL, API key. try: self.unmanaged_logins = set( login.lower() for login in config.get("unmanaged_logins", "").split()) log.debug("unmanaged_logins: {unmanaged_logins}", unmanaged_logins=list(self.unmanaged_logins)) self.provision_group = config.get("provision_group", None) if self.provision_group is not None: self.provision_group = self.provision_group.lower() target_group_map_path = config.get("target_group_map", None) self.endpoint_s = config.get("endpoint", None) self.url_prefix = config["url_prefix"] self.client_secret = config["client_secret"] self.account_cache_size = int(config["account_cache_size"]) if target_group_map_path: self.target_group_cache_size = int( config.get("target_group_cache_size", 100)) self.target_group_retry_delay = int( config.get("target_group_retry_delay", 20)) self.account_sync_rate_limit_ms = int( config.get("account_sync_rate_limit_ms", 0)) self.member_sync_rate_limit_ms = int( config.get("member_sync_rate_limit_ms", 0)) self.provision_strategy = config.get("provision_strategy", "query-first").lower() self.group_sync_strategy = config.get( "group_sync_strategy", "add-members-first").lower() if not self.group_sync_strategy in ('query-first', 'add-members-first'): raise Exception("Unknown group_sync_strategy: {}".format( self.group_sync_strategy)) self.account_cache_validity_period = int( config.get("account_cache_validity_period", 0)) except KeyError as ex: raise OptionMissingError( "A require option was missing: '{0}:{1}'.".format( section, ex.args[0])) if self.provision_group is None and target_group_map_path is None: raise OptionMissingError( "Must provide at least one of `provision_group` (account " "provisioning) or `target_group_map` (target_group mapping)." ) if not self.provision_strategy in ('query-first', 'create-first'): raise Exception( "`provision_strategy` must be one of: query-first, create-first" ) # Create the web client. self.make_default_web_client() self.__target_group_cache = None if target_group_map_path: # Create the target_group cache. self.__target_group_cache = pylru.lrucache( self.target_group_cache_size) # Create the target_group map. self.make_target_group_map(target_group_map_path) # Create account cache. self.__account_cache = pylru.lrucache(self.account_cache_size) # Initialize access token. self.auth_token = None except Exception as ex: d = self.reactor.callLater(0, self.reactor.stop) log.failure("Provisioner failed to initialize: {0}".format(ex)) raise self.parse_config(scp) return defer.succeed(None)
def load_config(self, config_file, default_log_level, logObserverFactory): """ Load the configuration for this provisioner and initialize it. """ log = Logger(observer=logObserverFactory("ERROR")) try: # Load config. scp = load_config(config_file, defaults=self.get_config_defaults()) section = "PROVISIONER" config = section2dict(scp, section) self.config = config # Start logger. log_level = config.get('log_level', default_log_level) log = Logger(observer=logObserverFactory(log_level)) self.log = log log.info("Initializing SSH provisioner.", event_type='init_provisioner') # Initialize template environment. self.template_env = jinja2.Environment(trim_blocks=True, lstrip_blocks=True) self.template_env.filters['shellquote'] = filter_shellquote self.template_env.filters['newline'] = filter_newline # Load SSH configuration info. try: self.provision_cmd = self.template_env.from_string( config["provision_cmd"].strip()) self.deprovision_cmd = self.template_env.from_string( config["deprovision_cmd"].strip()) template_str = config.get("sync_cmd", None) if template_str is not None: log.debug("Sync command template: {template}", template=template_str) self.sync_cmd = self.template_env.from_string( template_str.strip()) self.provision_cmd_type = self.parse_command_type( config.get("provision_cmd_type", "simple")) self.deprovision_cmd_type = self.parse_command_type( config.get("deprovision_cmd_type", "simple")) self.sync_cmd_type = self.parse_command_type( config.get("sync_cmd_type", "simple")) if self.provision_cmd_type == self.CMD_TYPE_INPUT: self.provision_input = self.template_env.from_string( config["provision_input"].strip()) if self.deprovision_cmd_type == self.CMD_TYPE_INPUT: self.deprovision_input = self.template_env.from_string( config["deprovision_input"].strip()) if self.sync_cmd_type == self.CMD_TYPE_INPUT: template_str = config.get("sync_input", None) log.debug("Sync input template: {template}", template=template_str) self.sync_input = self.template_env.from_string( template_str.strip()) result = config.get("provision_ok_result", None) if result is not None: self.provision_ok_result = int(result.strip()) result = config.get("deprovision_ok_result", None) if result is not None: self.deprovision_ok_result = int(result.strip()) result = config.get("sync_ok_result", None) if result is not None: self.sync_ok_result = int(result.strip()) self.cmd_timeout = int(config['cmd_timeout']) self.host = config["host"] self.port = int(config["port"]) self.ssh_user = config["user"] self.known_hosts = os.path.expanduser(config["known_hosts"]) if "keys" in config: self.keys = config["keys"].split(",") except KeyError as ex: raise OptionMissingError( "A require option was missing: '{0}:{1}'.".format( section, ex.args[0])) self.load_groupmap(config.get("group_map", None)) except Exception as ex: d = self.reactor.callLater(0, self.reactor.stop) log.failure("Provisioner failed to initialize: {0}".format(ex)) raise return defer.succeed(None)