Improve code documentation

This commit is contained in:
TwinProduction
2020-10-23 15:58:59 -04:00
parent c09cd9df7e
commit 1bde98868e
5 changed files with 24 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import (
"strings"
)
// Handler takes care of security for a given handler with the given security configuratioon
func Handler(handler http.HandlerFunc, security *Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
usernameEntered, passwordEntered, ok := r.BasicAuth()

View File

@ -1,18 +1,25 @@
package security
// Config is the security configuration for Gatus
type Config struct {
Basic *BasicConfig `yaml:"basic"`
}
// IsValid returns whether the security configuration is valid or not
func (c *Config) IsValid() bool {
return c.Basic != nil && c.Basic.IsValid()
}
// BasicConfig is the configuration for Basic authentication
type BasicConfig struct {
Username string `yaml:"username"`
// Username is the name which will need to be used for a successful authentication
Username string `yaml:"username"`
// PasswordSha512Hash is the SHA512 hash of the password which will need to be used for a successful authentication
PasswordSha512Hash string `yaml:"password-sha512"`
}
// IsValid returns whether the basic security configuration is valid or not
func (c *BasicConfig) IsValid() bool {
return len(c.Username) > 0 && len(c.PasswordSha512Hash) == 128
}

View File

@ -5,6 +5,7 @@ import (
"fmt"
)
// Sha512 hashes a provided string using SHA512 and returns the resulting hash as a string
func Sha512(s string) string {
hash := sha512.New()
hash.Write([]byte(s))