From 1bde98868e6a2f9876aa60ae35f962ff2787a986 Mon Sep 17 00:00:00 2001 From: TwinProduction Date: Fri, 23 Oct 2020 15:58:59 -0400 Subject: [PATCH] Improve code documentation --- client/client.go | 2 ++ core/alert.go | 15 ++++++++++++--- security/handler.go | 1 + security/security.go | 9 ++++++++- security/sha512.go | 1 + 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/client/client.go b/client/client.go index 6179017a..c081dc4b 100644 --- a/client/client.go +++ b/client/client.go @@ -12,6 +12,7 @@ var ( insecureHttpClient *http.Client ) +// GetHttpClient returns the shared HTTP client func GetHttpClient(insecure bool) *http.Client { if insecure { if insecureHttpClient == nil { @@ -35,6 +36,7 @@ func GetHttpClient(insecure bool) *http.Client { } } +// CanCreateConnectionToTcpService checks whether a connection can be established with a TCP service func CanCreateConnectionToTcpService(address string) bool { conn, err := net.DialTimeout("tcp", address, 5*time.Second) if err != nil { diff --git a/core/alert.go b/core/alert.go index 705eb515..99b12583 100644 --- a/core/alert.go +++ b/core/alert.go @@ -29,11 +29,20 @@ type Alert struct { Triggered bool } +// AlertType is the type of the alert. +// The value will generally be the name of the alert provider type AlertType string const ( - SlackAlert AlertType = "slack" + // SlackAlert is the AlertType for the slack alerting provider + SlackAlert AlertType = "slack" + + // PagerDutyAlert is the AlertType for the pagerduty alerting provider PagerDutyAlert AlertType = "pagerduty" - TwilioAlert AlertType = "twilio" - CustomAlert AlertType = "custom" + + // TwilioAlert is the AlertType for the twilio alerting provider + TwilioAlert AlertType = "twilio" + + // CustomAlert is the AlertType for the custom alerting provider + CustomAlert AlertType = "custom" ) diff --git a/security/handler.go b/security/handler.go index c63f57a8..0821347e 100644 --- a/security/handler.go +++ b/security/handler.go @@ -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() diff --git a/security/security.go b/security/security.go index 29b5340c..a93b5cde 100644 --- a/security/security.go +++ b/security/security.go @@ -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 } diff --git a/security/sha512.go b/security/sha512.go index fffcf1b8..818cccc1 100644 --- a/security/sha512.go +++ b/security/sha512.go @@ -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))