Skip to content

Commit

Permalink
Check .gitignore for .env entry
Browse files Browse the repository at this point in the history
If a connection string is saved to the .env file, we make a quick check to see if this file has been excluded in version control. (Otherwise you might inadvertently commit a connection string to version control.)
  • Loading branch information
joyfullservice committed Aug 1, 2023
1 parent cda5b18 commit 0adbe4b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Version Control.accda.src/forms/frmVCSDatabase.bas
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,7 @@ Private Function SaveConnection() As Boolean

' Connection string
If chkSaveDotEnv Then
CheckGitignoreDotEnv
' Save connection string to .env file
SaveConnectionStringToFile
' Remove connect parameter from dictionary
Expand Down Expand Up @@ -1104,3 +1105,36 @@ Private Sub cmdTest_Click()
End If

End Sub


'---------------------------------------------------------------------------------------
' Procedure : CheckGitignoreDotEnv
' Author : Adam Waller
' Date : 7/31/2023
' Purpose : If the project appears to be a .git repository, check to see if .env
' : appears in the .gitignore file.
' : (This is not a comprehensive test, but just an extra aid for most common
' : scenarios to help users avoid inadvertently comitting a .env file to
' : their version control system.)
'---------------------------------------------------------------------------------------
'
Private Sub CheckGitignoreDotEnv()

Dim strPath As String
Dim strContent As String

' Guess at the standard location for a .gitignore file
strPath = Options.GetExportFolder & "..\.gitignore"
If FSO.FileExists(strPath) Then
strContent = ReadFile(strPath)
If Len(strContent) Then
If InStr(1, strContent, ".env", vbTextCompare) = 0 Then
MsgBox2 "Potentially Sensitive File", _
"Please note: .env files should not be committed to version control.", _
"To avoid exposing credentials to your repository, please exclude .env files in .gitignore", _
vbExclamation
End If
End If
End If

End Sub

0 comments on commit 0adbe4b

Please sign in to comment.