Skip to content

Commit 0f5ec1c

Browse files
Merge pull request privacera#253 from SiddheshwarKamble/securechat_update_apikey_name
Update apikey name from PAIG_API_KEY to PAIG_APP_API_KEY
2 parents d5ef3bd + 7a4acc9 commit 0f5ec1c

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

paig-securechat/web-server/src/paig_securechat/app/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from fastapi.responses import HTMLResponse
2121
import os
2222
from core import constants
23-
from core.utils import set_paig_api_key
23+
from core.utils import set_paig_app_api_key
2424
import webbrowser
2525
import logging
2626
from fastapi.exceptions import RequestValidationError
@@ -136,7 +136,7 @@ def make_middleware() -> List[Middleware]:
136136

137137
def create_app() -> FastAPI:
138138
init_settings()
139-
set_paig_api_key()
139+
set_paig_app_api_key()
140140
init_paig_shield()
141141
init_vector_db()
142142
app_ = FastAPI(

paig-securechat/web-server/src/paig_securechat/core/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ def set_up_standalone_mode(
8282
constants.SINGLE_USER_MODE = single_user_mode
8383

8484

85-
def set_paig_api_key():
85+
def set_paig_app_api_key():
8686
from core import config
8787
conf = config.Config
88-
if 'PAIG_API_KEY' not in os.environ:
88+
if 'PAIG_APP_API_KEY' not in os.environ:
8989
if 'paig' in conf and 'key_file' in conf['paig']:
9090
key_file_path = conf['paig']['key_file']
9191
if os.path.exists(key_file_path):
9292
with open(key_file_path, 'r') as file:
93-
paig_api_key = file.read().strip()
94-
os.environ["PAIG_API_KEY"] = paig_api_key
93+
paig_app_api_key = file.read().strip()
94+
os.environ["PAIG_APP_API_KEY"] = paig_app_api_key

paig-securechat/web-server/src/paig_securechat/services/paig_shield.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def setup_shield_client(self):
2424
paig_shield_client.setup(frameworks=self.ai_application_conf["shield_frameworks"])
2525
except paig_client.exception.AccessControlException as err:
2626
logger.error(f"PAIG Shield plugin setup failed with error {err}")
27-
if 'PAIG_API_KEY' in os.environ:
28-
logger.error(f"Invalid PAIG_API_KEY key.")
29-
sys.exit('PAIG Shield plugin setup failed. Please provide valid PAIG_API_KEY key.')
27+
if 'PAIG_APP_API_KEY' in os.environ:
28+
logger.error(f"Invalid PAIG_APP_API_KEY key.")
29+
sys.exit('PAIG Shield plugin setup failed. Please provide valid PAIG_APP_API_KEY key.')
3030
elif 'PRIVACERA_SHIELD_CONF_FILE' in os.environ:
3131
logger.error(f"PAIG Shield configuration file used is {os.environ['PRIVACERA_SHIELD_CONF_FILE']}")
3232
sys.exit(f"PAIG Shield plugin setup failed. Please confirm if the configuration file {os.environ['PRIVACERA_SHIELD_CONF_FILE']} is correct and exists")
@@ -37,8 +37,8 @@ def paig_shield_setup_app_with_file(self, ai_application_name, paig_shield_confi
3737
"""Handles PAIG Shield setup using a configuration file."""
3838
if not paig_shield_config_file:
3939
if app_count > 1:
40-
logger.error(f"AI Application {ai_application_name} missing required 'paig_api_key' or 'paig_shield_config_file' in configuration file")
41-
sys.exit(f"AI Application {ai_application_name} missing required 'paig_api_key' or 'paig_shield_config_file' configuration file")
40+
logger.error(f"AI Application {ai_application_name} missing required 'paig_app_api_key' or 'paig_shield_config_file' in configuration file")
41+
sys.exit(f"AI Application {ai_application_name} missing required 'paig_app_api_key' or 'paig_shield_config_file' configuration file")
4242
if 'PRIVACERA_SHIELD_CONF_FILE' in os.environ:
4343
logger.info(f"AI Application {ai_application_name} setup using 'PRIVACERA_SHIELD_CONF_FILE' environment variable")
4444
return
@@ -60,20 +60,20 @@ def paig_shield_setup_app_with_file(self, ai_application_name, paig_shield_confi
6060

6161
def set_paig_config_map(self, ai_application_name, ai_application_config, app_count):
6262
"""Sets up PAIG Shield configuration using either API key or config file."""
63-
paig_api_key = ai_application_config.get('paig_api_key')
63+
paig_app_api_key = ai_application_config.get('paig_app_api_key')
6464

65-
if paig_api_key:
65+
if paig_app_api_key:
6666
try:
67-
ai_app = paig_shield_client.setup_app(application_config_api_key=paig_api_key)
67+
ai_app = paig_shield_client.setup_app(application_config_api_key=paig_app_api_key)
6868
self.paig_config_map[ai_application_name] = ai_app
6969
except paig_client.exception.AccessControlException as err:
7070
logger.error(f"PAIG Shield plugin setup failed for {ai_application_name} with error {err}")
7171
sys.exit(f"PAIG Shield plugin setup failed for {ai_application_name} with error {err}")
7272
return
7373

74-
if app_count == 1 and 'PAIG_API_KEY' in os.environ:
75-
logger.info(f"AI Application {ai_application_name} setup using 'PAIG_API_KEY' environment variable")
74+
if app_count == 1 and 'PAIG_APP_API_KEY' in os.environ:
75+
logger.info(f"AI Application {ai_application_name} setup using 'PAIG_APP_API_KEY' environment variable")
7676
return
7777

78-
logger.info("'paig_api_key' is not provided in config. Trying to setup PAIG Shield using configuration file.")
78+
logger.info("'paig_app_api_key' is not provided in config. Trying to setup PAIG Shield using configuration file.")
7979
self.paig_shield_setup_app_with_file(ai_application_name, ai_application_config.get('paig_shield_config_file'), app_count)

paig-securechat/web-server/src/paig_securechat/tests/test_utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from core.utils import (
88
get_uuid, generate_title, extract_keywords, summarize_conversation,
9-
construct_title, recursive_merge_dicts, set_paig_api_key
9+
construct_title, recursive_merge_dicts, set_paig_app_api_key
1010
)
1111

1212

@@ -54,11 +54,11 @@ def test_recursive_merge_dicts():
5454

5555

5656

57-
def test_set_paig_api_key():
57+
def test_set_paig_app_api_key():
5858
with patch("os.environ", {}), patch("os.path.exists", return_value=True), \
5959
patch("builtins.open", mock_open(read_data="test-paig-api-key")), \
6060
patch("core.config.Config", {"paig": {"key_file": "test_paig.key"}}):
61-
set_paig_api_key()
62-
assert os.environ["PAIG_API_KEY"] == "test-paig-api-key"
61+
set_paig_app_api_key()
62+
assert os.environ["PAIG_APP_API_KEY"] == "test-paig-api-key"
6363
# unset the environment variable
64-
del os.environ["PAIG_API_KEY"]
64+
del os.environ["PAIG_APP_API_KEY"]

0 commit comments

Comments
 (0)