Skip to content

Commit e968fe2

Browse files
committed
Add advisory_device_file_protection support to server_config API command on server
1 parent e573ffc commit e968fe2

4 files changed

Lines changed: 29 additions & 6 deletions

File tree

server/parsec/cli/run.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99

1010
import click
1111

12-
from parsec._parsec import ActiveUsersLimit, EmailAddress, ParsecAddr, SecretKey, TrustAnchor
12+
from parsec._parsec import (
13+
ActiveUsersLimit,
14+
AdvisoryDeviceFileProtection,
15+
EmailAddress,
16+
ParsecAddr,
17+
SecretKey,
18+
TrustAnchor,
19+
)
1320
from parsec._version import __version__ as server_version
1421
from parsec.asgi import app_factory, serve_parsec_asgi_app
1522
from parsec.backend import backend_factory
@@ -199,6 +206,7 @@ def handle_parse_result(
199206
envvar="PARSEC_ADVISORY_DEVICE_FILE_PROTECTION",
200207
show_envvar=True,
201208
multiple=True,
209+
type=AdvisoryDeviceFileProtection.from_str,
202210
metavar="STRATEGY",
203211
help="""Advisory device file protection to recommend to clients.
204212
@@ -571,7 +579,7 @@ async def run_cmd(
571579
blockstore: BaseBlockStoreConfig,
572580
administration_token: str,
573581
account_config: AccountConfig,
574-
advisory_device_file_protection: tuple[str, ...],
582+
advisory_device_file_protection: tuple[AdvisoryDeviceFileProtection, ...],
575583
cryptpad_server_url: str | None,
576584
openbao_server_url: str | None,
577585
openbao_secret_mount_path: str,

server/parsec/components/events.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,5 +547,7 @@ async def api_server_config(
547547
organization_bootstrap=organization_bootstrap,
548548
cryptpad=cryptpad,
549549
openbao=openbao,
550-
advisory_device_file_protection=list(self._config.advisory_device_file_protection),
550+
advisory_device_file_protection=[
551+
p.str for p in self._config.advisory_device_file_protection
552+
],
551553
)

server/parsec/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from parsec._parsec import (
1313
ActiveUsersLimit,
14+
AdvisoryDeviceFileProtection,
1415
DateTime,
1516
EmailAddress,
1617
OpenBaoAuthType,
@@ -306,7 +307,7 @@ class BackendConfig:
306307

307308
openbao_config: OpenBaoConfig | None = None
308309

309-
advisory_device_file_protection: tuple[str, ...] = ()
310+
advisory_device_file_protection: tuple[AdvisoryDeviceFileProtection, ...] = ()
310311

311312
organization_bootstrap_webhook_url: str | None = None
312313
organization_spontaneous_bootstrap: bool = False

server/tests/api_v5/anonymous_server/test_server_config.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
import pytest
44

5-
from parsec._parsec import OpenBaoAuthType, anonymous_server_cmds
5+
from parsec._parsec import (
6+
AdvisoryDeviceFilePrimaryProtection,
7+
AdvisoryDeviceFileProtection,
8+
OpenBaoAuthType,
9+
anonymous_server_cmds,
10+
)
611
from parsec.config import AccountConfig, CryptPadConfig, OpenBaoAuthConfig, OpenBaoConfig
712
from tests.common import AnonymousServerRpcClient, Backend, HttpCommonErrorsTester
813

@@ -71,7 +76,14 @@ async def test_anonymous_server_server_config_ok(
7176
)
7277

7378
case "with_advisory_device_file_protection":
74-
backend.config.advisory_device_file_protection = ("PASSWORD+TOTP", "PKI")
79+
backend.config.advisory_device_file_protection = (
80+
AdvisoryDeviceFileProtection(
81+
primary=AdvisoryDeviceFilePrimaryProtection.PASSWORD, with_totp=True
82+
),
83+
AdvisoryDeviceFileProtection(
84+
primary=AdvisoryDeviceFilePrimaryProtection.PKI, with_totp=False
85+
),
86+
)
7587

7688
expected_rep = anonymous_server_cmds.latest.server_config.RepOk(
7789
account=anonymous_server_cmds.latest.server_config.AccountConfig.DISABLED,

0 commit comments

Comments
 (0)