def parse_config(config: dict): """Check that the configuration includes the required keys and parse the values expressed as durations.""" if "period" not in config: raise ConfigError( "'period' is required when using email account validity") if "renew_at" not in config: raise ConfigError( "'renew_at' is required when using email account validity") config["period"] = Config.parse_duration(config.get("period") or 0) config["renew_at"] = Config.parse_duration(config.get("renew_at") or 0) return config
def __init__(self, config: dict, api: ModuleApi): self._api = api self._store = EmailAccountValidityStore(config, api) EmailAccountValidityBase.__init__(self, config, self._api, self._store) DirectServeHtmlResource.__init__(self) if "period" in config: self._period = Config.parse_duration(config["period"]) else: raise ConfigError( "'period' is required when using account validity") ( self._account_renewed_template, self._account_previously_renewed_template, self._invalid_token_template, ) = api.read_templates([ "account_renewed.html", "account_previously_renewed.html", "invalid_token.html", ])
def main() -> None: parser = argparse.ArgumentParser() parser.add_argument( "-c", "--config-path", action="append", metavar="CONFIG_FILE", help="The config files for Synapse.", required=True, ) parser.add_argument( "-s", "--since", metavar="duration", help= "Specify how far back to review user registrations for, defaults to 7d (i.e. 7 days).", default="7d", ) parser.add_argument( "-e", "--exclude-emails", action="store_true", help="Exclude users that have validated email addresses.", ) parser.add_argument( "-u", "--only-users", action="store_true", help="Only print user IDs that match.", ) parser.add_argument( "-a", "--exclude-app-service", help="Exclude appservice users.", action="store_true", ) config = ReviewConfig() config_args = parser.parse_args(sys.argv[1:]) config_files = find_config_files(search_paths=config_args.config_path) config_dict = read_config_files(config_files) config.parse_config_dict(config_dict, "", "") since_ms = time.time() * 1000 - Config.parse_duration(config_args.since) exclude_users_with_email = config_args.exclude_emails exclude_users_with_appservice = config_args.exclude_app_service include_context = not config_args.only_users for database_config in config.database.databases: if "main" in database_config.databases: break engine = create_engine(database_config.config) with make_conn(database_config, engine, "review_recent_signups") as db_conn: # This generates a type of Cursor, not LoggingTransaction. user_infos = get_recent_users( db_conn.cursor(), since_ms, exclude_users_with_appservice) # type: ignore[arg-type] for user_info in user_infos: if exclude_users_with_email and user_info.emails: continue if include_context: print_public_rooms = "" if user_info.public_rooms: print_public_rooms = "(" + ", ".join( user_info.public_rooms[:3]) if len(user_info.public_rooms) > 3: print_public_rooms += ", ..." print_public_rooms += ")" print("# Created:", datetime.fromtimestamp(user_info.creation_ts)) print("# Email:", ", ".join(user_info.emails) or "None") print("# IPs:", ", ".join(user_info.ips)) print( "# Number joined public rooms:", len(user_info.public_rooms), print_public_rooms, ) print("# Number joined private rooms:", len(user_info.private_rooms)) print("#") print(user_info.user_id) if include_context: print()
def parse_config(config: dict) -> dict: config["period"] = Config.parse_duration(config.get("period") or 0) return config