def set_data_and_call_lambda(params): f = json.load(open(constant.S3_CONFIG, 'r')) j = read_json_from_s3(f["bucket"], f["config"]) data = { "slack_token": params["token"], "channel": params["channel"]["id"], "user_id": params["user"]["id"], "db_url": j.get("db_url"), "bot_token": j.get("bot_token"), "webhook_url": j.get("webhook_url"), "cloudwatch_account": j.get("cloudwatch_account"), #for internal use "aws_internal_account": os.environ["aws_account"], #for internal use "aws_internal_id": os.environ["aws_id"], #for internal use "callback_id": params["callback_id"], "response_url": params["response_url"], "response": params["actions"][0]["value"] if params["actions"][0].has_key("value") else params["actions"][0]["selected_options"][0]["value"] } # call_lambda("slack_session", data) call_lambda_async("slack_interactive", data) return format_response(200, None)
def delete_cred_db(db_url, user_id): event = { "db_url": db_url, "user_id": user_id, "db_command": "delete_cred_db" } call_lambda_async("slack_db", event)
def write_cred_db(db_url, user_id, data): event = { "db_url": db_url, "user_id": user_id, "db_command": "write_cred_db", "data": data } call_lambda_async("slack_db", event)
def delete_confirmation(event): response = event.get("response") if "yes" in response: message_handler(msg_const.START_DELETE, event) if check_sddc_user(event): event.update( { "status": "task_started", "lambda_name": "check_task" } ) try: task_id = call_lambda_async("delete_sddc", event) except Exception as e: event.update( { "message": "Sorry, failed to delete sddc. {}".format(str(e)), # "status": "task_failed" } ) message_handler(msg_const.SDDC_RESULT, event) delete_event_db(event.get("db_url"), event.get("user_id")) else: event.update( { "status": "task_started" } ) call_lambda_async("check_task", event) message_handler(msg_const.TASK_MSG, event) message_handler(msg_const.CRUD_SDDC, event) message_handler(msg_const.TASK_WH, event) else: message_handler(msg_const.CANT_DELETE, event) delete_event_db( event.get("db_url"), event.get("user_id") ) else: message_handler(msg_const.CANCEL_DELETE, event) delete_event_db( event.get("db_url"), event.get("user_id") )
def check_config(event): if "yes" in event.get("response"): message_handler(msg_const.CREATE, event) event.update({"vmc_command": "create_sddc"}) try: task_id = call_lambda_sync("slack_vmc", event) except Exception as e: event.update( { "message": "Sorry, failed to create sddc. {}".format(str(e)), # "text": str(e), # "status": "task_failed" } ) message_handler(msg_const.SDDC_RESULT, event) delete_event_db(event.get("db_url"), event.get("user_id")) else: event.update( { "task_id": task_id, "status": "task_started", "lambda_name": "check_task" } ) write_event_db( event.get("db_url"), event.get("user_id"), { "status": "creating", } ) call_lambda_async("check_task", event) message_handler(msg_const.TASK_MSG, event) message_handler(msg_const.CRUD_SDDC, event) message_handler(msg_const.TASK_WH, event) else: message_handler(msg_const.CANCEL_SDDC, event) delete_event_db(event.get("db_url"), event.get("user_id"))
def lambda_handler(event, context): # logging.info(event) headers = event.get("headers") if is_retry_request(headers): return format_response(200, None) params = json.loads(event.get("body")) if not is_token_valid(params): return format_response(200, "token is invalid") if "challenge" in params: return {"challenge": params.get("challenge")} if check_event(params): # logging.info(params) f = json.load(open(constant.S3_CONFIG, 'r')) j = read_json_from_s3(f["bucket"], f["config"]) data = { "slack_token": params["token"], "channel": params["event"]["channel"], "text": params["event"]["text"], "user_id": params["event"]["user"], "db_url": j.get("db_url"), "bot_token": j.get("bot_token"), "webhook_url": j.get("webhook_url"), "cloudwatch_account": j.get("cloudwatch_account"), #for internal use "aws_internal_account": os.environ["aws_account"], #for internal use "aws_internal_id": os.environ["aws_id"] #for internal use } # call_lambda_async("slack_session", data) call_lambda_async("slack_event", data) return format_response(200, None) return format_response(200, None)