mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
vendor: update compose-go to v2.0.0-rc.3
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
39
vendor/github.com/compose-spec/compose-go/v2/transform/build.go
generated
vendored
Normal file
39
vendor/github.com/compose-spec/compose-go/v2/transform/build.go
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright 2020 The Compose Specification 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 transform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/compose-spec/compose-go/v2/tree"
|
||||
)
|
||||
|
||||
func transformBuild(data any, p tree.Path) (any, error) {
|
||||
switch v := data.(type) {
|
||||
case map[string]any:
|
||||
if _, ok := v["context"]; !ok {
|
||||
v["context"] = "." // TODO(ndeloof) maybe we miss an explicit "set-defaults" loading phase
|
||||
}
|
||||
return transformMapping(v, p)
|
||||
case string:
|
||||
return map[string]any{
|
||||
"context": v,
|
||||
}, nil
|
||||
default:
|
||||
return data, fmt.Errorf("%s: invalid type %T for build", p, v)
|
||||
}
|
||||
}
|
107
vendor/github.com/compose-spec/compose-go/v2/transform/canonical.go
generated
vendored
Normal file
107
vendor/github.com/compose-spec/compose-go/v2/transform/canonical.go
generated
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
Copyright 2020 The Compose Specification 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 transform
|
||||
|
||||
import (
|
||||
"github.com/compose-spec/compose-go/v2/tree"
|
||||
)
|
||||
|
||||
type transformFunc func(data any, p tree.Path) (any, error)
|
||||
|
||||
var transformers = map[tree.Path]transformFunc{}
|
||||
|
||||
func init() {
|
||||
transformers["services.*"] = transformService
|
||||
transformers["services.*.build.secrets.*"] = transformFileMount
|
||||
transformers["services.*.build.additional_contexts"] = transformKeyValue
|
||||
transformers["services.*.depends_on"] = transformDependsOn
|
||||
transformers["services.*.env_file"] = transformEnvFile
|
||||
transformers["services.*.extends"] = transformExtends
|
||||
transformers["services.*.networks"] = transformServiceNetworks
|
||||
transformers["services.*.volumes.*"] = transformVolumeMount
|
||||
transformers["services.*.secrets.*"] = transformFileMount
|
||||
transformers["services.*.configs.*"] = transformFileMount
|
||||
transformers["services.*.ports"] = transformPorts
|
||||
transformers["services.*.build"] = transformBuild
|
||||
transformers["services.*.build.ssh"] = transformSSH
|
||||
transformers["services.*.ulimits.*"] = transformUlimits
|
||||
transformers["services.*.build.ulimits.*"] = transformUlimits
|
||||
transformers["volumes.*"] = transformMaybeExternal
|
||||
transformers["networks.*"] = transformMaybeExternal
|
||||
transformers["secrets.*"] = transformMaybeExternal
|
||||
transformers["configs.*"] = transformMaybeExternal
|
||||
transformers["include.*"] = transformInclude
|
||||
}
|
||||
|
||||
// Canonical transforms a compose model into canonical syntax
|
||||
func Canonical(yaml map[string]any) (map[string]any, error) {
|
||||
canonical, err := transform(yaml, tree.NewPath())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return canonical.(map[string]any), nil
|
||||
}
|
||||
|
||||
func transform(data any, p tree.Path) (any, error) {
|
||||
for pattern, transformer := range transformers {
|
||||
if p.Matches(pattern) {
|
||||
t, err := transformer(data, p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return t, nil
|
||||
}
|
||||
}
|
||||
switch v := data.(type) {
|
||||
case map[string]any:
|
||||
a, err := transformMapping(v, p)
|
||||
if err != nil {
|
||||
return a, err
|
||||
}
|
||||
return v, nil
|
||||
case []any:
|
||||
a, err := transformSequence(v, p)
|
||||
if err != nil {
|
||||
return a, err
|
||||
}
|
||||
return v, nil
|
||||
default:
|
||||
return data, nil
|
||||
}
|
||||
}
|
||||
|
||||
func transformSequence(v []any, p tree.Path) ([]any, error) {
|
||||
for i, e := range v {
|
||||
t, err := transform(e, p.Next("[]"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v[i] = t
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func transformMapping(v map[string]any, p tree.Path) (map[string]any, error) {
|
||||
for k, e := range v {
|
||||
t, err := transform(e, p.Next(k))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v[k] = t
|
||||
}
|
||||
return v, nil
|
||||
}
|
53
vendor/github.com/compose-spec/compose-go/v2/transform/dependson.go
generated
vendored
Normal file
53
vendor/github.com/compose-spec/compose-go/v2/transform/dependson.go
generated
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
Copyright 2020 The Compose Specification 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 transform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/compose-spec/compose-go/v2/tree"
|
||||
)
|
||||
|
||||
func transformDependsOn(data any, p tree.Path) (any, error) {
|
||||
switch v := data.(type) {
|
||||
case map[string]any:
|
||||
for i, e := range v {
|
||||
d, ok := e.(map[string]any)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%s.%s: unsupported value %s", p, i, v)
|
||||
}
|
||||
if _, ok := d["condition"]; !ok {
|
||||
d["condition"] = "service_started"
|
||||
}
|
||||
if _, ok := d["required"]; !ok {
|
||||
d["required"] = true
|
||||
}
|
||||
}
|
||||
return v, nil
|
||||
case []any:
|
||||
d := map[string]any{}
|
||||
for _, k := range v {
|
||||
d[k.(string)] = map[string]any{
|
||||
"condition": "service_started",
|
||||
"required": true,
|
||||
}
|
||||
}
|
||||
return d, nil
|
||||
default:
|
||||
return data, fmt.Errorf("%s: invalid type %T for depend_on", p, v)
|
||||
}
|
||||
}
|
55
vendor/github.com/compose-spec/compose-go/v2/transform/envfile.go
generated
vendored
Normal file
55
vendor/github.com/compose-spec/compose-go/v2/transform/envfile.go
generated
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
Copyright 2020 The Compose Specification 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 transform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/compose-spec/compose-go/v2/tree"
|
||||
)
|
||||
|
||||
func transformEnvFile(data any, p tree.Path) (any, error) {
|
||||
switch v := data.(type) {
|
||||
case string:
|
||||
return []any{
|
||||
transformEnvFileValue(v),
|
||||
}, nil
|
||||
case []any:
|
||||
for i, e := range v {
|
||||
v[i] = transformEnvFileValue(e)
|
||||
}
|
||||
return v, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("%s: invalid type %T for env_file", p, v)
|
||||
}
|
||||
}
|
||||
|
||||
func transformEnvFileValue(data any) any {
|
||||
switch v := data.(type) {
|
||||
case string:
|
||||
return map[string]any{
|
||||
"path": v,
|
||||
"required": true,
|
||||
}
|
||||
case map[string]any:
|
||||
if _, ok := v["required"]; !ok {
|
||||
v["required"] = true
|
||||
}
|
||||
return v
|
||||
}
|
||||
return nil
|
||||
}
|
36
vendor/github.com/compose-spec/compose-go/v2/transform/extends.go
generated
vendored
Normal file
36
vendor/github.com/compose-spec/compose-go/v2/transform/extends.go
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright 2020 The Compose Specification 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 transform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/compose-spec/compose-go/v2/tree"
|
||||
)
|
||||
|
||||
func transformExtends(data any, p tree.Path) (any, error) {
|
||||
switch v := data.(type) {
|
||||
case map[string]any:
|
||||
return transformMapping(v, p)
|
||||
case string:
|
||||
return map[string]any{
|
||||
"service": v,
|
||||
}, nil
|
||||
default:
|
||||
return data, fmt.Errorf("%s: invalid type %T for extends", p, v)
|
||||
}
|
||||
}
|
54
vendor/github.com/compose-spec/compose-go/v2/transform/external.go
generated
vendored
Normal file
54
vendor/github.com/compose-spec/compose-go/v2/transform/external.go
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
Copyright 2020 The Compose Specification 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 transform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/compose-spec/compose-go/v2/tree"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func transformMaybeExternal(data any, p tree.Path) (any, error) {
|
||||
if data == nil {
|
||||
return nil, nil
|
||||
}
|
||||
resource, err := transformMapping(data.(map[string]any), p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if ext, ok := resource["external"]; ok {
|
||||
name, named := resource["name"]
|
||||
if external, ok := ext.(map[string]any); ok {
|
||||
resource["external"] = true
|
||||
if extname, extNamed := external["name"]; extNamed {
|
||||
logrus.Warnf("%s: external.name is deprecated. Please set name and external: true", p)
|
||||
if named && extname != name {
|
||||
return nil, fmt.Errorf("%s: name and external.name conflict; only use name", p)
|
||||
}
|
||||
if !named {
|
||||
// adopt (deprecated) external.name if set
|
||||
resource["name"] = extname
|
||||
return resource, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resource, nil
|
||||
}
|
36
vendor/github.com/compose-spec/compose-go/v2/transform/include.go
generated
vendored
Normal file
36
vendor/github.com/compose-spec/compose-go/v2/transform/include.go
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright 2020 The Compose Specification 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 transform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/compose-spec/compose-go/v2/tree"
|
||||
)
|
||||
|
||||
func transformInclude(data any, p tree.Path) (any, error) {
|
||||
switch v := data.(type) {
|
||||
case map[string]any:
|
||||
return v, nil
|
||||
case string:
|
||||
return map[string]any{
|
||||
"path": v,
|
||||
}, nil
|
||||
default:
|
||||
return data, fmt.Errorf("%s: invalid type %T for external", p, v)
|
||||
}
|
||||
}
|
43
vendor/github.com/compose-spec/compose-go/v2/transform/mapping.go
generated
vendored
Normal file
43
vendor/github.com/compose-spec/compose-go/v2/transform/mapping.go
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
Copyright 2020 The Compose Specification 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 transform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/compose-spec/compose-go/v2/tree"
|
||||
)
|
||||
|
||||
func transformKeyValue(data any, p tree.Path) (any, error) {
|
||||
switch v := data.(type) {
|
||||
case map[string]any:
|
||||
return v, nil
|
||||
case []any:
|
||||
mapping := map[string]any{}
|
||||
for _, e := range v {
|
||||
before, after, found := strings.Cut(e.(string), "=")
|
||||
if !found {
|
||||
return nil, fmt.Errorf("%s: invalid value %s, expected key=value", p, e)
|
||||
}
|
||||
mapping[before] = after
|
||||
}
|
||||
return mapping, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("%s: invalid type %T", p, v)
|
||||
}
|
||||
}
|
86
vendor/github.com/compose-spec/compose-go/v2/transform/ports.go
generated
vendored
Normal file
86
vendor/github.com/compose-spec/compose-go/v2/transform/ports.go
generated
vendored
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
Copyright 2020 The Compose Specification 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 transform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/compose-spec/compose-go/v2/tree"
|
||||
"github.com/compose-spec/compose-go/v2/types"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
func transformPorts(data any, p tree.Path) (any, error) {
|
||||
switch entries := data.(type) {
|
||||
case []any:
|
||||
// We process the list instead of individual items here.
|
||||
// The reason is that one entry might be mapped to multiple ServicePortConfig.
|
||||
// Therefore we take an input of a list and return an output of a list.
|
||||
var ports []any
|
||||
for _, entry := range entries {
|
||||
switch value := entry.(type) {
|
||||
case int:
|
||||
parsed, err := types.ParsePortConfig(fmt.Sprint(value))
|
||||
if err != nil {
|
||||
return data, err
|
||||
}
|
||||
for _, v := range parsed {
|
||||
m, err := encode(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ports = append(ports, m)
|
||||
}
|
||||
case string:
|
||||
parsed, err := types.ParsePortConfig(value)
|
||||
if err != nil {
|
||||
return data, err
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range parsed {
|
||||
m, err := encode(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ports = append(ports, m)
|
||||
}
|
||||
case map[string]any:
|
||||
ports = append(ports, value)
|
||||
default:
|
||||
return data, fmt.Errorf("%s: invalid type %T for port", p, value)
|
||||
}
|
||||
}
|
||||
return ports, nil
|
||||
default:
|
||||
return data, fmt.Errorf("%s: invalid type %T for port", p, entries)
|
||||
}
|
||||
}
|
||||
|
||||
func encode(v any) (map[string]any, error) {
|
||||
m := map[string]any{}
|
||||
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
|
||||
Result: &m,
|
||||
TagName: "yaml",
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = decoder.Decode(v)
|
||||
return m, err
|
||||
}
|
36
vendor/github.com/compose-spec/compose-go/v2/transform/secrets.go
generated
vendored
Normal file
36
vendor/github.com/compose-spec/compose-go/v2/transform/secrets.go
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright 2020 The Compose Specification 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 transform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/compose-spec/compose-go/v2/tree"
|
||||
)
|
||||
|
||||
func transformFileMount(data any, p tree.Path) (any, error) {
|
||||
switch v := data.(type) {
|
||||
case map[string]any:
|
||||
return data, nil
|
||||
case string:
|
||||
return map[string]any{
|
||||
"source": v,
|
||||
}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("%s: unsupported type %T", p, data)
|
||||
}
|
||||
}
|
41
vendor/github.com/compose-spec/compose-go/v2/transform/services.go
generated
vendored
Normal file
41
vendor/github.com/compose-spec/compose-go/v2/transform/services.go
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
Copyright 2020 The Compose Specification 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 transform
|
||||
|
||||
import (
|
||||
"github.com/compose-spec/compose-go/v2/tree"
|
||||
)
|
||||
|
||||
func transformService(data any, p tree.Path) (any, error) {
|
||||
switch value := data.(type) {
|
||||
case map[string]any:
|
||||
return transformMapping(value, p)
|
||||
default:
|
||||
return value, nil
|
||||
}
|
||||
}
|
||||
|
||||
func transformServiceNetworks(data any, _ tree.Path) (any, error) {
|
||||
if slice, ok := data.([]any); ok {
|
||||
networks := make(map[string]any, len(slice))
|
||||
for _, net := range slice {
|
||||
networks[net.(string)] = nil
|
||||
}
|
||||
return networks, nil
|
||||
}
|
||||
return data, nil
|
||||
}
|
51
vendor/github.com/compose-spec/compose-go/v2/transform/ssh.go
generated
vendored
Normal file
51
vendor/github.com/compose-spec/compose-go/v2/transform/ssh.go
generated
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
Copyright 2020 The Compose Specification 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 transform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/compose-spec/compose-go/v2/tree"
|
||||
)
|
||||
|
||||
func transformSSH(data any, p tree.Path) (any, error) {
|
||||
switch v := data.(type) {
|
||||
case map[string]any:
|
||||
return v, nil
|
||||
case []any:
|
||||
result := make(map[string]any, len(v))
|
||||
for _, e := range v {
|
||||
s, ok := e.(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid ssh key type %T", e)
|
||||
}
|
||||
id, path, ok := strings.Cut(s, "=")
|
||||
if !ok {
|
||||
if id != "default" {
|
||||
return nil, fmt.Errorf("invalid ssh key %q", s)
|
||||
}
|
||||
result[id] = nil
|
||||
continue
|
||||
}
|
||||
result[id] = path
|
||||
}
|
||||
return result, nil
|
||||
default:
|
||||
return data, fmt.Errorf("%s: invalid type %T for ssh", p, v)
|
||||
}
|
||||
}
|
34
vendor/github.com/compose-spec/compose-go/v2/transform/ulimits.go
generated
vendored
Normal file
34
vendor/github.com/compose-spec/compose-go/v2/transform/ulimits.go
generated
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
Copyright 2020 The Compose Specification 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 transform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/compose-spec/compose-go/v2/tree"
|
||||
)
|
||||
|
||||
func transformUlimits(data any, p tree.Path) (any, error) {
|
||||
switch v := data.(type) {
|
||||
case map[string]any:
|
||||
return v, nil
|
||||
case int:
|
||||
return v, nil
|
||||
default:
|
||||
return data, fmt.Errorf("%s: invalid type %T for external", p, v)
|
||||
}
|
||||
}
|
49
vendor/github.com/compose-spec/compose-go/v2/transform/volume.go
generated
vendored
Normal file
49
vendor/github.com/compose-spec/compose-go/v2/transform/volume.go
generated
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
Copyright 2020 The Compose Specification 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 transform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
"github.com/compose-spec/compose-go/v2/format"
|
||||
"github.com/compose-spec/compose-go/v2/tree"
|
||||
)
|
||||
|
||||
func transformVolumeMount(data any, p tree.Path) (any, error) {
|
||||
switch v := data.(type) {
|
||||
case map[string]any:
|
||||
return v, nil
|
||||
case string:
|
||||
volume, err := format.ParseVolume(v) // TODO(ndeloof) ParseVolume should not rely on types and return map[string]
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
volume.Target = cleanTarget(volume.Target)
|
||||
|
||||
return encode(volume)
|
||||
default:
|
||||
return data, fmt.Errorf("%s: invalid type %T for service volume mount", p, v)
|
||||
}
|
||||
}
|
||||
|
||||
func cleanTarget(target string) string {
|
||||
if target == "" {
|
||||
return ""
|
||||
}
|
||||
return path.Clean(target)
|
||||
}
|
Reference in New Issue
Block a user