Skip to content

Commit

Permalink
tests: move setup_acls to Python
Browse files Browse the repository at this point in the history
Reviewed By: quark-zju

Differential Revision: D64315956

fbshipit-source-id: a4ef223f01566cbee3917daccb0ceba79e5d8b44
  • Loading branch information
sggutier authored and facebook-github-bot committed Oct 16, 2024
1 parent 2bf1c46 commit 8c8f4c6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
15 changes: 1 addition & 14 deletions eden/mononoke/tests/integration/library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -726,20 +726,7 @@ CONFIG
}

function setup_acls() {
if [[ ! -f "$ACL_FILE" ]]; then
cat > "$ACL_FILE" <<ACLS
{
"repos": {
"default": {
"actions": {
"read": ["$CLIENT0_ID_TYPE:$CLIENT0_ID_DATA"],
"write": ["$CLIENT0_ID_TYPE:$CLIENT0_ID_DATA"]
}
}
}
}
ACLS
fi
python_fn setup_acls "$@"
}

function db_config() {
Expand Down
30 changes: 30 additions & 0 deletions eden/scm/sapling/testing/ext/mononoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2.

import json
import os
from typing import BinaryIO, List, Union
from urllib.parse import quote, unquote
Expand All @@ -19,6 +20,7 @@ def testsetup(t: TestTmp):


def setupfuncs(t: TestTmp):
t.command(setup_acls)
t.command(setup_mononoke_repo_config)
t.command(write_infinitepush_config)
t.command(urlencode)
Expand All @@ -29,6 +31,34 @@ def setupfuncs(t: TestTmp):
t.command(setup_environment_variables)


def setup_acls(stderr: BinaryIO, fs: ShellFS, env: Env) -> int:
acl_file = env.getenv("ACL_FILE")
if not acl_file:
stderr.write(b"Error: ACL_FILE environment variable is not set\n")
return 1

# Check if the ACL file already exists
if not fs.exists(acl_file):
client0_id_type = env.getenv("CLIENT0_ID_TYPE")
client0_id_data = env.getenv("CLIENT0_ID_DATA")

# Create the ACL file with the necessary permissions
acl_content = {
"repos": {
"default": {
"actions": {
"read": [f"{client0_id_type}:{client0_id_data}"],
"write": [f"{client0_id_type}:{client0_id_data}"],
}
}
}
}
with fs.open(acl_file, "w") as f:
f.write(json.dumps(acl_content).encode())

return 0


def setup_mononoke_repo_config(
args: List[str],
stderr: BinaryIO,
Expand Down

0 comments on commit 8c8f4c6

Please sign in to comment.