mirror of
https://github.com/docker/compose.git
synced 2026-11-28 02:49:57 +00:00
Some checks are pending
ci / validate (lint) (push) Waiting to run
ci / validate (relay-lint) (push) Waiting to run
ci / validate (relay-test) (push) Waiting to run
ci / validate (validate-docs) (push) Waiting to run
ci / validate (validate-go-mod) (push) Waiting to run
ci / validate (validate-headers) (push) Waiting to run
ci / validate (validate-mocks) (push) Waiting to run
ci / binary (push) Waiting to run
ci / binary-finalize (push) Blocked by required conditions
ci / bin-image-test (push) Waiting to run
ci / relay-image-test (push) Waiting to run
ci / test (push) Waiting to run
ci / e2e (plugin, oldstable, graphdriver) (push) Waiting to run
ci / e2e (standalone, oldstable, graphdriver) (push) Waiting to run
ci / e2e (plugin, stable, containerd) (push) Waiting to run
ci / e2e (plugin, stable, graphdriver) (push) Waiting to run
ci / e2e (standalone, stable, containerd) (push) Waiting to run
ci / e2e (standalone, stable, graphdriver) (push) Waiting to run
ci / e2e (plugin, test, graphdriver, jobs extension) (push) Waiting to run
ci / coverage (push) Blocked by required conditions
ci / ci-ok (push) Blocked by required conditions
ci / release (push) Blocked by required conditions
merge / bin-image-prepare (push) Waiting to run
merge / bin-image (push) Blocked by required conditions
merge / relay-image (push) Waiting to run
merge / module-image (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
zizmor / zizmor (push) Waiting to run
DownOptions.Validate omitted the empty ImagePruneNone value from the allowed list, so the error did not tell callers that "" is accepted. Quote the allowed values so an empty one stays readable, fall back to a generic message when no closed set is given, and word the Logs Index error properly when no service is selected. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
74 lines
2.7 KiB
Go
74 lines
2.7 KiB
Go
/*
|
|
Copyright 2020 Docker Compose CLI authors
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"slices"
|
|
)
|
|
|
|
// Validate checks the options of Logs. A replica is selected inside one
|
|
// service, so Index requires exactly one service in Services: with none there
|
|
// is nothing to select the replica of, and with several the replica would
|
|
// silently be looked up in the first one only. It returns nil, or an error
|
|
// matching ErrIncompatibleOptions, and Logs calls it before doing anything.
|
|
func (o LogOptions) Validate() error {
|
|
if o.Index > 0 && len(o.Services) != 1 {
|
|
return incompatible("Index selects a replica of one service, but "+servicesSelected(len(o.Services)),
|
|
"Index", "Services")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Validate checks the options of Events: the Consumer receives every event and
|
|
// must be set. It returns nil, or an error matching ErrInvalidOption, and
|
|
// Events calls it before doing anything.
|
|
func (o EventsOptions) Validate() error {
|
|
if o.Consumer == nil {
|
|
return &InvalidOptionError{Option: "Consumer", Reason: "a consumer of the events is required"}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Validate checks the options of Publish: OCIVersion must be empty (the
|
|
// version is then determined from the registry) or one of the OCIVersion*
|
|
// constants. It returns nil, or an error matching ErrInvalidOption, and
|
|
// Publish calls it before pushing anything.
|
|
func (o PublishOptions) Validate() error {
|
|
allowed := []string{string(OCIVersion1_0), string(OCIVersion1_1)}
|
|
if o.OCIVersion != "" && !slices.Contains(allowed, string(o.OCIVersion)) {
|
|
return &InvalidOptionError{Option: "OCIVersion", Value: string(o.OCIVersion), Allowed: allowed}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Validate checks the options of Down: Images must be one of the ImagePrune*
|
|
// values. It returns nil, or an error matching ErrInvalidOption, and Down
|
|
// calls it before touching a single resource.
|
|
func (o DownOptions) Validate() error {
|
|
if !o.Images.Valid() {
|
|
return &InvalidOptionError{Option: "Images", Value: string(o.Images), Allowed: []string{string(ImagePruneNone), string(ImagePruneLocal), string(ImagePruneAll)}}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func servicesSelected(n int) string {
|
|
if n == 0 {
|
|
return "no service is selected"
|
|
}
|
|
return fmt.Sprintf("%d services are selected", n)
|
|
}
|