-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
58 lines (44 loc) · 1.11 KB
/
main.go
File metadata and controls
58 lines (44 loc) · 1.11 KB
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
51
52
53
54
55
56
57
58
package main
import (
"context"
"github.com/ci-space/validate-credentials/internal/credentials"
"github.com/ci-space/validate-credentials/internal/validator"
"log/slog"
"os"
"strings"
)
func main() {
ctx := context.Background()
slog.Info("allocating validators")
validators := validator.Allocate(credentials.NewEnvStore())
if len(validators) == 0 {
fail("no found validators. please check your configuration")
}
names := make([]string, len(validators))
i := 0
for name := range validators {
names[i] = name
i++
}
slog.Info("running validators", slog.Any("validators", strings.Join(names, ", ")))
if !runValidators(ctx, validators) {
os.Exit(1)
}
}
func runValidators(ctx context.Context, validators map[string]validator.Validator) bool {
ok := true
for name, v := range validators {
err := v.Validate(ctx)
if err != nil {
ok = false
slog.Error("validation failed", slog.String("validator", name), slog.Any("err", err))
continue
}
slog.Info("validation succeed", slog.String("validator", name))
}
return ok
}
func fail(message string) {
slog.Error(message)
os.Exit(1)
}