fleet/server/contexts/installersize/installersize.go
Ian Littman a394596fbf
Bump installer max size, make configurable (#38122)
Resolves #37464.

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.

- [x] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)

## Testing

- [x] Added/updated automated tests

- [x] QA'd all new/changed functionality manually

## New Fleet configuration settings

- [x] Setting(s) is/are explicitly excluded from GitOps
2026-01-19 13:36:01 -06:00

41 lines
1.1 KiB
Go

// Package installersize provides context handling for the maximum software installer size.
package installersize
import (
"context"
"github.com/docker/go-units"
)
// Human formats a byte size into a human-readable string.
// It evaluates both SI units (KB, MB, GB) and binary units (KiB, MiB, GiB)
// and returns whichever representation is shorter.
func Human(bytes int64) string {
si := units.HumanSize(float64(bytes))
binary := units.BytesSize(float64(bytes))
if len(binary) < len(si) {
return binary
}
return si
}
type key struct{}
// DefaultMaxInstallerSize is the default maximum size allowed for software installers (10 GiB).
const DefaultMaxInstallerSize int64 = 10 * units.GiB
// NewContext returns a new context with the max installer size value.
func NewContext(ctx context.Context, maxSize int64) context.Context {
return context.WithValue(ctx, key{}, maxSize)
}
// FromContext returns the max installer size from the context if present.
// If not present, returns DefaultMaxInstallerSize.
func FromContext(ctx context.Context) int64 {
v, ok := ctx.Value(key{}).(int64)
if !ok {
return DefaultMaxInstallerSize
}
return v
}