Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ out/

### VS Code ###
.vscode/
.env
17 changes: 17 additions & 0 deletions src/main/java/chess/utils/DatabaseUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package chess.utils;

import io.github.cdimascio.dotenv.Dotenv;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 라이브러리를 선택한 이유가 있나요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DB 비밀번호 같은 민감한 정보를 Dotenv로 관리하는 것이 좋다고 알고 있었기에 선택했습니다.

해당 경우에 다른 선택지가 있는지는 자세히 알아보지는 않았습니다

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DatabaseUtil {
private static final Dotenv dotenv = Dotenv.load();
private static final String URL = dotenv.get("DB_URL");
private static final String USER = dotenv.get("DB_USER");
private static final String PASSWORD = dotenv.get("DB_PASSWORD");
Comment on lines +10 to +12
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

라이브러리 사용 이유와는 별개로 DB 정보를 숨긴 것은 너무 좋네요 👍👍


질문

  1. dotenv.get 은 해당 키값이 없을 경우 null 이 저장되나요?

  2. 만약 dotenv 라이브러리가 지원이 멈춰서, 혹은 취약점이 발견되어서 다른 라이브러리로 변경된다면 이 코드는 변경에 대응하기 쉬운 코드일까요?

  3. 협업하는 사람들에게 dotenv 파일은 어떻게 전달해줄 수 있나요?


public static Connection getConnection() throws SQLException {
return DriverManager.getConnection(URL, USER, PASSWORD);
}
}