You've already forked woodpecker
mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-11-29 21:48:14 +02:00
@@ -36,7 +36,7 @@ func (c *volumeCacher) Restore(repo, branch string, mounts []string) *yaml_types
|
||||
return &yaml_types.Container{
|
||||
Name: "rebuild_cache",
|
||||
Image: "plugins/volume-cache:1.0.0",
|
||||
Settings: map[string]interface{}{
|
||||
Settings: map[string]any{
|
||||
"mount": mounts,
|
||||
"path": "/cache",
|
||||
"restore": true,
|
||||
@@ -59,7 +59,7 @@ func (c *volumeCacher) Rebuild(repo, branch string, mounts []string) *yaml_types
|
||||
return &yaml_types.Container{
|
||||
Name: "rebuild_cache",
|
||||
Image: "plugins/volume-cache:1.0.0",
|
||||
Settings: map[string]interface{}{
|
||||
Settings: map[string]any{
|
||||
"mount": mounts,
|
||||
"path": "/cache",
|
||||
"rebuild": true,
|
||||
@@ -89,7 +89,7 @@ func (c *s3Cacher) Restore(_, _ string, mounts []string) *yaml_types.Container {
|
||||
return &yaml_types.Container{
|
||||
Name: "rebuild_cache",
|
||||
Image: "plugins/s3-cache:latest",
|
||||
Settings: map[string]interface{}{
|
||||
Settings: map[string]any{
|
||||
"mount": mounts,
|
||||
"access_key": c.access,
|
||||
"secret_key": c.secret,
|
||||
@@ -104,7 +104,7 @@ func (c *s3Cacher) Rebuild(_, _ string, mounts []string) *yaml_types.Container {
|
||||
return &yaml_types.Container{
|
||||
Name: "rebuild_cache",
|
||||
Image: "plugins/s3-cache:latest",
|
||||
Settings: map[string]interface{}{
|
||||
Settings: map[string]any{
|
||||
"mount": mounts,
|
||||
"access_key": c.access,
|
||||
"secret_key": c.secret,
|
||||
|
||||
@@ -151,7 +151,7 @@ func (c *Compiler) Compile(conf *yaml_types.Workflow) (*backend_types.Config, er
|
||||
|
||||
// add default clone step
|
||||
if !c.local && len(conf.Clone.ContainerList) == 0 && !conf.SkipClone {
|
||||
cloneSettings := map[string]interface{}{"depth": "0"}
|
||||
cloneSettings := map[string]any{"depth": "0"}
|
||||
if c.metadata.Curr.Event == metadata.EventTag {
|
||||
cloneSettings["tags"] = "true"
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
|
||||
// ParamsToEnv uses reflection to convert a map[string]interface to a list
|
||||
// of environment variables.
|
||||
func ParamsToEnv(from map[string]interface{}, to, secrets map[string]string) (err error) {
|
||||
func ParamsToEnv(from map[string]any, to, secrets map[string]string) (err error) {
|
||||
if to == nil {
|
||||
return fmt.Errorf("no map to write to")
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func isComplex(t reflect.Kind) bool {
|
||||
}
|
||||
|
||||
// sanitizeParamValue returns the value of a setting as string prepared to be injected as environment variable
|
||||
func sanitizeParamValue(v interface{}, secrets map[string]string) (string, error) {
|
||||
func sanitizeParamValue(v any, secrets map[string]string) (string, error) {
|
||||
t := reflect.TypeOf(v)
|
||||
vv := reflect.ValueOf(v)
|
||||
|
||||
@@ -82,7 +82,7 @@ func sanitizeParamValue(v interface{}, secrets map[string]string) (string, error
|
||||
case reflect.Map:
|
||||
switch v := v.(type) {
|
||||
// gopkg.in/yaml.v3 only emits this map interface
|
||||
case map[string]interface{}:
|
||||
case map[string]any:
|
||||
// check if it's a secret and return value if it's the case
|
||||
value, isSecret, err := injectSecret(v, secrets)
|
||||
if err != nil {
|
||||
@@ -139,7 +139,7 @@ func sanitizeParamValue(v interface{}, secrets map[string]string) (string, error
|
||||
}
|
||||
|
||||
// handleComplex uses yaml2json to get json strings as values for environment variables
|
||||
func handleComplex(v interface{}, secrets map[string]string) (string, error) {
|
||||
func handleComplex(v any, secrets map[string]string) (string, error) {
|
||||
v, err := injectSecretRecursive(v, secrets)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -159,7 +159,7 @@ func handleComplex(v interface{}, secrets map[string]string) (string, error) {
|
||||
// injectSecret probes if a map is a from_secret request.
|
||||
// If it's a from_secret request it either returns the secret value or an error if the secret was not found
|
||||
// else it just indicates to progress normally using the provided map as is
|
||||
func injectSecret(v map[string]interface{}, secrets map[string]string) (string, bool, error) {
|
||||
func injectSecret(v map[string]any, secrets map[string]string) (string, bool, error) {
|
||||
if secretNameI, ok := v["from_secret"]; ok {
|
||||
if secretName, ok := secretNameI.(string); ok {
|
||||
if secret, ok := secrets[strings.ToLower(secretName)]; ok {
|
||||
@@ -174,7 +174,7 @@ func injectSecret(v map[string]interface{}, secrets map[string]string) (string,
|
||||
|
||||
// injectSecretRecursive iterates over all types and if they contain elements
|
||||
// it iterates recursively over them too, using injectSecret internally
|
||||
func injectSecretRecursive(v interface{}, secrets map[string]string) (interface{}, error) {
|
||||
func injectSecretRecursive(v any, secrets map[string]string) (any, error) {
|
||||
t := reflect.TypeOf(v)
|
||||
|
||||
if !isComplex(t.Kind()) {
|
||||
@@ -185,7 +185,7 @@ func injectSecretRecursive(v interface{}, secrets map[string]string) (interface{
|
||||
case reflect.Map:
|
||||
switch v := v.(type) {
|
||||
// gopkg.in/yaml.v3 only emits this map interface
|
||||
case map[string]interface{}:
|
||||
case map[string]any:
|
||||
// handle secrets
|
||||
value, isSecret, err := injectSecret(v, secrets)
|
||||
if err != nil {
|
||||
@@ -207,7 +207,7 @@ func injectSecretRecursive(v interface{}, secrets map[string]string) (interface{
|
||||
|
||||
case reflect.Array, reflect.Slice:
|
||||
vv := reflect.ValueOf(v)
|
||||
vl := make([]interface{}, vv.Len())
|
||||
vl := make([]any, vv.Len())
|
||||
|
||||
for i := 0; i < vv.Len(); i++ {
|
||||
v, err := injectSecretRecursive(vv.Index(i).Interface(), secrets)
|
||||
|
||||
@@ -22,21 +22,21 @@ import (
|
||||
)
|
||||
|
||||
func TestParamsToEnv(t *testing.T) {
|
||||
from := map[string]interface{}{
|
||||
from := map[string]any{
|
||||
"skip": nil,
|
||||
"string": "stringz",
|
||||
"int": 1,
|
||||
"float": 1.2,
|
||||
"bool": true,
|
||||
"slice": []int{1, 2, 3},
|
||||
"map": map[string]interface{}{"hello": "world"},
|
||||
"map": map[string]any{"hello": "world"},
|
||||
"complex": []struct{ Name string }{{"Jack"}, {"Jill"}},
|
||||
"complex2": struct{ Name string }{"Jack"},
|
||||
"from.address": "noreply@example.com",
|
||||
"tags": stringsToInterface("next", "latest"),
|
||||
"tag": stringsToInterface("next"),
|
||||
"my_secret": map[string]interface{}{"from_secret": "secret_token"},
|
||||
"UPPERCASE_SECRET": map[string]interface{}{"from_secret": "SECRET_TOKEN"},
|
||||
"my_secret": map[string]any{"from_secret": "secret_token"},
|
||||
"UPPERCASE_SECRET": map[string]any{"from_secret": "SECRET_TOKEN"},
|
||||
}
|
||||
want := map[string]string{
|
||||
"PLUGIN_STRING": "stringz",
|
||||
@@ -62,7 +62,7 @@ func TestParamsToEnv(t *testing.T) {
|
||||
|
||||
// handle edge cases (#1609)
|
||||
got = map[string]string{}
|
||||
assert.NoError(t, ParamsToEnv(map[string]interface{}{"a": []interface{}{"a", nil}}, got, nil))
|
||||
assert.NoError(t, ParamsToEnv(map[string]any{"a": []any{"a", nil}}, got, nil))
|
||||
assert.EqualValues(t, map[string]string{"PLUGIN_A": "a,"}, got)
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ list.map:
|
||||
password:
|
||||
from_secret: cb_password
|
||||
`)
|
||||
var from map[string]interface{}
|
||||
var from map[string]any
|
||||
err := yaml.Unmarshal(fromYAML, &from)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -122,7 +122,7 @@ func TestYAMLToParamsToEnvError(t *testing.T) {
|
||||
fromYAML := []byte(`my_secret:
|
||||
from_secret: not_a_secret
|
||||
`)
|
||||
var from map[string]interface{}
|
||||
var from map[string]any
|
||||
err := yaml.Unmarshal(fromYAML, &from)
|
||||
assert.NoError(t, err)
|
||||
secrets := map[string]string{
|
||||
@@ -131,8 +131,8 @@ func TestYAMLToParamsToEnvError(t *testing.T) {
|
||||
assert.Error(t, ParamsToEnv(from, make(map[string]string), secrets))
|
||||
}
|
||||
|
||||
func stringsToInterface(val ...string) []interface{} {
|
||||
res := make([]interface{}, len(val))
|
||||
func stringsToInterface(val ...string) []any {
|
||||
res := make([]any, len(val))
|
||||
for i := range val {
|
||||
res[i] = val[i]
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ func (c *Map) Match(params map[string]string) bool {
|
||||
}
|
||||
|
||||
// UnmarshalYAML unmarshal the constraint map.
|
||||
func (c *Map) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
func (c *Map) UnmarshalYAML(unmarshal func(any) error) error {
|
||||
out1 := struct {
|
||||
Include map[string]string
|
||||
Exclude map[string]string
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
type StringOrInt int64
|
||||
|
||||
// UnmarshalYAML implements the Unmarshaler interface.
|
||||
func (s *StringOrInt) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
func (s *StringOrInt) UnmarshalYAML(unmarshal func(any) error) error {
|
||||
var intType int64
|
||||
if err := unmarshal(&intType); err == nil {
|
||||
*s = StringOrInt(intType)
|
||||
@@ -50,7 +50,7 @@ func (s *StringOrInt) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
type MemStringOrInt int64
|
||||
|
||||
// UnmarshalYAML implements the Unmarshaler interface.
|
||||
func (s *MemStringOrInt) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
func (s *MemStringOrInt) UnmarshalYAML(unmarshal func(any) error) error {
|
||||
var intType int64
|
||||
if err := unmarshal(&intType); err == nil {
|
||||
*s = MemStringOrInt(intType)
|
||||
|
||||
@@ -24,8 +24,8 @@ import (
|
||||
type SliceOrMap map[string]string
|
||||
|
||||
// UnmarshalYAML implements the Unmarshaler interface.
|
||||
func (s *SliceOrMap) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
var sliceType []interface{}
|
||||
func (s *SliceOrMap) UnmarshalYAML(unmarshal func(any) error) error {
|
||||
var sliceType []any
|
||||
if err := unmarshal(&sliceType); err == nil {
|
||||
parts := map[string]string{}
|
||||
for _, s := range sliceType {
|
||||
@@ -47,7 +47,7 @@ func (s *SliceOrMap) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var mapType map[interface{}]interface{}
|
||||
var mapType map[any]any
|
||||
if err := unmarshal(&mapType); err == nil {
|
||||
parts := map[string]string{}
|
||||
for k, v := range mapType {
|
||||
|
||||
@@ -24,14 +24,14 @@ import (
|
||||
type StringOrSlice []string
|
||||
|
||||
// UnmarshalYAML implements the Unmarshaler interface.
|
||||
func (s *StringOrSlice) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
func (s *StringOrSlice) UnmarshalYAML(unmarshal func(any) error) error {
|
||||
var stringType string
|
||||
if err := unmarshal(&stringType); err == nil {
|
||||
*s = []string{stringType}
|
||||
return nil
|
||||
}
|
||||
|
||||
var sliceType []interface{}
|
||||
var sliceType []any
|
||||
if err := unmarshal(&sliceType); err == nil {
|
||||
parts, err := toStrings(sliceType)
|
||||
if err != nil {
|
||||
@@ -44,7 +44,7 @@ func (s *StringOrSlice) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
return errors.New("Failed to unmarshal StringOrSlice")
|
||||
}
|
||||
|
||||
func toStrings(s []interface{}) ([]string, error) {
|
||||
func toStrings(s []any) ([]string, error) {
|
||||
if len(s) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -33,21 +33,21 @@ type (
|
||||
|
||||
// Container defines a container.
|
||||
Container struct {
|
||||
BackendOptions BackendOptions `yaml:"backend_options,omitempty"`
|
||||
Commands base.StringOrSlice `yaml:"commands,omitempty"`
|
||||
Detached bool `yaml:"detach,omitempty"`
|
||||
Directory string `yaml:"directory,omitempty"`
|
||||
Environment base.SliceOrMap `yaml:"environment,omitempty"`
|
||||
Failure string `yaml:"failure,omitempty"`
|
||||
Group string `yaml:"group,omitempty"`
|
||||
Image string `yaml:"image,omitempty"`
|
||||
Name string `yaml:"name,omitempty"`
|
||||
Pull bool `yaml:"pull,omitempty"`
|
||||
Secrets Secrets `yaml:"secrets,omitempty"`
|
||||
Settings map[string]interface{} `yaml:"settings"`
|
||||
Volumes Volumes `yaml:"volumes,omitempty"`
|
||||
When constraint.When `yaml:"when,omitempty"`
|
||||
Ports []base.StringOrInt `yaml:"ports,omitempty"`
|
||||
BackendOptions BackendOptions `yaml:"backend_options,omitempty"`
|
||||
Commands base.StringOrSlice `yaml:"commands,omitempty"`
|
||||
Detached bool `yaml:"detach,omitempty"`
|
||||
Directory string `yaml:"directory,omitempty"`
|
||||
Environment base.SliceOrMap `yaml:"environment,omitempty"`
|
||||
Failure string `yaml:"failure,omitempty"`
|
||||
Group string `yaml:"group,omitempty"`
|
||||
Image string `yaml:"image,omitempty"`
|
||||
Name string `yaml:"name,omitempty"`
|
||||
Pull bool `yaml:"pull,omitempty"`
|
||||
Secrets Secrets `yaml:"secrets,omitempty"`
|
||||
Settings map[string]any `yaml:"settings"`
|
||||
Volumes Volumes `yaml:"volumes,omitempty"`
|
||||
When constraint.When `yaml:"when,omitempty"`
|
||||
Ports []base.StringOrInt `yaml:"ports,omitempty"`
|
||||
|
||||
// Docker Specific
|
||||
Privileged bool `yaml:"privileged,omitempty"`
|
||||
|
||||
@@ -124,7 +124,7 @@ func TestUnmarshalContainer(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Settings: map[string]interface{}{
|
||||
Settings: map[string]any{
|
||||
"foo": "bar",
|
||||
"baz": false,
|
||||
},
|
||||
@@ -159,7 +159,7 @@ func TestUnmarshalContainers(t *testing.T) {
|
||||
{
|
||||
Name: "unit_test",
|
||||
Image: "node",
|
||||
Settings: map[string]interface{}{
|
||||
Settings: map[string]any{
|
||||
"normal_setting": true,
|
||||
},
|
||||
},
|
||||
@@ -190,7 +190,7 @@ func TestUnmarshalContainers(t *testing.T) {
|
||||
Source: "docker_password",
|
||||
Target: "docker_password",
|
||||
}}},
|
||||
Settings: map[string]interface{}{
|
||||
Settings: map[string]any{
|
||||
"repo": "woodpeckerci/woodpecker-agent",
|
||||
"dockerfile": "docker/Dockerfile.agent",
|
||||
"tag": stringsToInterface("next", "latest"),
|
||||
@@ -223,7 +223,7 @@ func TestUnmarshalContainers(t *testing.T) {
|
||||
Name: "publish-cli",
|
||||
Image: "print/env",
|
||||
Group: "docker",
|
||||
Settings: map[string]interface{}{
|
||||
Settings: map[string]any{
|
||||
"repo": "woodpeckerci/woodpecker-cli",
|
||||
"dockerfile": "docker/Dockerfile.cli",
|
||||
"tag": stringsToInterface("next"),
|
||||
@@ -289,8 +289,8 @@ func TestUnmarshalContainersErr(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func stringsToInterface(val ...string) []interface{} {
|
||||
res := make([]interface{}, len(val))
|
||||
func stringsToInterface(val ...string) []any {
|
||||
res := make([]any, len(val))
|
||||
for i := range val {
|
||||
res[i] = val[i]
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ type Network struct {
|
||||
}
|
||||
|
||||
// MarshalYAML implements the Marshaller interface.
|
||||
func (n Networks) MarshalYAML() (interface{}, error) {
|
||||
func (n Networks) MarshalYAML() (any, error) {
|
||||
m := map[string]*Network{}
|
||||
for _, network := range n.Networks {
|
||||
m[network.Name] = network
|
||||
@@ -43,8 +43,8 @@ func (n Networks) MarshalYAML() (interface{}, error) {
|
||||
}
|
||||
|
||||
// UnmarshalYAML implements the Unmarshaler interface.
|
||||
func (n *Networks) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
var sliceType []interface{}
|
||||
func (n *Networks) UnmarshalYAML(unmarshal func(any) error) error {
|
||||
var sliceType []any
|
||||
if err := unmarshal(&sliceType); err == nil {
|
||||
n.Networks = []*Network{}
|
||||
for _, network := range sliceType {
|
||||
@@ -59,7 +59,7 @@ func (n *Networks) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var mapType map[interface{}]interface{}
|
||||
var mapType map[any]any
|
||||
if err := unmarshal(&mapType); err == nil {
|
||||
n.Networks = []*Network{}
|
||||
for mapKey, mapValue := range mapType {
|
||||
@@ -79,21 +79,21 @@ func (n *Networks) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
return errors.New("Failed to unmarshal Networks")
|
||||
}
|
||||
|
||||
func handleNetwork(name string, value interface{}) (*Network, error) {
|
||||
func handleNetwork(name string, value any) (*Network, error) {
|
||||
if value == nil {
|
||||
return &Network{
|
||||
Name: name,
|
||||
}, nil
|
||||
}
|
||||
switch v := value.(type) {
|
||||
case map[string]interface{}:
|
||||
case map[string]any:
|
||||
network := &Network{
|
||||
Name: name,
|
||||
}
|
||||
for mapKey, mapValue := range v {
|
||||
switch mapKey {
|
||||
case "aliases":
|
||||
aliases, ok := mapValue.([]interface{})
|
||||
aliases, ok := mapValue.([]any)
|
||||
if !ok {
|
||||
return &Network{}, fmt.Errorf("Cannot unmarshal '%v' to type %T into a string value", aliases, aliases)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func (v *Volume) String() string {
|
||||
}
|
||||
|
||||
// MarshalYAML implements the Marshaller interface.
|
||||
func (v Volumes) MarshalYAML() (interface{}, error) {
|
||||
func (v Volumes) MarshalYAML() (any, error) {
|
||||
vs := []string{}
|
||||
for _, volume := range v.Volumes {
|
||||
vs = append(vs, volume.String())
|
||||
@@ -57,8 +57,8 @@ func (v Volumes) MarshalYAML() (interface{}, error) {
|
||||
}
|
||||
|
||||
// UnmarshalYAML implements the Unmarshaler interface.
|
||||
func (v *Volumes) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
var sliceType []interface{}
|
||||
func (v *Volumes) UnmarshalYAML(unmarshal func(any) error) error {
|
||||
var sliceType []any
|
||||
if err := unmarshal(&sliceType); err == nil {
|
||||
v.Volumes = []*Volume{}
|
||||
for _, volume := range sliceType {
|
||||
|
||||
Reference in New Issue
Block a user