Skip to content

Commit

Permalink
Update fix_container_permissions.py (#2)
Browse files Browse the repository at this point in the history
* Update fix_container_permissions.py

* Update setup.cfg

* Update fix_container_permissions.py

* Apply suggestions from code review

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update fix_container_permissions.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update fix_container_permissions.py

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
RhinosF1 and coderabbitai[bot] authored May 18, 2024
1 parent e6f95d3 commit 75a9878
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
28 changes: 17 additions & 11 deletions miraheze/swift/fix_container_permissions.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import os
import re
import subprocess
import sys
import argparse

if len(sys.argv) != 2:
print("Please use in form of 'python fix_containers.py foowiki'")
sys.exit(1)

wiki = sys.argv[1]
def fix_container_perms(wiki: str) -> None:
out = subprocess.run(['sudo', '-u', 'www-data', 'php', '/srv/mediawiki/1.41/maintenance/run.php', '/srv/mediawiki/1.41/extensions/CreateWiki/maintenance/setContainersAccess.php', '--wiki', wiki], capture_output=True, text=True)
matches = re.findall(r"Making sure 'mwstore:\/\/miraheze-swift\/([^']+)' [^\n]+\.failed\.", out.stdout)
for match in matches:
subprocess.run(['swift', 'post', '--read-acl', 'mw:media', '--write-acl', 'mw:media', f'miraheze-{wiki}-{match}'], check=True)

out = subprocess.run(['sudo', '-u', 'www-data', 'php', '/srv/mediawiki/1.41/maintenance/run.php', '/srv/mediawiki/1.41/extensions/CreateWiki/maintenance/setContainersAccess.php', '--wiki', wiki], capture_output=True, text=True)
subprocess.run(['sudo', '-u', 'www-data', 'php', '/srv/mediawiki/1.41/maintenance/run.php', '/srv/mediawiki/1.41/extensions/CreateWiki/maintenance/setContainersAccess.php', '--wiki', wiki])

matches = re.findall(r"Making sure 'mwstore:\/\/miraheze-swift\/([^']+)' [^\n]+\.failed\.", out.stdout)
for match in matches:
os.system(f"swift post --read-acl 'mw:media' --write-acl 'mw:media' miraheze-{wiki}-{match}")

os.system(f'sudo -u www-data php /srv/mediawiki/1.41/maintenance/run.php /srv/mediawiki/1.41/extensions/CreateWiki/maintenance/setContainersAccess.php --wiki {wiki}')
def main() -> None:
parser = argparse.ArgumentParser(description='Fix container permissions for a specified wiki')
parser.add_argument('--wiki', required=True, help='wiki database name')

args = parser.parse_args()
fix_container_perms(args.wiki)


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ python_requires = >=3.11
console_scripts =
partial-reset-wiki = miraheze.salt.mwcli.partial_reset_wiki:main
rename-wiki = miraheze.salt.mwcli.rename_wiki:main
fix-container-perms = miraheze.swift.fix_container_permissions:main

0 comments on commit 75a9878

Please sign in to comment.