-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
61 lines (50 loc) · 1.29 KB
/
config.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
51
52
53
54
55
56
57
58
59
60
61
/*************************************************************************
* Copyright 2020 Gravwell, Inc. All rights reserved.
* Contact: <[email protected]>
*
* This software may be modified and distributed under the terms of the
* BSD 2-clause license. See the LICENSE file for details.
**************************************************************************/
package main
import (
"errors"
"github.com/google/uuid"
"github.com/gravwell/gravwell/v3/ingest/config"
)
type global struct {
config.IngestConfig
Tag_Name string
}
type cfgType struct {
Global global
}
func GetConfig(path string) (*cfgType, error) {
var c cfgType
if err := config.LoadConfigFile(&c, path); err != nil {
return nil, err
}
if err := verifyConfig(&c); err != nil {
return nil, err
}
// Verify and set UUID
if _, ok := c.Global.IngesterUUID(); !ok {
id := uuid.New()
if err := c.Global.SetIngesterUUID(id, path); err != nil {
return nil, err
}
if id2, ok := c.Global.IngesterUUID(); !ok || id != id2 {
return nil, errors.New("Failed to set a new ingester UUID")
}
}
return &c, nil
}
func verifyConfig(c *cfgType) error {
//verify the global parameters
if err := c.Global.Verify(); err != nil {
return err
}
if c.Global.Tag_Name == "" {
c.Global.Tag_Name = "default"
}
return nil
}