bump compose-go to v2.4.5

Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
Guillaume Lours
2024-11-28 15:01:24 +01:00
parent 71c7889719
commit 8f70196de1
6 changed files with 88 additions and 47 deletions

View File

@ -108,6 +108,9 @@ func extractVariable(value interface{}, pattern *regexp.Regexp) ([]Variable, boo
if r >= 'A' && r <= 'Z' {
return false
}
if r >= '0' && r <= '9' {
return false
}
if r == '_' {
return false
}

View File

@ -560,39 +560,69 @@ func (p *Project) WithImagesResolved(resolver func(named reference.Named) (godig
})
}
type marshallOptions struct {
secretsContent bool
}
func WithSecretContent(o *marshallOptions) {
o.secretsContent = true
}
func (opt *marshallOptions) apply(p *Project) *Project {
if opt.secretsContent {
p = p.deepCopy()
for name, config := range p.Secrets {
config.marshallContent = true
p.Secrets[name] = config
}
}
return p
}
func applyMarshallOptions(p *Project, options ...func(*marshallOptions)) *Project {
opts := &marshallOptions{}
for _, option := range options {
option(opts)
}
p = opts.apply(p)
return p
}
// MarshalYAML marshal Project into a yaml tree
func (p *Project) MarshalYAML() ([]byte, error) {
func (p *Project) MarshalYAML(options ...func(*marshallOptions)) ([]byte, error) {
buf := bytes.NewBuffer([]byte{})
encoder := yaml.NewEncoder(buf)
encoder.SetIndent(2)
// encoder.CompactSeqIndent() FIXME https://github.com/go-yaml/yaml/pull/753
err := encoder.Encode(p)
src := applyMarshallOptions(p, options...)
err := encoder.Encode(src)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
// MarshalJSON makes Config implement json.Marshaler
func (p *Project) MarshalJSON() ([]byte, error) {
// MarshalJSON marshal Project into a json document
func (p *Project) MarshalJSON(options ...func(*marshallOptions)) ([]byte, error) {
src := applyMarshallOptions(p, options...)
m := map[string]interface{}{
"name": p.Name,
"services": p.Services,
"name": src.Name,
"services": src.Services,
}
if len(p.Networks) > 0 {
m["networks"] = p.Networks
if len(src.Networks) > 0 {
m["networks"] = src.Networks
}
if len(p.Volumes) > 0 {
m["volumes"] = p.Volumes
if len(src.Volumes) > 0 {
m["volumes"] = src.Volumes
}
if len(p.Secrets) > 0 {
m["secrets"] = p.Secrets
if len(src.Secrets) > 0 {
m["secrets"] = src.Secrets
}
if len(p.Configs) > 0 {
m["configs"] = p.Configs
if len(src.Configs) > 0 {
m["configs"] = src.Configs
}
for k, v := range p.Extensions {
for k, v := range src.Extensions {
m[k] = v
}
return json.MarshalIndent(m, "", " ")

View File

@ -678,16 +678,17 @@ func (u *UlimitsConfig) MarshalJSON() ([]byte, error) {
// NetworkConfig for a network
type NetworkConfig struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Driver string `yaml:"driver,omitempty" json:"driver,omitempty"`
DriverOpts Options `yaml:"driver_opts,omitempty" json:"driver_opts,omitempty"`
Ipam IPAMConfig `yaml:"ipam,omitempty" json:"ipam,omitempty"`
External External `yaml:"external,omitempty" json:"external,omitempty"`
Internal bool `yaml:"internal,omitempty" json:"internal,omitempty"`
Attachable bool `yaml:"attachable,omitempty" json:"attachable,omitempty"`
Labels Labels `yaml:"labels,omitempty" json:"labels,omitempty"`
EnableIPv6 *bool `yaml:"enable_ipv6,omitempty" json:"enable_ipv6,omitempty"`
Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Driver string `yaml:"driver,omitempty" json:"driver,omitempty"`
DriverOpts Options `yaml:"driver_opts,omitempty" json:"driver_opts,omitempty"`
Ipam IPAMConfig `yaml:"ipam,omitempty" json:"ipam,omitempty"`
External External `yaml:"external,omitempty" json:"external,omitempty"`
Internal bool `yaml:"internal,omitempty" json:"internal,omitempty"`
Attachable bool `yaml:"attachable,omitempty" json:"attachable,omitempty"`
Labels Labels `yaml:"labels,omitempty" json:"labels,omitempty"`
CustomLabels Labels `yaml:"-" json:"-"`
EnableIPv6 *bool `yaml:"enable_ipv6,omitempty" json:"enable_ipv6,omitempty"`
Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
}
// IPAMConfig for a network
@ -708,12 +709,13 @@ type IPAMPool struct {
// VolumeConfig for a volume
type VolumeConfig struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Driver string `yaml:"driver,omitempty" json:"driver,omitempty"`
DriverOpts Options `yaml:"driver_opts,omitempty" json:"driver_opts,omitempty"`
External External `yaml:"external,omitempty" json:"external,omitempty"`
Labels Labels `yaml:"labels,omitempty" json:"labels,omitempty"`
Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Driver string `yaml:"driver,omitempty" json:"driver,omitempty"`
DriverOpts Options `yaml:"driver_opts,omitempty" json:"driver_opts,omitempty"`
External External `yaml:"external,omitempty" json:"external,omitempty"`
Labels Labels `yaml:"labels,omitempty" json:"labels,omitempty"`
CustomLabels Labels `yaml:"-" json:"-"`
Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
}
// External identifies a Volume or Network as a reference to a resource that is
@ -730,16 +732,18 @@ type CredentialSpecConfig struct {
// FileObjectConfig is a config type for a file used by a service
type FileObjectConfig struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
File string `yaml:"file,omitempty" json:"file,omitempty"`
Environment string `yaml:"environment,omitempty" json:"environment,omitempty"`
Content string `yaml:"content,omitempty" json:"content,omitempty"`
External External `yaml:"external,omitempty" json:"external,omitempty"`
Labels Labels `yaml:"labels,omitempty" json:"labels,omitempty"`
Driver string `yaml:"driver,omitempty" json:"driver,omitempty"`
DriverOpts map[string]string `yaml:"driver_opts,omitempty" json:"driver_opts,omitempty"`
TemplateDriver string `yaml:"template_driver,omitempty" json:"template_driver,omitempty"`
Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
Name string `yaml:"name,omitempty" json:"name,omitempty"`
File string `yaml:"file,omitempty" json:"file,omitempty"`
Environment string `yaml:"environment,omitempty" json:"environment,omitempty"`
Content string `yaml:"content,omitempty" json:"content,omitempty"`
// configure marshalling to include Content - excluded by default to prevent sensitive data leaks
marshallContent bool
External External `yaml:"external,omitempty" json:"external,omitempty"`
Labels Labels `yaml:"labels,omitempty" json:"labels,omitempty"`
Driver string `yaml:"driver,omitempty" json:"driver,omitempty"`
DriverOpts map[string]string `yaml:"driver_opts,omitempty" json:"driver_opts,omitempty"`
TemplateDriver string `yaml:"template_driver,omitempty" json:"template_driver,omitempty"`
Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
}
const (
@ -773,14 +777,18 @@ type SecretConfig FileObjectConfig
// MarshalYAML makes SecretConfig implement yaml.Marshaller
func (s SecretConfig) MarshalYAML() (interface{}, error) {
// secret content is set while loading model. Never marshall it
s.Content = ""
if !s.marshallContent {
s.Content = ""
}
return FileObjectConfig(s), nil
}
// MarshalJSON makes SecretConfig implement json.Marshaller
func (s SecretConfig) MarshalJSON() ([]byte, error) {
// secret content is set while loading model. Never marshall it
s.Content = ""
if !s.marshallContent {
s.Content = ""
}
return json.Marshal(FileObjectConfig(s))
}