"""Verify the DuneChat artifact and prepare the Arrakis public relay.""" import hashlib import re DISCORD_CONFIGS = { 'arrakis': 'ea5460f59766315e47e343e0a6d88deb71232df065f7bde0074ab742c8f65b4d', 'caladan': 'b5e49f560c8ff43d0d49002dc6844e30c81449bd220c51e151b9f47215e71c14', 'giedi_prime': 'd1bc9a45a59813f3c2b8e1478e854ea193a272c69bc78b84ac542b178fd575f1', 'kaitain': '4f962d0225a934906a96b095933816505801e702dab8633456d6e9daa8aa131f', 'sigma_draconis_iv': '5ce962eae27af1af1bcf6527bb840a80bc44b921745416e318b8ce002ddca597', 'lobby': 'b95c7ed186c048ee4ca88d3c7eaa6962eb6228525b1ecb09f11727e41df21924', } DISCORD_JAR = 'ef2fa1f2eb146c7c77412b7190a7dd33f1fc91282683fe45407739554c8aefef' def enable_modern_discord(config): setting = re.compile(r'(?m)^(UseModernPaperChatEvent:[ \t]*)false([ \t]*(?:#[^\r\n]*)?)(\r?\n)') matches = list(setting.finditer(config)) if len(matches) != 1 or len(re.findall(r'(?m)^UseModernPaperChatEvent\s*:', config)) != 1: raise ValueError('Expected exactly one disabled modern Discord chat setting') if re.search(r'(?m)^RespectChatPlugins\s*:', config): raise ValueError('Discord cancellation policy differs from the reviewed config') return setting.sub(r'\g<1>true\g<2>\g<3>RespectChatPlugins: true\g<3>', config) def verify_artifact(artifact, source): expected = { 'DuneChat.jar', 'SOURCE_COMMIT', 'plugin_dunechat.py', 'install-plugin-fleet.py', 'write-plugin-manifest.py', 'plugin_menu_pack.py', 'plugin_backend_abi.py', 'plugin_fleet_rollback.py', 'plugin_pack_properties.py', 'plugin_pillager_abi.py', } lines = (artifact / 'SHA256SUMS').read_text().splitlines() sums = dict(line.split(' ', 1)[::-1] for line in lines) if len(lines) != len(sums) or sums.keys() != expected or any( hashlib.sha256((artifact / name).read_bytes()).hexdigest() != sha for name, sha in sums.items() ): raise ValueError('Unexpected DuneChat archive manifest') if (artifact / 'SOURCE_COMMIT').read_text().strip() != source: raise ValueError('DuneChat archive source differs from the selected commit')