-
-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy pathconfig.go
174 lines (142 loc) · 4.34 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package config
import (
"fmt"
"os"
"path"
"time"
)
// Config holds the overall configuration for the application.
type Config struct {
// Global contains global configuration settings.
Global Global
// Server contains the API server configuration.
Server Server
// Paths holds various filesystem path configurations used throughout the application.
Paths PathsConfig
// UI contains settings specific to the application's user interface.
UI UI
// Warnings contains a list of warnings generated during the configuration loading process.
Warnings []string
}
type Global struct {
// Debug toggles debug mode; when true, the application may output extra logs and error details.
Debug bool
// LogFormat defines the output format for log messages (e.g., JSON, plain text).
LogFormat string
// TZ represents the timezone setting for the application (for example, "UTC" or "America/New_York").
TZ string
// Location represents the time location for the application based on the TZ setting.
Location *time.Location
// WorkDir specifies the default working directory for DAG (Directed Acyclic Graph) files.
// If not explicitly provided, it defaults to the directory where the DAG file resides.
WorkDir string
}
func (cfg *Global) setTimezone() error {
if cfg.TZ != "" {
loc, err := time.LoadLocation(cfg.TZ)
if err != nil {
return fmt.Errorf("failed to load timezone: %w", err)
}
cfg.Location = loc
os.Setenv("TZ", cfg.TZ)
} else {
_, offset := time.Now().Zone()
if offset == 0 {
cfg.TZ = "UTC"
} else {
cfg.TZ = fmt.Sprintf("UTC%+d", offset/3600)
}
cfg.Location = time.Local
}
return nil
}
// Server contains the API server configuration
type Server struct {
// Host defines the hostname or IP address on which the application will run.
Host string
// Port specifies the network port for incoming connections.
Port int
// BasePath is the root URL path from which the application is served.
// This is useful when hosting the app behind a reverse proxy under a subpath.
BasePath string
// APIBasePath sets the base path for all API endpoints provided by the application.
APIBasePath string
// Headless determines if the application should run without a graphical user interface.
// Useful for automated or headless server environments.
Headless bool
// LatestStatusToday indicates whether the application should display only the most recent status for the current day.
LatestStatusToday bool
// TLS contains configuration details for enabling TLS/SSL encryption,
// such as certificate and key file paths.
TLS *TLSConfig
// Auth contains authentication settings (such as credentials or tokens) needed to secure the application.
Auth Auth
// RemoteNodes holds a list of configurations for connecting to remote nodes.
// This enables the management of DAGs on external servers.
RemoteNodes []RemoteNode
}
func (cfg *Server) cleanBasePath() {
if cfg.BasePath == "" {
return
}
// Clean the provided BasePath.
cleanPath := path.Clean(cfg.BasePath)
// Ensure the path is absolute.
if !path.IsAbs(cleanPath) {
cleanPath = path.Join("/", cleanPath)
}
// If the cleaned path is the root, reset it to an empty string.
if cleanPath == "/" {
cfg.BasePath = ""
} else {
cfg.BasePath = cleanPath
}
}
// Auth represents the authentication configuration
type Auth struct {
Basic AuthBasic
Token AuthToken
}
// AuthBasic represents the basic authentication configuration
type AuthBasic struct {
Enabled bool
Username string
Password string
}
// AuthToken represents the authentication token configuration
type AuthToken struct {
Enabled bool
Value string
}
// Paths represents the file system paths configuration
type PathsConfig struct {
DAGsDir string
Executable string
LogDir string
DataDir string
SuspendFlagsDir string
AdminLogsDir string
BaseConfig string
}
type UI struct {
LogEncodingCharset string
NavbarColor string
NavbarTitle string
MaxDashboardPageLimit int
}
// RemoteNode represents a remote node configuration
type RemoteNode struct {
Name string
APIBaseURL string
IsBasicAuth bool
BasicAuthUsername string
BasicAuthPassword string
IsAuthToken bool
AuthToken string
SkipTLSVerify bool
}
// TLSConfig represents TLS configuration
type TLSConfig struct {
CertFile string
KeyFile string
}