|
1
|
package api |
|
2
|
|
|
3
|
import ( |
|
4
|
"net/http" |
|
5
|
|
|
6
|
"github.com/conflicthq/scuttlebot/internal/config" |
|
7
|
) |
|
8
|
|
|
9
|
type settingsResponse struct { |
|
10
|
TLS tlsInfo `json:"tls"` |
|
11
|
Policies Policies `json:"policies"` |
|
12
|
BotCommands map[string][]BotCommand `json:"bot_commands,omitempty"` |
|
13
|
} |
|
14
|
|
|
15
|
type tlsInfo struct { |
|
16
|
Enabled bool `json:"enabled"` |
|
17
|
Domain string `json:"domain,omitempty"` |
|
18
|
AllowInsecure bool `json:"allow_insecure"` |
|
19
|
} |
|
20
|
|
|
21
|
func (s *Server) handleGetSettings(w http.ResponseWriter, r *http.Request) { |
|
22
|
resp := settingsResponse{ |
|
23
|
TLS: tlsInfo{ |
|
24
|
Enabled: s.tlsDomain != "", |
|
25
|
Domain: s.tlsDomain, |
|
26
|
AllowInsecure: true, |
|
27
|
}, |
|
28
|
} |
|
29
|
if s.policies != nil { |
|
30
|
resp.Policies = s.policies.Get() |
|
31
|
} |
|
32
|
// Prefer ConfigStore for fields that have migrated to scuttlebot.yaml. |
|
33
|
if s.cfgStore != nil { |
|
34
|
cfg := s.cfgStore.Get() |
|
35
|
resp.Policies.AgentPolicy = toAPIAgentPolicy(cfg.AgentPolicy) |
|
36
|
resp.Policies.Logging = toAPILogging(cfg.Logging) |
|
37
|
resp.Policies.Bridge.WebUserTTLMinutes = cfg.Bridge.WebUserTTLMinutes |
|
38
|
} |
|
39
|
resp.BotCommands = botCommands |
|
40
|
writeJSON(w, http.StatusOK, resp) |
|
41
|
} |
|
42
|
|
|
43
|
func toAPIAgentPolicy(c config.AgentPolicyConfig) AgentPolicy { |
|
44
|
return AgentPolicy{ |
|
45
|
RequireCheckin: c.RequireCheckin, |
|
46
|
CheckinChannel: c.CheckinChannel, |
|
47
|
RequiredChannels: c.RequiredChannels, |
|
48
|
} |
|
49
|
} |
|
50
|
|
|
51
|
func toAPILogging(c config.LoggingConfig) LoggingPolicy { |
|
52
|
return LoggingPolicy{ |
|
53
|
Enabled: c.Enabled, |
|
54
|
Dir: c.Dir, |
|
55
|
Format: c.Format, |
|
56
|
Rotation: c.Rotation, |
|
57
|
MaxSizeMB: c.MaxSizeMB, |
|
58
|
PerChannel: c.PerChannel, |
|
59
|
MaxAgeDays: c.MaxAgeDays, |
|
60
|
} |
|
61
|
} |
|
62
|
|