Skip to content

Commit 9a0a29a

Browse files
committed
fix: update tails server upload methods to return public file URIs
We ran into an issue where we had a different tails_server_base_url from the tails_server_upload_url. This makes sense where you want to have a separate base URL for accessing the public files, and a private URL that is used for pushing the changes (where access controls dictate who can upload files, and they are restricted on the public URL). The `upload_tails_file` methods were returning the private URLs and the calling code was expecting public URLs. The solution was to update the methods to return the public URLs instead, while still uploading to the private URLs. Signed-off-by: Colton Wolkins (Laptop) <colton@indicio.tech>
1 parent f3a28de commit 9a0a29a

5 files changed

Lines changed: 35 additions & 7 deletions

File tree

acapy_agent/config/argparse.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,8 @@ def get_settings(self, args: Namespace) -> dict:
776776
settings["tails_server_upload_url"] = args.tails_server_base_url
777777
if args.tails_server_upload_url:
778778
settings["tails_server_upload_url"] = args.tails_server_upload_url
779+
if args.tails_server_upload_url and not args.tails_server_base_url:
780+
settings["args.tails_server_base_url"] = args.tails_server_upload_url
779781
if args.notify_revocation:
780782
settings["revocation.notify"] = args.notify_revocation
781783
if args.monitor_revocation_notification:

acapy_agent/tails/anoncreds_tails_server.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,24 @@ async def upload_tails_file(
3535
3636
Returns:
3737
Tuple[bool, str]: tuple with success status and url of uploaded
38-
file or error message if failed
38+
public file uri or error message if failed
3939
4040
"""
4141
tails_server_upload_url = context.settings.get("tails_server_upload_url")
42+
tails_server_base_url = context.settings.get("tails_server_base_url")
4243

4344
if not tails_server_upload_url:
4445
raise TailsServerNotConfiguredError(
4546
"tails_server_upload_url setting is not set"
4647
)
4748

49+
if not tails_server_base_url:
50+
raise TailsServerNotConfiguredError(
51+
"tails_server_base_url setting is not set"
52+
)
53+
4854
upload_url = tails_server_upload_url.rstrip("/") + f"/hash/{filename}"
55+
public_url = tails_server_base_url.rstrip("/") + f"/hash/{filename}"
4956

5057
try:
5158
await put_file(
@@ -59,4 +66,4 @@ async def upload_tails_file(
5966
except PutError as x_put:
6067
return (False, x_put.message)
6168

62-
return True, upload_url
69+
return True, public_url

acapy_agent/tails/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ async def upload_tails_file(
3131
3232
Returns:
3333
Tuple[bool, str]: tuple with success status and url of uploaded
34-
file or error message if failed
34+
public file uri or error message if failed
3535
3636
"""

acapy_agent/tails/indy_tails_server.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ async def upload_tails_file(
3737
3838
Returns:
3939
Tuple[bool, str]: tuple with success status and url of uploaded
40-
file or error message if failed
40+
public file uri or error message if failed
4141
4242
"""
4343
tails_server_upload_url = context.settings.get("tails_server_upload_url")
44+
tails_server_base_url = context.settings.get("tails_server_base_url")
4445
genesis_transactions = context.settings.get("ledger.genesis_transactions")
4546

4647
if not genesis_transactions:
@@ -64,7 +65,13 @@ async def upload_tails_file(
6465
"tails_server_upload_url setting is not set"
6566
)
6667

68+
if not tails_server_base_url:
69+
raise TailsServerNotConfiguredError(
70+
"tails_server_base_url setting is not set"
71+
)
72+
6773
upload_url = tails_server_upload_url.rstrip("/") + f"/{filename}"
74+
public_url = tails_server_base_url.rstrip("/") + f"/{filename}"
6875

6976
try:
7077
await put_file(
@@ -78,4 +85,4 @@ async def upload_tails_file(
7885
except PutError as x_put:
7986
return (False, x_put.message)
8087

81-
return True, upload_url
88+
return True, public_url

acapy_agent/tails/tests/test_indy.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ async def test_upload(self):
2424
context = InjectionContext(
2525
settings={
2626
"ledger.genesis_transactions": "dummy",
27+
"tails_server_base_url": "http://1.2.3.4:8088/tails/",
2728
"tails_server_upload_url": "http://1.2.3.4:8088",
2829
}
2930
)
@@ -37,10 +38,17 @@ async def test_upload(self):
3738
"/tmp/dummy/path",
3839
)
3940
assert ok
40-
assert text == context.settings["tails_server_upload_url"] + "/" + REV_REG_ID
41+
42+
# already contains / from config, no need to add it
43+
assert text == context.settings["tails_server_base_url"] + REV_REG_ID
44+
assert (
45+
mock_put.call_args.args[0]
46+
== context.settings["tails_server_upload_url"] + "/" + REV_REG_ID
47+
)
4148

4249
async def test_upload_indy_vdr(self):
4350
self.profile = await create_test_profile()
51+
self.profile.settings["tails_server_base_url"] = "http://1.2.3.4:8088/tails/"
4452
self.profile.settings["tails_server_upload_url"] = "http://1.2.3.4:8088"
4553
mock_multi_ledger_manager = mock.MagicMock(
4654
BaseMultipleLedgerManager, autospec=True
@@ -69,15 +77,19 @@ async def test_upload_indy_vdr(self):
6977
"/tmp/dummy/path",
7078
)
7179
assert ok
80+
81+
# already contains / from config, no need to add it
82+
assert text == self.profile.settings["tails_server_base_url"] + REV_REG_ID
7283
assert (
73-
text
84+
mock_put.call_args.args[0]
7485
== self.profile.settings["tails_server_upload_url"] + "/" + REV_REG_ID
7586
)
7687

7788
async def test_upload_x(self):
7889
context = InjectionContext(
7990
settings={
8091
"ledger.genesis_transactions": "dummy",
92+
"tails_server_base_url": "http://1.2.3.4:8088/tails/",
8193
"tails_server_upload_url": "http://1.2.3.4:8088",
8294
}
8395
)

0 commit comments

Comments
 (0)