# 요청에서 코드 파일 경로 추출
code_path = request.code_path
# 코드 파일 읽기 시도
try:
with open(code_path, "r", encoding="utf-8") as f:
code = f.read()
except Exception as e:
# 파일 읽기 실패 시 오류 메시지 반환
return agents_pb2.CodeResponse(summary=f"[Secrets] 파일 읽기 오류: {e}")
# 정규표현식 패턴으로 코드에서 시크릿 패턴 검색
matches = SECRET_PATTERN.findall(code)
if not matches:
# 매칭된 패턴이 없는 경우
summary = "[Secrets] 하드코딩된 비밀번호/키 패턴 없음."
else:
# 중복 제거 후 정렬하여 고유한 패턴만 추출
unique = sorted(set(matches))
# 발견된 시크릿 패턴을 쉼표로 구분하여 요약 생성
summary = "[Secrets] 잠재적 시크릿 발견: " + ", ".join(unique)
# CodeResponse 객체를 생성하여 반환
return agents_pb2.CodeResponse(summary=summary)