-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvalidate.go
50 lines (41 loc) · 1.1 KB
/
validate.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.
package main
import (
"fmt"
"github.com/go-vela/types/constants"
"github.com/sirupsen/logrus"
)
// Validate verifies the provided database is configured properly.
func (d *db) Validate() error {
logrus.Debug("validating provided database configuration")
// check if an action was provided
switch {
case d.Actions.SetUntrusted:
fallthrough
case d.Actions.UpdatePrivRepos:
fallthrough
case d.Actions.All:
break
default:
logrus.Warning("no vela-migration actions provided")
}
// check if the database driver is set
if len(d.Driver) == 0 {
return fmt.Errorf("VELA_DATABASE_DRIVER is not properly configured")
}
switch d.Driver {
case constants.DriverPostgres:
fallthrough
case constants.DriverSqlite:
break
default:
return fmt.Errorf("invalid VELA_DATABASE_DRIVER provided: %s", d.Driver)
}
// check if the database address is set
if len(d.Address) == 0 {
return fmt.Errorf("VELA_DATABASE_ADDR is not properly configured")
}
return nil
}