1919 SLACK_BOT_TOKEN ,
2020)
2121
22+
23+ def get_secret (secret_name ):
24+ aws_secret_id = os .environ .get ("RAY_ASSISTANT_AWS_SECRET_ID" )
25+ if aws_secret_id :
26+ import boto3
27+ client = boto3 .client (
28+ "secretsmanager" , region_name = os .environ ["RAY_ASSISTANT_AWS_REGION" ]
29+ )
30+ response = client .get_secret_value (SecretId = aws_secret_id )
31+ return json .loads (response ["SecretString" ])[secret_name ]
32+ else :
33+ raise NotImplemented (
34+ "Currently only AWS is supported "
35+ "and you need to set RAY_ASSISTANT_AWS_SECRET_ID" )
36+
37+
2238app = FastAPI ()
2339
2440
2541@ray .remote
2642class SlackApp :
2743 def __init__ (self ):
28- slack_app = App (token = os . environ [ "SLACK_BOT_TOKEN" ] )
44+ slack_app = App (token = get_secret ( "SLACK_BOT_TOKEN" ) )
2945
3046 @slack_app .event ("app_mention" )
3147 def event_mention (body , say ):
@@ -39,16 +55,14 @@ def event_mention(body, say):
3955 self .slack_app = slack_app
4056
4157 def run (self ):
42- SocketModeHandler (self .slack_app , SLACK_APP_TOKEN ).start ()
58+ SocketModeHandler (self .slack_app , get_secret ( " SLACK_APP_TOKEN" ) ).start ()
4359
4460
4561ray .init (
4662 runtime_env = {
4763 "env_vars" : {
48- "DB_CONNECTION_STRING" : DB_CONNECTION_STRING ,
64+ "DB_CONNECTION_STRING" : get_secret ( " DB_CONNECTION_STRING" ) ,
4965 "OPENAI_API_KEY" : OPENAI_API_KEY ,
50- "SLACK_APP_TOKEN" : SLACK_APP_TOKEN ,
51- "SLACK_BOT_TOKEN" : SLACK_BOT_TOKEN ,
5266 }
5367 },
5468 ignore_reinit_error = True ,
0 commit comments