summaryrefslogtreecommitdiff
path: root/internal/configuration/validator/duo.go
blob: 5d6938b6dee19c47dfa4cb1c7f9a26c9de6b8af1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package validator

import (
	"fmt"

	"github.com/authelia/authelia/v4/internal/configuration/schema"
)

// ValidateDuo validates and updates the Duo configuration.
func ValidateDuo(config *schema.Configuration, validator *schema.StructValidator) {
	if config.DuoAPI.Disable {
		return
	}

	if config.DuoAPI.Hostname == "" && config.DuoAPI.IntegrationKey == "" && config.DuoAPI.SecretKey == "" {
		config.DuoAPI.Disable = true
	}

	if config.DuoAPI.Disable {
		return
	}

	if config.DuoAPI.Hostname == "" {
		validator.Push(fmt.Errorf(errFmtDuoMissingOption, "hostname"))
	}

	if config.DuoAPI.IntegrationKey == "" {
		validator.Push(fmt.Errorf(errFmtDuoMissingOption, "integration_key"))
	}

	if config.DuoAPI.SecretKey == "" {
		validator.Push(fmt.Errorf(errFmtDuoMissingOption, "secret_key"))
	}
}