mirror of
https://github.com/gmemstr/sliproad.git
synced 2024-09-19 16:11:11 +01:00
c559f28ebb
Implemented a rudementary authentication method using Keycloak as the IdP - still very barebones, but login does function. Next steps will include a Docker Compose file (most likely) for managing this integration. The application will work fine without setting up the integration however, and will just throw a warning message. Setup should be relatively self explanatory, but some documentation is TBD, along with some automation when spinning up for the first time. Still not super happy with the implementation.
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gmemstr/nas/authentication"
|
|
"github.com/gmemstr/nas/files"
|
|
"github.com/gmemstr/nas/router"
|
|
"github.com/go-yaml/yaml"
|
|
"io/ioutil"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
// Main function that defines routes
|
|
func main() {
|
|
// Initialize file providers.
|
|
file, err := ioutil.ReadFile("providers.yml")
|
|
if err != nil {
|
|
fmt.Println("Unable to read providers.yml file, does it exist?")
|
|
}
|
|
err = yaml.Unmarshal(file, &files.ProviderConfig)
|
|
if err != nil {
|
|
fmt.Println("Unable to parse providers.yml file, is it correct?")
|
|
}
|
|
files.SetupProviders()
|
|
|
|
// Initialize auth if set up.
|
|
authConfig, err := ioutil.ReadFile("auth.yml")
|
|
if err != nil {
|
|
fmt.Println("!! No Keycloack configuration found !!\n!! Requests will be unauthenticated !!")
|
|
router.AuthEnabled = false
|
|
} else {
|
|
err = yaml.Unmarshal(authConfig, &authentication.AuthConfig)
|
|
if err != nil {
|
|
fmt.Println("Unable to parse auth.yml file, is it correct?")
|
|
router.AuthEnabled = false
|
|
}
|
|
fmt.Println("Keycloak configured")
|
|
}
|
|
|
|
r := router.Init()
|
|
fmt.Println("Your NAS instance is live on port :3000")
|
|
log.Fatal(http.ListenAndServe(":3000", r))
|
|
}
|