-
Notifications
You must be signed in to change notification settings - Fork 415
Expand file tree
/
Copy pathgit.go
More file actions
80 lines (64 loc) · 2.34 KB
/
git.go
File metadata and controls
80 lines (64 loc) · 2.34 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2022 Redpanda Data, Inc.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.md
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0
package config
import (
"errors"
"flag"
"time"
)
// Git config for Git Service
type Git struct {
Enabled bool `yaml:"enabled"`
// AllowedFileExtensions specifies file extensions that shall be picked up. If at least one is specified all other
// file extensions will be ignored.
AllowedFileExtensions []string `yaml:"-"`
// Max file size which will be considered. Files exceeding this size will be ignored and logged.
MaxFileSize int64 `yaml:"maxFileSize"`
// Whether or not to use the filename or the full filepath as key in the map
IndexByFullFilepath bool `yaml:"-"`
// RefreshInterval specifies how often the repository shall be pulled to check for new changes.
RefreshInterval time.Duration `yaml:"refreshInterval"`
// Repository that contains markdown files that document a Kafka topic.
Repository GitRepository `yaml:"repository"`
// Authentication Configs
BasicAuth GitAuthBasicAuth `yaml:"basicAuth"`
SSH GitAuthSSH `yaml:"ssh"`
GithubApp GitGithubApp `yaml:"githubApp"`
// CloneSubmodules enables shallow cloning of submodules at recursion depth of 1.
CloneSubmodules bool `yaml:"cloneSubmodules"`
}
// RegisterFlagsWithPrefix for all (sub)configs
func (c *Git) RegisterFlagsWithPrefix(f *flag.FlagSet, prefix string) {
c.BasicAuth.RegisterFlagsWithPrefix(f, prefix)
c.SSH.RegisterFlagsWithPrefix(f, prefix)
c.GithubApp.RegisterFlagsWithPrefix(f, prefix)
}
// Validate all root and child config structs
func (c *Git) Validate() error {
if !c.Enabled {
return nil
}
if c.RefreshInterval == 0 {
return errors.New("git config is enabled but refresh interval is set to 0 (disabled)")
}
if c.MaxFileSize <= 0 {
return errors.New("git config is enabled but file max size is <= 0")
}
if err := c.GithubApp.Validate(); err != nil {
return err
}
return c.Repository.Validate()
}
// SetDefaults for all root and child config structs
func (c *Git) SetDefaults() {
c.Repository.SetDefaults()
c.RefreshInterval = time.Minute
c.MaxFileSize = 500 * 1000 // 500KB
c.IndexByFullFilepath = false
}