Skip to content

Commit

Permalink
Replace interface{} with any (#2807)
Browse files Browse the repository at this point in the history
like golang:
golang/go@2580d0e
  • Loading branch information
qwerty287 authored Nov 12, 2023
1 parent fd77b2e commit 70711ed
Show file tree
Hide file tree
Showing 35 changed files with 106 additions and 106 deletions.
2 changes: 1 addition & 1 deletion agent/rpc/auth_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (interceptor *AuthInterceptor) Unary() grpc.UnaryClientInterceptor {
return func(
ctx context.Context,
method string,
req, reply interface{},
req, reply any,
cc *grpc.ClientConn,
invoker grpc.UnaryInvoker,
opts ...grpc.CallOption,
Expand Down
4 changes: 2 additions & 2 deletions pipeline/backend/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (e *kube) WaitStep(ctx context.Context, step *types.Step, taskUUID string)

finished := make(chan bool)

podUpdated := func(old, new interface{}) {
podUpdated := func(old, new any) {
pod := new.(*v1.Pod)
if pod.Name == podName {
if isImagePullBackOffState(pod) {
Expand Down Expand Up @@ -273,7 +273,7 @@ func (e *kube) TailStep(ctx context.Context, step *types.Step, taskUUID string)

up := make(chan bool)

podUpdated := func(old, new interface{}) {
podUpdated := func(old, new any) {
pod := new.(*v1.Pod)
if pod.Name == podName {
switch pod.Status.Phase {
Expand Down
2 changes: 1 addition & 1 deletion pipeline/errors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type PipelineError struct {
Type PipelineErrorType `json:"type"`
Message string `json:"message"`
IsWarning bool `json:"is_warning"`
Data interface{} `json:"data"`
Data any `json:"data"`
}

type LinterErrorData struct {
Expand Down
8 changes: 4 additions & 4 deletions pipeline/frontend/yaml/compiler/cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pipeline/frontend/yaml/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
16 changes: 8 additions & 8 deletions pipeline/frontend/yaml/compiler/settings/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)

Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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()) {
Expand All @@ -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 {
Expand All @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions pipeline/frontend/yaml/compiler/settings/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]",
"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",
Expand All @@ -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)
}

Expand Down Expand Up @@ -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)

Expand All @@ -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{
Expand All @@ -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]
}
Expand Down
2 changes: 1 addition & 1 deletion pipeline/frontend/yaml/constraint/constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pipeline/frontend/yaml/types/base/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions pipeline/frontend/yaml/types/base/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions pipeline/frontend/yaml/types/base/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
30 changes: 15 additions & 15 deletions pipeline/frontend/yaml/types/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
12 changes: 6 additions & 6 deletions pipeline/frontend/yaml/types/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func TestUnmarshalContainer(t *testing.T) {
},
},
},
Settings: map[string]interface{}{
Settings: map[string]any{
"foo": "bar",
"baz": false,
},
Expand Down Expand Up @@ -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,
},
},
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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]
}
Expand Down
Loading

0 comments on commit 70711ed

Please sign in to comment.