Skip to content

Commit

Permalink
feat: follow best practices with regards to naming .env files
Browse files Browse the repository at this point in the history
Signed-off-by: Drake Evans <[email protected]>
  • Loading branch information
DrakeEvans committed May 24, 2024
1 parent 91b23ea commit 382f421
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmd/sops/formats/formats.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package formats

import "strings"
import (
"path/filepath"
"strings"
)

// Format is an enum type
type Format int
Expand Down Expand Up @@ -43,7 +46,7 @@ func IsJSONFile(path string) bool {

// IsEnvFile returns true if a given file path corresponds to a .env file
func IsEnvFile(path string) bool {
return strings.HasSuffix(path, ".env")
return strings.HasSuffix(path, ".env") || strings.HasPrefix(filepath.Base(path), ".env")
}

// IsIniFile returns true if a given file path corresponds to a INI file
Expand Down
2 changes: 2 additions & 0 deletions cmd/sops/formats/formats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func TestFormatFromString(t *testing.T) {
func TestFormatForPath(t *testing.T) {
assert.Equal(t, Binary, FormatForPath("/path/to/foobar"))
assert.Equal(t, Dotenv, FormatForPath("/path/to/foobar.env"))
assert.Equal(t, Dotenv, FormatForPath("/path/to/.env.foobar"))
assert.Equal(t, Ini, FormatForPath("/path/to/foobar.ini"))
assert.Equal(t, Json, FormatForPath("/path/to/foobar.json"))
assert.Equal(t, Yaml, FormatForPath("/path/to/foobar.yml"))
Expand All @@ -27,6 +28,7 @@ func TestFormatForPathOrString(t *testing.T) {
assert.Equal(t, Binary, FormatForPathOrString("/path/to/foobar", ""))
assert.Equal(t, Dotenv, FormatForPathOrString("/path/to/foobar", "dotenv"))
assert.Equal(t, Dotenv, FormatForPathOrString("/path/to/foobar.env", ""))
assert.Equal(t, Dotenv, FormatForPathOrString("/path/to/.env.foobar", ""))
assert.Equal(t, Ini, FormatForPathOrString("/path/to/foobar", "ini"))
assert.Equal(t, Ini, FormatForPathOrString("/path/to/foobar.ini", ""))
assert.Equal(t, Json, FormatForPathOrString("/path/to/foobar", "json"))
Expand Down

0 comments on commit 382f421

Please sign in to comment.