-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper function for compiling TLS arguments (#1610)
Summary: Pull Request resolved: #1610 All PCF2 stage services will need to put together TLS arguments. We define a simple helper function that can be reused by all stage services input - if the TLS feature is enabled output - the argument dict Reviewed By: danbunnell Differential Revision: D39636352 fbshipit-source-id: 8f601a67e47259ee6d7fecf58e3050151490b298
- Loading branch information
1 parent
a4ba8dc
commit af31a6d
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env fbpython | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
# pyre-strict | ||
|
||
from typing import Any, Dict | ||
|
||
from fbpcs.private_computation.service.constants import ( | ||
CA_CERT_PATH, | ||
PRIVATE_KEY_PATH, | ||
SERVER_CERT_PATH, | ||
) | ||
|
||
|
||
def get_tls_arguments(has_tls_feature: bool) -> Dict[str, Any]: | ||
return { | ||
"use_tls": has_tls_feature, | ||
"ca_cert_path": CA_CERT_PATH if has_tls_feature else "", | ||
"server_cert_path": SERVER_CERT_PATH if has_tls_feature else "", | ||
"private_key_path": PRIVATE_KEY_PATH if has_tls_feature else "", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
fbpcs/private_computation/test/service/test_argument_helpers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env fbpython | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
from unittest import TestCase | ||
|
||
from fbpcs.private_computation.service.argument_helper import get_tls_arguments | ||
from fbpcs.private_computation.service.constants import ( | ||
CA_CERT_PATH, | ||
PRIVATE_KEY_PATH, | ||
SERVER_CERT_PATH, | ||
) | ||
|
||
|
||
class TestArgumentHelpers(TestCase): | ||
def test_get_tls_arguments_no_feature(self): | ||
tls_arguments = get_tls_arguments(False) | ||
|
||
self.assertFalse(tls_arguments["use_tls"]) | ||
self.assertEqual(tls_arguments["ca_cert_path"], "") | ||
self.assertEqual(tls_arguments["server_cert_path"], "") | ||
self.assertEqual(tls_arguments["private_key_path"], "") | ||
|
||
def test_get_tls_arguments_with_feature(self): | ||
tls_arguments = get_tls_arguments(True) | ||
|
||
self.assertTrue(tls_arguments["use_tls"]) | ||
self.assertEqual(tls_arguments["ca_cert_path"], CA_CERT_PATH) | ||
self.assertEqual(tls_arguments["server_cert_path"], SERVER_CERT_PATH) | ||
self.assertEqual(tls_arguments["private_key_path"], PRIVATE_KEY_PATH) |