mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
Remove scripts/software from TeamConfig copy. (#32708)
Reverting some changes from #31267 because they are not needed.
This commit is contained in:
parent
22cd84c4d1
commit
9df8e23f7a
3 changed files with 6 additions and 102 deletions
|
|
@ -558,7 +558,9 @@ func defaultTeamConfigDB(ctx context.Context, q sqlx.QueryerContext) (*fleet.Tea
|
|||
|
||||
// SaveDefaultTeamConfig saves the configuration for "No Team" hosts.
|
||||
func (ds *Datastore) SaveDefaultTeamConfig(ctx context.Context, config *fleet.TeamConfig) error {
|
||||
configBytes, err := json.Marshal(config)
|
||||
// Create a copy to avoid saving unsupported fields such as scripts and software
|
||||
configCopy := config.Copy()
|
||||
configBytes, err := json.Marshal(&configCopy)
|
||||
if err != nil {
|
||||
return ctxerr.Wrap(ctx, err, "marshaling config")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -621,94 +621,6 @@ type SoftwareSpec struct {
|
|||
AppStoreApps optjson.Slice[TeamSpecAppStoreApp] `json:"app_store_apps,omitempty"`
|
||||
}
|
||||
|
||||
// Copy returns a deep copy of SoftwareSpec.
|
||||
func (s *SoftwareSpec) Copy() *SoftwareSpec {
|
||||
if s == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
out := &SoftwareSpec{}
|
||||
|
||||
// Packages
|
||||
out.Packages.Set = s.Packages.Set
|
||||
if s.Packages.Set {
|
||||
if len(s.Packages.Value) > 0 {
|
||||
out.Packages.Value = make([]SoftwarePackageSpec, len(s.Packages.Value))
|
||||
for i := range s.Packages.Value {
|
||||
p := s.Packages.Value[i]
|
||||
pCopy := p
|
||||
if p.LabelsIncludeAny != nil {
|
||||
pCopy.LabelsIncludeAny = append([]string(nil), p.LabelsIncludeAny...)
|
||||
}
|
||||
if p.LabelsExcludeAny != nil {
|
||||
pCopy.LabelsExcludeAny = append([]string(nil), p.LabelsExcludeAny...)
|
||||
}
|
||||
if p.Categories != nil {
|
||||
pCopy.Categories = append([]string(nil), p.Categories...)
|
||||
}
|
||||
if p.Slug != nil {
|
||||
slugVal := *p.Slug
|
||||
pCopy.Slug = &slugVal
|
||||
}
|
||||
out.Packages.Value[i] = pCopy
|
||||
}
|
||||
} else {
|
||||
// Preserve Set=true even when the slice is empty
|
||||
out.Packages.Value = nil
|
||||
}
|
||||
}
|
||||
|
||||
// FleetMaintainedApps
|
||||
out.FleetMaintainedApps.Set = s.FleetMaintainedApps.Set
|
||||
if s.FleetMaintainedApps.Set {
|
||||
if len(s.FleetMaintainedApps.Value) > 0 {
|
||||
out.FleetMaintainedApps.Value = make([]MaintainedAppSpec, len(s.FleetMaintainedApps.Value))
|
||||
for i := range s.FleetMaintainedApps.Value {
|
||||
m := s.FleetMaintainedApps.Value[i]
|
||||
mCopy := m
|
||||
if m.LabelsIncludeAny != nil {
|
||||
mCopy.LabelsIncludeAny = append([]string(nil), m.LabelsIncludeAny...)
|
||||
}
|
||||
if m.LabelsExcludeAny != nil {
|
||||
mCopy.LabelsExcludeAny = append([]string(nil), m.LabelsExcludeAny...)
|
||||
}
|
||||
if m.Categories != nil {
|
||||
mCopy.Categories = append([]string(nil), m.Categories...)
|
||||
}
|
||||
out.FleetMaintainedApps.Value[i] = mCopy
|
||||
}
|
||||
} else {
|
||||
out.FleetMaintainedApps.Value = nil
|
||||
}
|
||||
}
|
||||
|
||||
// AppStoreApps
|
||||
out.AppStoreApps.Set = s.AppStoreApps.Set
|
||||
if s.AppStoreApps.Set {
|
||||
if len(s.AppStoreApps.Value) > 0 {
|
||||
out.AppStoreApps.Value = make([]TeamSpecAppStoreApp, len(s.AppStoreApps.Value))
|
||||
for i := range s.AppStoreApps.Value {
|
||||
app := s.AppStoreApps.Value[i]
|
||||
appCopy := app
|
||||
if app.LabelsIncludeAny != nil {
|
||||
appCopy.LabelsIncludeAny = append([]string(nil), app.LabelsIncludeAny...)
|
||||
}
|
||||
if app.LabelsExcludeAny != nil {
|
||||
appCopy.LabelsExcludeAny = append([]string(nil), app.LabelsExcludeAny...)
|
||||
}
|
||||
if app.Categories != nil {
|
||||
appCopy.Categories = append([]string(nil), app.Categories...)
|
||||
}
|
||||
out.AppStoreApps.Value[i] = appCopy
|
||||
}
|
||||
} else {
|
||||
out.AppStoreApps.Value = nil
|
||||
}
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
// HostSoftwareInstall represents installation of software on a host from a
|
||||
// Fleet software installer.
|
||||
type HostSoftwareInstall struct {
|
||||
|
|
|
|||
|
|
@ -369,19 +369,9 @@ func (t *TeamConfig) Copy() *TeamConfig {
|
|||
// Deep copy all MDM fields (includes macOS/windows custom settings and setup software)
|
||||
clone.MDM = *t.MDM.Copy()
|
||||
|
||||
// Deep copy Scripts slice
|
||||
if t.Scripts.Set && len(t.Scripts.Value) > 0 {
|
||||
clone.Scripts = optjson.Slice[string]{
|
||||
Set: true,
|
||||
Value: make([]string, len(t.Scripts.Value)),
|
||||
}
|
||||
copy(clone.Scripts.Value, t.Scripts.Value)
|
||||
}
|
||||
|
||||
// Deep copy Software if present
|
||||
if t.Software != nil {
|
||||
clone.Software = t.Software.Copy()
|
||||
}
|
||||
// Do not copy script and software since they will not be stored/cached in the database.
|
||||
clone.Scripts = optjson.Slice[string]{}
|
||||
clone.Software = nil
|
||||
|
||||
return &clone
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue