summaryrefslogtreecommitdiff
path: root/internal/authentication/file_user_provider.go
diff options
context:
space:
mode:
authorAmir Zarrinkafsh <nightah@me.com>2021-02-22 10:07:06 +1100
committerGitHub <noreply@github.com>2021-02-22 10:07:06 +1100
commit74721a9f4126a9d4cddd082b7e50ad477c9d154b (patch)
tree218a910b69a6d3e007b3a24e18c8db3201ba6714 /internal/authentication/file_user_provider.go
parent8bc7ef5d8f4a12d07e9d3ce4b56ad9a41936cf9b (diff)
feat: go:embed static assets (#1733)
* feat: go:embed static assets Go 1.16 introduced the ability to embed files within a generated binary directly with the go tool chain. This simplifies our dependencies and the significantly improves the development workflow for future developers. Key points to note: Due to the inability to embed files that do not reside within the local package we need to duplicate our `config.template.yml` within `internal/configuration`. To avoid issues with the development workflow empty mock files have been included within `internal/server/public_html`. These are substituted with the respective generated files during the CI/CD and build workflows. * fix(suites): increase ldap suite test timeout * fix(server): fix swagger asset CSP
Diffstat (limited to 'internal/authentication/file_user_provider.go')
-rw-r--r--internal/authentication/file_user_provider.go16
1 files changed, 5 insertions, 11 deletions
diff --git a/internal/authentication/file_user_provider.go b/internal/authentication/file_user_provider.go
index 3a42290c0..7a11c2c42 100644
--- a/internal/authentication/file_user_provider.go
+++ b/internal/authentication/file_user_provider.go
@@ -1,6 +1,7 @@
package authentication
import (
+ _ "embed" // Embed users_database.template.yml.
"fmt"
"io/ioutil"
"os"
@@ -102,18 +103,11 @@ func checkDatabase(path string) []error {
return nil
}
-func generateDatabaseFromTemplate(path string) error {
- f, err := cfg.Open("users_database.template.yml")
- if err != nil {
- return fmt.Errorf("Unable to open users_database.template.yml: %v", err)
- }
+//go:embed users_database.template.yml
+var cfg []byte
- b, err := ioutil.ReadAll(f)
- if err != nil {
- return fmt.Errorf("Unable to read users_database.template.yml: %v", err)
- }
-
- err = ioutil.WriteFile(path, b, 0600)
+func generateDatabaseFromTemplate(path string) error {
+ err := ioutil.WriteFile(path, cfg, 0600)
if err != nil {
return fmt.Errorf("Unable to generate %v: %v", path, err)
}