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