mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
daemon refuses unknown filters in prune functions
- container prune - volume prune - image prune - network prune Signed-off-by: Gaetan de Villele <gdevillele@gmail.com>
This commit is contained in:
parent
b61ffbfb52
commit
71760ae648
1 changed files with 46 additions and 1 deletions
|
@ -25,6 +25,27 @@ var (
|
|||
// ErrPruneRunning is returned when a prune request is received while
|
||||
// one is in progress
|
||||
ErrPruneRunning = fmt.Errorf("a prune operation is already running")
|
||||
|
||||
containersAcceptedFilters = map[string]bool{
|
||||
"label": true,
|
||||
"label!": true,
|
||||
"until": true,
|
||||
}
|
||||
volumesAcceptedFilters = map[string]bool{
|
||||
"label": true,
|
||||
"label!": true,
|
||||
}
|
||||
imagesAcceptedFilters = map[string]bool{
|
||||
"dangling": true,
|
||||
"label": true,
|
||||
"label!": true,
|
||||
"until": true,
|
||||
}
|
||||
networksAcceptedFilters = map[string]bool{
|
||||
"label": true,
|
||||
"label!": true,
|
||||
"until": true,
|
||||
}
|
||||
)
|
||||
|
||||
// ContainersPrune removes unused containers
|
||||
|
@ -36,6 +57,12 @@ func (daemon *Daemon) ContainersPrune(ctx context.Context, pruneFilters filters.
|
|||
|
||||
rep := &types.ContainersPruneReport{}
|
||||
|
||||
// make sure that only accepted filters have been received
|
||||
err := pruneFilters.Validate(containersAcceptedFilters)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
until, err := getUntilFromPruneFilters(pruneFilters)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -81,6 +108,12 @@ func (daemon *Daemon) VolumesPrune(ctx context.Context, pruneFilters filters.Arg
|
|||
}
|
||||
defer atomic.StoreInt32(&daemon.pruneRunning, 0)
|
||||
|
||||
// make sure that only accepted filters have been received
|
||||
err := pruneFilters.Validate(volumesAcceptedFilters)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rep := &types.VolumesPruneReport{}
|
||||
|
||||
pruneVols := func(v volume.Volume) error {
|
||||
|
@ -117,7 +150,7 @@ func (daemon *Daemon) VolumesPrune(ctx context.Context, pruneFilters filters.Arg
|
|||
return nil
|
||||
}
|
||||
|
||||
err := daemon.traverseLocalVolumes(pruneVols)
|
||||
err = daemon.traverseLocalVolumes(pruneVols)
|
||||
|
||||
return rep, err
|
||||
}
|
||||
|
@ -129,6 +162,12 @@ func (daemon *Daemon) ImagesPrune(ctx context.Context, pruneFilters filters.Args
|
|||
}
|
||||
defer atomic.StoreInt32(&daemon.pruneRunning, 0)
|
||||
|
||||
// make sure that only accepted filters have been received
|
||||
err := pruneFilters.Validate(imagesAcceptedFilters)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rep := &types.ImagesPruneReport{}
|
||||
|
||||
danglingOnly := true
|
||||
|
@ -357,6 +396,12 @@ func (daemon *Daemon) NetworksPrune(ctx context.Context, pruneFilters filters.Ar
|
|||
}
|
||||
defer atomic.StoreInt32(&daemon.pruneRunning, 0)
|
||||
|
||||
// make sure that only accepted filters have been received
|
||||
err := pruneFilters.Validate(networksAcceptedFilters)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := getUntilFromPruneFilters(pruneFilters); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue