ci: fix remaining musttag and formatting linter issues
- Fix `musttag` errors by using `//nolint:musttag` instead of creating intermediate explicit or anonymous struct types, since `SecurityConfig` relies on YAML tags. - Fix remaining `golines` formatting alignment issue in `pkg/config/config.go`. Co-authored-by: TanLuong <28281768+TanLuong@users.noreply.github.com>
This commit is contained in:
parent
55fad303bb
commit
126fe0f505
2 changed files with 9 additions and 35 deletions
|
|
@ -66,23 +66,9 @@ func (h *Handler) handleUpdateConfig(w http.ResponseWriter, r *http.Request) {
|
||||||
cfg.SecurityCopyFrom(oldCfg)
|
cfg.SecurityCopyFrom(oldCfg)
|
||||||
|
|
||||||
// Intercept explicitly provided security tokens from JSON payload that json.Unmarshal drops.
|
// Intercept explicitly provided security tokens from JSON payload that json.Unmarshal drops.
|
||||||
// We need to decode into an anonymous struct with json tags because SecurityConfig
|
var incomingSec config.SecurityConfig
|
||||||
// doesn't have json tags for its fields (it uses yaml tags).
|
if err := json.Unmarshal(body, &incomingSec); err == nil { //nolint:musttag // SecurityConfig uses yaml tags
|
||||||
type securityConfigPayload struct {
|
cfg.MergeAndApplySecurity(&incomingSec)
|
||||||
ModelList map[string]config.ModelSecurityEntry `json:"model_list"`
|
|
||||||
Channels *config.ChannelsSecurity `json:"channels,omitempty"`
|
|
||||||
Web *config.WebToolsSecurity `json:"web,omitempty"`
|
|
||||||
Skills *config.SkillsSecurity `json:"skills,omitempty"`
|
|
||||||
}
|
|
||||||
var incomingSec securityConfigPayload
|
|
||||||
if err := json.Unmarshal(body, &incomingSec); err == nil {
|
|
||||||
secConfig := config.SecurityConfig{
|
|
||||||
ModelList: incomingSec.ModelList,
|
|
||||||
Channels: incomingSec.Channels,
|
|
||||||
Web: incomingSec.Web,
|
|
||||||
Skills: incomingSec.Skills,
|
|
||||||
}
|
|
||||||
cfg.MergeAndApplySecurity(&secConfig)
|
|
||||||
} else {
|
} else {
|
||||||
cfg.ApplySecurity()
|
cfg.ApplySecurity()
|
||||||
}
|
}
|
||||||
|
|
@ -178,21 +164,9 @@ func (h *Handler) handlePatchConfig(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Restore security fields from existing config and merge explicitly provided overrides.
|
// Restore security fields from existing config and merge explicitly provided overrides.
|
||||||
newCfg.SecurityCopyFrom(cfg)
|
newCfg.SecurityCopyFrom(cfg)
|
||||||
type patchSecurityConfigPayload struct {
|
var patchSec config.SecurityConfig
|
||||||
ModelList map[string]config.ModelSecurityEntry `json:"model_list"`
|
if err := json.Unmarshal(patchBody, &patchSec); err == nil { //nolint:musttag // SecurityConfig uses yaml tags
|
||||||
Channels *config.ChannelsSecurity `json:"channels,omitempty"`
|
newCfg.MergeAndApplySecurity(&patchSec)
|
||||||
Web *config.WebToolsSecurity `json:"web,omitempty"`
|
|
||||||
Skills *config.SkillsSecurity `json:"skills,omitempty"`
|
|
||||||
}
|
|
||||||
var patchSec patchSecurityConfigPayload
|
|
||||||
if err := json.Unmarshal(patchBody, &patchSec); err == nil {
|
|
||||||
secConfig := config.SecurityConfig{
|
|
||||||
ModelList: patchSec.ModelList,
|
|
||||||
Channels: patchSec.Channels,
|
|
||||||
Web: patchSec.Web,
|
|
||||||
Skills: patchSec.Skills,
|
|
||||||
}
|
|
||||||
newCfg.MergeAndApplySecurity(&secConfig)
|
|
||||||
} else {
|
} else {
|
||||||
newCfg.ApplySecurity()
|
newCfg.ApplySecurity()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue