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
|
package app
import (
"log"
"time"
"code.crute.us/mcrute/golib/cli"
"code.crute.us/mcrute/golib/vault"
"github.com/spf13/cobra"
)
type GitHubOauthCreds struct {
ClientId string `mapstructure:"client-id"`
ClientSecret string `mapstructure:"client-secret"`
}
type Config struct {
Bind []string
BindTLS []string
Debug bool
TemplateGlob string
TemplatePath string
MongoDbUri string
MongodbVaultPath string
LogFile string
TLSCacheDir string
TrustedIPRanges []string
ManagementIPRanges []string
Hostnames []string
DisableBackgroundJobs bool
RateLimit time.Duration
RateLimitBurst int
IssuerEndpoint string
JWTAudience string
AuthCookieDuration time.Duration
GitHubOauthCreds *GitHubOauthCreds
}
func NewConfigFromCmd(cmd *cobra.Command) Config {
f := cli.TolerantPflagSet{cmd.Flags()}
var githubOauth GitHubOauthCreds
oauthPath := f.MayGetString("github-oauth-vault-path")
err := vault.GetVaultKeyStruct(oauthPath, &githubOauth)
if err != nil {
log.Fatalf("Error getting %s from vault: %w", oauthPath, err)
}
return Config{
Bind: f.MayGetStringSlice("bind"),
BindTLS: f.MayGetStringSlice("bind-tls"),
Debug: f.MayGetBool("debug"),
TemplateGlob: f.MayGetString("template-glob"),
TemplatePath: f.MayGetString("template-path"),
MongoDbUri: f.MayGetString("mongodb-uri"),
MongodbVaultPath: f.MayGetString("mongodb-vault-path"),
DisableBackgroundJobs: f.MayGetBool("disable-bg-jobs"),
TrustedIPRanges: f.MayGetStringSlice("trusted-ip-ranges"),
ManagementIPRanges: f.MayGetStringSlice("management-ip-ranges"),
Hostnames: f.MayGetStringSlice("hostname"),
LogFile: f.MayGetString("log-file"),
TLSCacheDir: f.MayGetString("tls-cache-dir"),
RateLimit: f.MayGetDuration("rate-limit"),
RateLimitBurst: f.MayGetInt("rate-limit-burst"),
IssuerEndpoint: f.MayGetString("issuer-endpoint"),
JWTAudience: f.MayGetString("jwt-audience"),
AuthCookieDuration: f.MayGetDuration("auth-cookie-duration"),
GitHubOauthCreds: &githubOauth,
}
}
|