Skip to content

Commit

Permalink
Default credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorespert committed Aug 16, 2024
1 parent 0a1757c commit 813dc62
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
14 changes: 4 additions & 10 deletions controller/daemon/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,15 @@ import (
"github.com/reef-pi/reef-pi/controller/utils"
)

var DefaultCredentials = utils.Credentials{
User: "reef-pi",
Password: "reef-pi",
}

func (r *ReefPi) API() error {
creds, err := r.a.GetCredentials()
_, err := r.a.GetCredentials()
if err != nil {
log.Println("ERROR: Failed to load credentials. Error", err)
if err := r.store.Update(Bucket, "credentials", DefaultCredentials); err != nil {
if err := r.a.DefaultCredentials(); err != nil {
return err
}
creds = DefaultCredentials
}
err, router := startAPIServer(r.settings.Address, creds, r.settings.HTTPS)
err, router := startAPIServer(r.settings.Address, r.settings.HTTPS)
if err != nil {
return err
}
Expand Down Expand Up @@ -226,7 +220,7 @@ func (r *ReefPi) AuthenticatedAPI(router *mux.Router) {
}
}

func startAPIServer(address string, creds utils.Credentials, https bool) (error, *mux.Router) {
func startAPIServer(address string, https bool) (error, *mux.Router) {
assets := http.FileServer(http.Dir("ui/assets"))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "ui/home.html")
Expand Down
8 changes: 8 additions & 0 deletions controller/utils/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type Auth interface {
UpdateCredentials(http.ResponseWriter, *http.Request)
Me(http.ResponseWriter, *http.Request)
Authenticate(http.HandlerFunc) http.HandlerFunc
DefaultCredentials() error
}

type auth struct {
Expand Down Expand Up @@ -155,3 +156,10 @@ func (a *auth) UpdateCredentials(w http.ResponseWriter, req *http.Request) {
}
JSONUpdateResponse(&credentials, fn, w, req)
}

func (a *auth) DefaultCredentials() error {
return a.credentialsManager.Update(Credentials{
User: "reef-pi",
Password: "reef-pi",
})
}

0 comments on commit 813dc62

Please sign in to comment.