Skip to content

Commit

Permalink
Fix TokenStore and SecureStorage on boot
Browse files Browse the repository at this point in the history
  • Loading branch information
greeeen-dev committed Feb 6, 2025
1 parent 8dc2ff1 commit 5d8ce95
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions cogs/sysmgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,11 @@ def __init__(self, bot):
try:
extras = {}

if extension in sysext.get('uses_tokenstore', []):
if extension in extinfo.get('uses_tokenstore', []):
# noinspection PyUnresolvedReferences
extras.update({'tokenstore': secrets_issuer.get_secret(plugin[:-5])})
self.logger.debug(f'Issued TokenStore to {extension}')
if extension in sysext.get('uses_storage', []):
if extension in extinfo.get('uses_storage', []):
# noinspection PyUnresolvedReferences
extras.update({'storage': secrets_issuer.get_storage(plugin[:-5])})
self.logger.debug(f'Issued SecureStorage to {extension}')
Expand Down Expand Up @@ -992,6 +992,10 @@ def allow_storage(plugin, cog):

plugin_data = {}

if plugin_exists:
with open('plugins/' + cog + '.json') as file:
plugin_data = json.load(file)

if plugin_exists and cog_exists:
if self.bot.config['plugin_priority']:
toload.extend(plugin_data['modules'])
Expand All @@ -1001,6 +1005,11 @@ def allow_storage(plugin, cog):
if extension_clean.startswith('cogs.') or extension_clean.startswith('cogs/'):
extension_clean = ext[5:]

if not ext.startswith('cogs.'):
ext = 'cogs.' + ext
if ext.endswith('.py'):
ext = ext[:-3]

if extension_clean in plugin_data.get('uses_tokenstore', []):
allow_tokenstore(plugin_data['id'], ext)
if extension_clean in plugin_data.get('uses_storage', []):
Expand All @@ -1019,9 +1028,18 @@ def allow_storage(plugin, cog):
toload.extend([f'cogs.{module[:-3]}' for module in plugin_data['modules']])

for ext in plugin_data['modules']:
if ext in plugin_data.get('uses_tokenstore', []):
extension_clean = ext
if extension_clean.startswith('cogs.') or extension_clean.startswith('cogs/'):
extension_clean = ext[5:]

if not ext.startswith('cogs.'):
ext = 'cogs.' + ext
if ext.endswith('.py'):
ext = ext[:-3]

if extension_clean in plugin_data.get('uses_tokenstore', []):
allow_tokenstore(plugin_data['id'], ext)
if ext in plugin_data.get('uses_storage', []):
if extension_clean in plugin_data.get('uses_storage', []):
allow_storage(plugin_data['id'], ext)

if not action == CogAction.load:
Expand Down Expand Up @@ -1088,13 +1106,15 @@ def allow_storage(plugin, cog):
if toload_cog in requires_tokens[plugin]:
# noinspection PyUnresolvedReferences
extras.update({'tokenstore': secrets_issuer.get_secret(plugin)})
self.logger.debug(f'Issued TokenStore to {toload_cog}')
break

# Generate SecureStorageWrapper if needed
for plugin in requires_storage.keys():
if toload_cog in requires_storage[plugin]:
# noinspection PyUnresolvedReferences
extras.update({'storage': secrets_issuer.get_storage(plugin)})
self.logger.debug(f'Issued SecureStorage to {toload_cog}')
break

try:
Expand Down

0 comments on commit 5d8ce95

Please sign in to comment.