From d9252d122ebf8fbc7a4ac11d6def917ece682a6c Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Thu, 23 Jul 2026 23:26:44 -0400 Subject: [PATCH] refactor: replace interface{} with any Modernize Go type declarations by using the equivalent `any` alias throughout the SDK. Reports type declarations that use interface{} and can be simplified by using `any` since `any` is an alias for `interface{}`. Signed-off-by: Ryan Johnson --- acctest/pluginacc.go | 2 +- adapter/scp.go | 4 +- bootcommand/boot_command_ast.go | 2 +- chroot/communicator_test.go | 2 +- chroot/step_copy_files_test.go | 2 +- chroot/step_mount_extra_test.go | 2 +- .../internal/fix/testdata/fixed/basic/go.sum | 3 ++ .../fix/testdata/missing-requires/both/go.sum | 11 ++++ .../testdata/missing-requires/go-cty/go.mod | 16 +++--- .../testdata/missing-requires/go-cty/go.sum | 13 +++++ .../missing-requires/packer-plugin-sdk/go.mod | 2 +- .../missing-requires/packer-plugin-sdk/go.sum | 12 +++++ .../fix/testdata/unfixed/basic/go.sum | 23 ++++++++ .../fix/testdata/unfixed/version/go.sum | 23 ++++++++ .../mapstructure-to-hcl2.go | 2 +- communicator/config.go | 4 +- communicator/sshkey/generate.go | 2 +- guestexec/elevated_test.go | 6 +-- hcl2helper/values.go | 12 ++--- hcl2helper/values_test.go | 14 ++--- json/unmarshal.go | 2 +- multistep/basic_runner_test.go | 2 +- multistep/commonsteps/multistep_runner.go | 2 +- .../commonsteps/step_create_cdrom_test.go | 2 +- .../commonsteps/step_create_floppy_test.go | 2 +- .../commonsteps/step_http_server_test.go | 2 +- multistep/commonsteps/step_provision.go | 6 +-- multistep/commonsteps/step_provision_test.go | 4 +- multistep/debug_runner_test.go | 2 +- multistep/statebag.go | 16 +++--- multistep/statebag_test.go | 2 +- packer/artifact.go | 2 +- packer/artifact_mock.go | 4 +- packer/artifact_test.go | 4 +- packer/builder.go | 2 +- packer/builder_mock.go | 6 +-- packer/builder_mock.hcl2spec.go | 22 ++++---- packer/communicator.go | 6 +-- packer/communicator_mock_test.go | 2 +- packer/datasource.go | 2 +- packer/datasource_mock.go | 10 ++-- packer/hook.go | 4 +- packer/hook_mock.go | 4 +- packer/hook_test.go | 2 +- packer/multi_error_test.go | 2 +- packer/post_processor.go | 2 +- packer/provisioner.go | 4 +- packer/provisioner_mock.go | 8 +-- packer/provisioner_mock.hcl2spec.go | 12 ++--- .../image/fromartifact_example_test.go | 4 +- .../image/frommappeddata_example_test.go | 4 +- packer/registry/image/image.go | 4 +- packer/registry/image/image_test.go | 6 +-- packerbuilderdata/generated_data.go | 6 +-- packerbuilderdata/generated_data_test.go | 2 +- retry/utils_test.go | 4 +- rpc/artifact.go | 24 ++++----- rpc/build.go | 28 +++++----- rpc/build_test.go | 2 +- rpc/builder.go | 10 ++-- rpc/builder_test.go | 2 +- rpc/common.go | 4 +- rpc/communicator.go | 12 ++--- rpc/communicator_test.go | 2 +- rpc/cty_encode.go | 4 +- rpc/datasource.go | 12 ++--- rpc/datasource_test.go | 8 +-- rpc/fileinfo.go | 4 +- rpc/fileinfo_test.go | 4 +- rpc/hook.go | 14 ++--- rpc/init.go | 2 +- rpc/post_processor.go | 14 ++--- rpc/post_processor_test.go | 8 +-- rpc/provisioner.go | 22 ++++---- rpc/provisioner_test.go | 4 +- rpc/ui.go | 18 +++---- rpc/ui_progress_tracking.go | 8 +-- .../communicator/none/communicator_test.go | 2 +- .../communicator/ssh/communicator_test.go | 2 +- .../communicator/ssh/password_test.go | 2 +- shell-local/config.go | 4 +- shell-local/run.go | 4 +- template/config/decode.go | 16 +++--- template/config/decode_test.go | 52 +++++++++--------- template/funcs.go | 2 +- .../aws/secretsmanager/secretsmanager.go | 4 +- template/interpolate/funcs.go | 54 +++++++++---------- template/interpolate/funcs_test.go | 12 ++--- template/interpolate/i.go | 6 +-- template/interpolate/render.go | 12 ++--- template/interpolate/render_test.go | 36 ++++++------- template/parse.go | 50 ++++++++--------- template/parse_test.go | 26 ++++----- template/template.go | 28 +++++----- template/template.hcl2spec.go | 16 +++--- 95 files changed, 473 insertions(+), 388 deletions(-) create mode 100644 cmd/packer-sdc/internal/fix/testdata/fixed/basic/go.sum create mode 100644 cmd/packer-sdc/internal/fix/testdata/missing-requires/both/go.sum create mode 100644 cmd/packer-sdc/internal/fix/testdata/missing-requires/go-cty/go.sum create mode 100644 cmd/packer-sdc/internal/fix/testdata/missing-requires/packer-plugin-sdk/go.sum create mode 100644 cmd/packer-sdc/internal/fix/testdata/unfixed/basic/go.sum create mode 100644 cmd/packer-sdc/internal/fix/testdata/unfixed/version/go.sum diff --git a/acctest/pluginacc.go b/acctest/pluginacc.go index 30379dfb0..9c050df4f 100644 --- a/acctest/pluginacc.go +++ b/acctest/pluginacc.go @@ -77,7 +77,7 @@ func TestPlugin(t *testing.T, testCase *PluginTestCase) { logfile := fmt.Sprintf("packer_log_%s.txt", testCase.Name) extension := ".pkr.hcl" - if err := json.Unmarshal([]byte(testCase.Template), &(map[string]interface{}{})); err == nil { + if err := json.Unmarshal([]byte(testCase.Template), &(map[string]any{})); err == nil { extension = ".json" } templatePath := fmt.Sprintf("./%s%s", testCase.Name, extension) diff --git a/adapter/scp.go b/adapter/scp.go index 0a8704cef..12341b624 100644 --- a/adapter/scp.go +++ b/adapter/scp.go @@ -350,5 +350,5 @@ func (fi fileInfo) ModTime() time.Time { } return fi.mtime } -func (fi fileInfo) IsDir() bool { return fi.mode.IsDir() } -func (fi fileInfo) Sys() interface{} { return nil } +func (fi fileInfo) IsDir() bool { return fi.mode.IsDir() } +func (fi fileInfo) Sys() any { return nil } diff --git a/bootcommand/boot_command_ast.go b/bootcommand/boot_command_ast.go index 00b04b13e..dbfb88278 100644 --- a/bootcommand/boot_command_ast.go +++ b/bootcommand/boot_command_ast.go @@ -86,7 +86,7 @@ func GenerateExpressionSequence(command string) (expressionSequence, error) { if err != nil { return nil, err } - for _, exp := range got.([]interface{}) { + for _, exp := range got.([]any) { seq = append(seq, exp.(expression)) } return seq, nil diff --git a/chroot/communicator_test.go b/chroot/communicator_test.go index 4ac54f2b3..7ab838d77 100644 --- a/chroot/communicator_test.go +++ b/chroot/communicator_test.go @@ -10,7 +10,7 @@ import ( ) func TestCommunicator_ImplementsCommunicator(t *testing.T) { - var raw interface{} = &Communicator{} + var raw any = &Communicator{} if _, ok := raw.(packersdk.Communicator); !ok { t.Fatalf("Communicator should be a communicator") diff --git a/chroot/step_copy_files_test.go b/chroot/step_copy_files_test.go index 3a674245c..4645d64af 100644 --- a/chroot/step_copy_files_test.go +++ b/chroot/step_copy_files_test.go @@ -30,7 +30,7 @@ func testUI() (packersdk.Ui, func() string) { } func TestCopyFilesCleanupFunc_ImplementsCleanupFunc(t *testing.T) { - var raw interface{} = new(StepCopyFiles) + var raw any = new(StepCopyFiles) if _, ok := raw.(Cleanup); !ok { t.Fatalf("cleanup func should be a CleanupFunc") } diff --git a/chroot/step_mount_extra_test.go b/chroot/step_mount_extra_test.go index 488e60de7..6a0c48b60 100644 --- a/chroot/step_mount_extra_test.go +++ b/chroot/step_mount_extra_test.go @@ -6,7 +6,7 @@ package chroot import "testing" func TestMountExtraCleanupFunc_ImplementsCleanupFunc(t *testing.T) { - var raw interface{} = new(StepMountExtra) + var raw any = new(StepMountExtra) if _, ok := raw.(Cleanup); !ok { t.Fatalf("cleanup func should be a CleanupFunc") } diff --git a/cmd/packer-sdc/internal/fix/testdata/fixed/basic/go.sum b/cmd/packer-sdc/internal/fix/testdata/fixed/basic/go.sum new file mode 100644 index 000000000..79f23ee85 --- /dev/null +++ b/cmd/packer-sdc/internal/fix/testdata/fixed/basic/go.sum @@ -0,0 +1,3 @@ +github.com/hashicorp/hcl/v2 v2.13.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0= +github.com/hashicorp/packer-plugin-sdk v0.3.1/go.mod h1:+GzydiXdn0CkueigqXBsX4Poz5gfmFXZ/DkxKt4fmt4= +github.com/nywilken/go-cty v1.13.3/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0= diff --git a/cmd/packer-sdc/internal/fix/testdata/missing-requires/both/go.sum b/cmd/packer-sdc/internal/fix/testdata/missing-requires/both/go.sum new file mode 100644 index 000000000..ae1b83fa1 --- /dev/null +++ b/cmd/packer-sdc/internal/fix/testdata/missing-requires/both/go.sum @@ -0,0 +1,11 @@ +github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= +github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I= +github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/klauspost/compress v1.11.2/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= diff --git a/cmd/packer-sdc/internal/fix/testdata/missing-requires/go-cty/go.mod b/cmd/packer-sdc/internal/fix/testdata/missing-requires/go-cty/go.mod index ad38b4bd0..f14cabb48 100644 --- a/cmd/packer-sdc/internal/fix/testdata/missing-requires/go-cty/go.mod +++ b/cmd/packer-sdc/internal/fix/testdata/missing-requires/go-cty/go.mod @@ -2,18 +2,18 @@ module example require ( github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d - github.com/google/go-cmp v0.3.0 - github.com/hashicorp/go-cleanhttp v0.5.0 - github.com/hashicorp/go-multierror v1.1.0 + github.com/google/go-cmp v0.5.9 + github.com/hashicorp/go-cleanhttp v0.5.2 + github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/go-safetemp v1.0.0 - github.com/hashicorp/go-version v1.1.0 + github.com/hashicorp/go-version v1.6.0 github.com/hashicorp/packer-plugin-sdk v0.4.0 github.com/klauspost/compress v1.11.2 - github.com/mitchellh/go-homedir v1.0.0 - github.com/mitchellh/go-testing-interface v1.0.0 - github.com/ulikunitz/xz v0.5.8 + github.com/mitchellh/go-homedir v1.1.0 + github.com/mitchellh/go-testing-interface v1.14.1 + github.com/ulikunitz/xz v0.5.10 ) -require github.com/hashicorp/errwrap v1.0.0 // indirect +require github.com/hashicorp/errwrap v1.1.0 // indirect go 1.18 diff --git a/cmd/packer-sdc/internal/fix/testdata/missing-requires/go-cty/go.sum b/cmd/packer-sdc/internal/fix/testdata/missing-requires/go-cty/go.sum new file mode 100644 index 000000000..8bdd40d5d --- /dev/null +++ b/cmd/packer-sdc/internal/fix/testdata/missing-requires/go-cty/go.sum @@ -0,0 +1,13 @@ +github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= +github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I= +github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/packer-plugin-sdk v0.4.0/go.mod h1:uNhU3pmjM2ejgHYce/g4J+sa5rh81iYQztpGvGa5FOs= +github.com/klauspost/compress v1.11.2/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= +github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= diff --git a/cmd/packer-sdc/internal/fix/testdata/missing-requires/packer-plugin-sdk/go.mod b/cmd/packer-sdc/internal/fix/testdata/missing-requires/packer-plugin-sdk/go.mod index aace57136..8487eddf8 100644 --- a/cmd/packer-sdc/internal/fix/testdata/missing-requires/packer-plugin-sdk/go.mod +++ b/cmd/packer-sdc/internal/fix/testdata/missing-requires/packer-plugin-sdk/go.mod @@ -2,7 +2,7 @@ module example require ( github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d - github.com/google/go-cmp v0.3.0 + github.com/google/go-cmp v0.3.1 github.com/hashicorp/go-cleanhttp v0.5.0 github.com/hashicorp/go-multierror v1.1.0 github.com/hashicorp/go-safetemp v1.0.0 diff --git a/cmd/packer-sdc/internal/fix/testdata/missing-requires/packer-plugin-sdk/go.sum b/cmd/packer-sdc/internal/fix/testdata/missing-requires/packer-plugin-sdk/go.sum new file mode 100644 index 000000000..66d80f15e --- /dev/null +++ b/cmd/packer-sdc/internal/fix/testdata/missing-requires/packer-plugin-sdk/go.sum @@ -0,0 +1,12 @@ +github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= +github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I= +github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/klauspost/compress v1.11.2/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= +github.com/zclconf/go-cty v1.13.1/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0= diff --git a/cmd/packer-sdc/internal/fix/testdata/unfixed/basic/go.sum b/cmd/packer-sdc/internal/fix/testdata/unfixed/basic/go.sum new file mode 100644 index 000000000..a950ff20c --- /dev/null +++ b/cmd/packer-sdc/internal/fix/testdata/unfixed/basic/go.sum @@ -0,0 +1,23 @@ +github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/hashicorp/hcl/v2 v2.13.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0= +github.com/hashicorp/packer-plugin-sdk v0.3.1/go.mod h1:+GzydiXdn0CkueigqXBsX4Poz5gfmFXZ/DkxKt4fmt4= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= +github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= +github.com/zclconf/go-cty v1.10.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/cmd/packer-sdc/internal/fix/testdata/unfixed/version/go.sum b/cmd/packer-sdc/internal/fix/testdata/unfixed/version/go.sum new file mode 100644 index 000000000..8c1099692 --- /dev/null +++ b/cmd/packer-sdc/internal/fix/testdata/unfixed/version/go.sum @@ -0,0 +1,23 @@ +github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/hashicorp/hcl/v2 v2.13.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0= +github.com/hashicorp/packer-plugin-sdk v0.3.1/go.mod h1:+GzydiXdn0CkueigqXBsX4Poz5gfmFXZ/DkxKt4fmt4= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/nywilken/go-cty v1.12.1/go.mod h1:jQhMnBcOB2DrBaV2awY4z+oSZTPc2dnnwGqYqFo86G0= +github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= +github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/cmd/packer-sdc/internal/mapstructure-to-hcl2/mapstructure-to-hcl2.go b/cmd/packer-sdc/internal/mapstructure-to-hcl2/mapstructure-to-hcl2.go index 6b560a728..3f417a868 100644 --- a/cmd/packer-sdc/internal/mapstructure-to-hcl2/mapstructure-to-hcl2.go +++ b/cmd/packer-sdc/internal/mapstructure-to-hcl2/mapstructure-to-hcl2.go @@ -290,7 +290,7 @@ func outputHCL2SpecField(w io.Writer, accessor string, fieldType types.Type, tag // a cty.Type or a string. The second argument is used for recursion and is the // type that will be used by the parent. For example when fieldType is a []string; a // recursive goFieldToCtyType call will return a cty.String. -func goFieldToCtyType(accessor string, fieldType types.Type) (interface{}, cty.Type) { +func goFieldToCtyType(accessor string, fieldType types.Type) (any, cty.Type) { switch f := fieldType.(type) { case *types.Pointer: return goFieldToCtyType(accessor, f.Elem()) diff --git a/communicator/config.go b/communicator/config.go index 750f855f4..9b0124b58 100644 --- a/communicator/config.go +++ b/communicator/config.go @@ -279,13 +279,13 @@ func (c *SSH) ConfigSpec() hcldec.ObjectSpec { return c.FlatMapstructure().HCL2S func (c *WinRM) ConfigSpec() hcldec.ObjectSpec { return c.FlatMapstructure().HCL2Spec() } // Configure parses the json template into the Config structs -func (c *SSH) Configure(raws ...interface{}) ([]string, error) { +func (c *SSH) Configure(raws ...any) ([]string, error) { err := config.Decode(c, nil, raws...) return nil, err } // Configure parses the json template into the Config structs -func (c *WinRM) Configure(raws ...interface{}) ([]string, error) { +func (c *WinRM) Configure(raws ...any) ([]string, error) { err := config.Decode(c, nil, raws...) return nil, err } diff --git a/communicator/sshkey/generate.go b/communicator/sshkey/generate.go index 901117bd4..71b80a412 100644 --- a/communicator/sshkey/generate.go +++ b/communicator/sshkey/generate.go @@ -43,7 +43,7 @@ type Pair struct { Public []byte } -func NewPair(public, private interface{}) (*Pair, error) { +func NewPair(public, private any) (*Pair, error) { kb, err := x509.MarshalPKCS8PrivateKey(private) if err != nil { return nil, err diff --git a/guestexec/elevated_test.go b/guestexec/elevated_test.go index 75c52308a..c836d435b 100644 --- a/guestexec/elevated_test.go +++ b/guestexec/elevated_test.go @@ -10,9 +10,9 @@ import ( packersdk "github.com/hashicorp/packer-plugin-sdk/packer" ) -func testConfig() map[string]interface{} { - return map[string]interface{}{ - "inline": []interface{}{"foo", "bar"}, +func testConfig() map[string]any { + return map[string]any{ + "inline": []any{"foo", "bar"}, } } diff --git a/hcl2helper/values.go b/hcl2helper/values.go index 540682349..0c811fce2 100644 --- a/hcl2helper/values.go +++ b/hcl2helper/values.go @@ -22,7 +22,7 @@ const UnknownVariableValue = "74D93920-ED26-11E3-AC10-0800200C9A66" // HCL2ValueFromConfigValue takes a value turns it into // a cty.Value so it can be used within, for example, an HCL2 EvalContext. -func HCL2ValueFromConfigValue(v interface{}) cty.Value { +func HCL2ValueFromConfigValue(v any) cty.Value { if v == nil { return cty.NullVal(cty.DynamicPseudoType) } @@ -39,7 +39,7 @@ func HCL2ValueFromConfigValue(v interface{}) cty.Value { return cty.NumberIntVal(int64(tv)) case float64: return cty.NumberFloatVal(tv) - case []interface{}: + case []any: vals := make([]cty.Value, len(tv)) for i, ev := range tv { vals[i] = HCL2ValueFromConfigValue(ev) @@ -51,7 +51,7 @@ func HCL2ValueFromConfigValue(v interface{}) cty.Value { vals[i] = cty.StringVal(ev) } return cty.ListVal(vals) - case map[string]interface{}: + case map[string]any: vals := map[string]cty.Value{} for k, ev := range tv { vals[k] = HCL2ValueFromConfigValue(ev) @@ -66,8 +66,8 @@ func HCL2ValueFromConfigValue(v interface{}) cty.Value { // HCL2ValueFromConfig takes a struct with it's map of hcldec.Spec, and turns it into // a cty.Value so it can be used as, for example, a Datasource value. -func HCL2ValueFromConfig(conf interface{}, configSpec map[string]hcldec.Spec) cty.Value { - c := map[string]interface{}{} +func HCL2ValueFromConfig(conf any, configSpec map[string]hcldec.Spec) cty.Value { + c := map[string]any{} if err := mapstructure.Decode(conf, &c); err != nil { panic(fmt.Errorf("can't convert %#v to cty.Value", conf)) } @@ -102,7 +102,7 @@ If this doesn't fix your problem, this is likely a Packer bug, please consider o // This should be a slice of objects, so we need to take a special care if hcldec.ImpliedType(st.Nested).IsObjectType() { res := []cty.Value{} - c := []interface{}{} + c := []any{} if err := mapstructure.Decode(v, &c); err != nil { panic(fmt.Errorf("can't convert %#v to cty.Value", conf)) } diff --git a/hcl2helper/values_test.go b/hcl2helper/values_test.go index c49ede9d0..e42e4fe65 100644 --- a/hcl2helper/values_test.go +++ b/hcl2helper/values_test.go @@ -16,7 +16,7 @@ import ( func TestHCL2ValueFromConfigValue(t *testing.T) { tests := []struct { Name string - Input interface{} + Input any Want cty.Value }{ { @@ -46,11 +46,11 @@ func TestHCL2ValueFromConfigValue(t *testing.T) { }, { Name: "nested map[string]interface{}", - Input: map[string]interface{}{ + Input: map[string]any{ "name": "Ermintrude", "age": int(19), - "address": map[string]interface{}{ - "street": []interface{}{"421 Shoreham Loop"}, + "address": map[string]any{ + "street": []any{"421 Shoreham Loop"}, "city": "Fridgewater", "state": "MA", "zip": "91037", @@ -69,7 +69,7 @@ func TestHCL2ValueFromConfigValue(t *testing.T) { }, { Name: "simple map[string]interface{}", - Input: map[string]interface{}{ + Input: map[string]any{ "foo": "bar", "bar": "baz", }, @@ -80,7 +80,7 @@ func TestHCL2ValueFromConfigValue(t *testing.T) { }, { Name: "[]interface{} as tuple", - Input: []interface{}{ + Input: []any{ "foo", true, }, @@ -127,7 +127,7 @@ func TestHCL2ValueFromConfigValue(t *testing.T) { func TestHCL2ValueFromConfig(t *testing.T) { tests := []struct { Name string - Input interface{} + Input any Spec map[string]hcldec.Spec Want cty.Value }{ diff --git a/json/unmarshal.go b/json/unmarshal.go index 02961402f..bc2ca4ca1 100644 --- a/json/unmarshal.go +++ b/json/unmarshal.go @@ -11,7 +11,7 @@ import ( // Unmarshal is wrapper around json.Unmarshal that returns user-friendly // errors when there are syntax errors. -func Unmarshal(data []byte, i interface{}) error { +func Unmarshal(data []byte, i any) error { err := json.Unmarshal(data, i) if err != nil { syntaxErr, ok := err.(*json.SyntaxError) diff --git a/multistep/basic_runner_test.go b/multistep/basic_runner_test.go index 321d58791..607fd7857 100644 --- a/multistep/basic_runner_test.go +++ b/multistep/basic_runner_test.go @@ -10,7 +10,7 @@ import ( ) func TestBasicRunner_ImplRunner(t *testing.T) { - var raw interface{} = &BasicRunner{} + var raw any = &BasicRunner{} if _, ok := raw.(Runner); !ok { t.Fatalf("BasicRunner must be a Runner") } diff --git a/multistep/commonsteps/multistep_runner.go b/multistep/commonsteps/multistep_runner.go index 1a405eee0..67333b59e 100644 --- a/multistep/commonsteps/multistep_runner.go +++ b/multistep/commonsteps/multistep_runner.go @@ -68,7 +68,7 @@ func NewRunnerWithPauseFn(steps []multistep.Step, config common.PackerConfig, ui return runner } -func typeName(i interface{}) string { +func typeName(i any) string { return reflect.Indirect(reflect.ValueOf(i)).Type().Name() } diff --git a/multistep/commonsteps/step_create_cdrom_test.go b/multistep/commonsteps/step_create_cdrom_test.go index 9eced658a..a582c8d07 100644 --- a/multistep/commonsteps/step_create_cdrom_test.go +++ b/multistep/commonsteps/step_create_cdrom_test.go @@ -16,7 +16,7 @@ import ( ) func TestStepCreateCD_Impl(t *testing.T) { - var raw interface{} = new(StepCreateCD) + var raw any = new(StepCreateCD) if _, ok := raw.(multistep.Step); !ok { t.Fatalf("StepCreateCD should be a step") } diff --git a/multistep/commonsteps/step_create_floppy_test.go b/multistep/commonsteps/step_create_floppy_test.go index 8f03f27ca..9b395fa39 100644 --- a/multistep/commonsteps/step_create_floppy_test.go +++ b/multistep/commonsteps/step_create_floppy_test.go @@ -21,7 +21,7 @@ import ( const TestFixtures = "test-fixtures" func TestStepCreateFloppy_Impl(t *testing.T) { - var raw interface{} = new(StepCreateFloppy) + var raw any = new(StepCreateFloppy) if _, ok := raw.(multistep.Step); !ok { t.Fatalf("StepCreateFloppy should be a step") } diff --git a/multistep/commonsteps/step_http_server_test.go b/multistep/commonsteps/step_http_server_test.go index 519fae71e..88e2cd5f3 100644 --- a/multistep/commonsteps/step_http_server_test.go +++ b/multistep/commonsteps/step_http_server_test.go @@ -20,7 +20,7 @@ func TestStepHTTPServer_Run(t *testing.T) { tests := []struct { cfg *HTTPConfig want multistep.StepAction - wantPort interface{} + wantPort any wantContent map[string]string }{ { diff --git a/multistep/commonsteps/step_provision.go b/multistep/commonsteps/step_provision.go index 21f9d36d3..87c822558 100644 --- a/multistep/commonsteps/step_provision.go +++ b/multistep/commonsteps/step_provision.go @@ -30,13 +30,13 @@ const HttpIPNotImplemented = "ERR_HTTP_IP_NOT_IMPLEMENTED_BY_BUILDER" const HttpPortNotImplemented = "ERR_HTTP_PORT_NOT_IMPLEMENTED_BY_BUILDER" const HttpAddrNotImplemented = "ERR_HTTP_ADDR_NOT_IMPLEMENTED_BY_BUILDER" -func PopulateProvisionHookData(state multistep.StateBag) map[string]interface{} { - hookData := make(map[string]interface{}) +func PopulateProvisionHookData(state multistep.StateBag) map[string]any { + hookData := make(map[string]any) // Load Builder hook data from state, if it has been set. hd, ok := state.GetOk("generated_data") if ok { - hookData = hd.(map[string]interface{}) + hookData = hd.(map[string]any) } // Warn user that the id isn't implemented diff --git a/multistep/commonsteps/step_provision_test.go b/multistep/commonsteps/step_provision_test.go index ab6e61d56..097996c28 100644 --- a/multistep/commonsteps/step_provision_test.go +++ b/multistep/commonsteps/step_provision_test.go @@ -30,7 +30,7 @@ func testCommConfig() *communicator.Config { } func TestStepProvision_Impl(t *testing.T) { - var raw interface{} = new(StepProvision) + var raw any = new(StepProvision) if _, ok := raw.(multistep.Step); !ok { t.Fatalf("provision should be a step") } @@ -39,7 +39,7 @@ func TestStepProvision_Impl(t *testing.T) { func TestPopulateProvisionHookData(t *testing.T) { state := testState(t) commConfig := testCommConfig() - generatedData := map[string]interface{}{"Data": "generated"} + generatedData := map[string]any{"Data": "generated"} instanceId := 11111 packerRunUUID := "1fa225b8-27d1-42d1-9117-221772213962" httpIP := "10.0.2.2" diff --git a/multistep/debug_runner_test.go b/multistep/debug_runner_test.go index 0b6c71662..de9a87d92 100644 --- a/multistep/debug_runner_test.go +++ b/multistep/debug_runner_test.go @@ -12,7 +12,7 @@ import ( ) func TestDebugRunner_Impl(t *testing.T) { - var raw interface{} = &DebugRunner{} + var raw any = &DebugRunner{} if _, ok := raw.(Runner); !ok { t.Fatal("DebugRunner must be a runner.") } diff --git a/multistep/statebag.go b/multistep/statebag.go index 0dd862678..5f5c78b7e 100644 --- a/multistep/statebag.go +++ b/multistep/statebag.go @@ -10,26 +10,26 @@ import "sync" // StateBag holds the state that is used by the Runner and Steps. The // StateBag implementation must be safe for concurrent access. type StateBag interface { - Get(string) interface{} - GetOk(string) (interface{}, bool) - Put(string, interface{}) + Get(string) any + GetOk(string) (any, bool) + Put(string, any) Remove(string) } // BasicStateBag implements StateBag by using a normal map underneath // protected by a RWMutex. type BasicStateBag struct { - data map[string]interface{} + data map[string]any l sync.RWMutex once sync.Once } -func (b *BasicStateBag) Get(k string) interface{} { +func (b *BasicStateBag) Get(k string) any { result, _ := b.GetOk(k) return result } -func (b *BasicStateBag) GetOk(k string) (interface{}, bool) { +func (b *BasicStateBag) GetOk(k string) (any, bool) { b.l.RLock() defer b.l.RUnlock() @@ -37,13 +37,13 @@ func (b *BasicStateBag) GetOk(k string) (interface{}, bool) { return result, ok } -func (b *BasicStateBag) Put(k string, v interface{}) { +func (b *BasicStateBag) Put(k string, v any) { b.l.Lock() defer b.l.Unlock() // Make sure the map is initialized one time, on write b.once.Do(func() { - b.data = make(map[string]interface{}) + b.data = make(map[string]any) }) // Write the data diff --git a/multistep/statebag_test.go b/multistep/statebag_test.go index 31a7d4459..ac42e0ea7 100644 --- a/multistep/statebag_test.go +++ b/multistep/statebag_test.go @@ -8,7 +8,7 @@ import ( ) func TestBasicStateBag_ImplRunner(t *testing.T) { - var raw interface{} = &BasicStateBag{} + var raw any = &BasicStateBag{} if _, ok := raw.(StateBag); !ok { t.Fatalf("must be a StateBag") } diff --git a/packer/artifact.go b/packer/artifact.go index 6835e2d0f..d58f742cf 100644 --- a/packer/artifact.go +++ b/packer/artifact.go @@ -30,7 +30,7 @@ type Artifact interface { // State allows the caller to ask for builder specific state information // relating to the artifact instance. - State(name string) interface{} + State(name string) any // Destroy deletes the artifact. Packer calls this for various reasons, // such as if a post-processor has processed this artifact and it is diff --git a/packer/artifact_mock.go b/packer/artifact_mock.go index bc7a63370..5cc8023f2 100644 --- a/packer/artifact_mock.go +++ b/packer/artifact_mock.go @@ -8,7 +8,7 @@ type MockArtifact struct { BuilderIdValue string FilesValue []string IdValue string - StateValues map[string]interface{} + StateValues map[string]any DestroyCalled bool StringValue string } @@ -46,7 +46,7 @@ func (a *MockArtifact) String() string { return str } -func (a *MockArtifact) State(name string) interface{} { +func (a *MockArtifact) State(name string) any { value := a.StateValues[name] return value } diff --git a/packer/artifact_test.go b/packer/artifact_test.go index e12e851e2..c0df19dd4 100644 --- a/packer/artifact_test.go +++ b/packer/artifact_test.go @@ -5,7 +5,7 @@ package packer type TestArtifact struct { id string - state map[string]interface{} + state map[string]any destroyCalled bool } @@ -30,7 +30,7 @@ func (*TestArtifact) String() string { return "string" } -func (a *TestArtifact) State(name string) interface{} { +func (a *TestArtifact) State(name string) any { value := a.state[name] return value } diff --git a/packer/builder.go b/packer/builder.go index 18e70543f..628281f4c 100644 --- a/packer/builder.go +++ b/packer/builder.go @@ -35,7 +35,7 @@ type Builder interface { // Prepare should return a list of variables that will be made accessible to // users during the provision methods, a list of warnings along with any // errors that occurred while preparing. - Prepare(...interface{}) ([]string, []string, error) + Prepare(...any) ([]string, []string, error) // Run is where the actual build should take place. It takes a Build and a Ui. Run(context.Context, Ui, Hook) (Artifact, error) diff --git a/packer/builder_mock.go b/packer/builder_mock.go index 9d9fc22fe..1b5114e3b 100644 --- a/packer/builder_mock.go +++ b/packer/builder_mock.go @@ -22,7 +22,7 @@ type MockBuilder struct { RunNilResult bool PrepareCalled bool - PrepareConfig []interface{} + PrepareConfig []any RunCalled bool RunHook Hook RunUi Ui @@ -34,9 +34,9 @@ type MockBuilder struct { func (tb *MockBuilder) ConfigSpec() hcldec.ObjectSpec { return tb.FlatMapstructure().HCL2Spec() } -func (tb *MockBuilder) FlatConfig() interface{} { return tb.FlatMapstructure() } +func (tb *MockBuilder) FlatConfig() any { return tb.FlatMapstructure() } -func (tb *MockBuilder) Prepare(config ...interface{}) ([]string, []string, error) { +func (tb *MockBuilder) Prepare(config ...any) ([]string, []string, error) { tb.PrepareCalled = true tb.PrepareConfig = config return tb.GeneratedVars, tb.PrepareWarnings, nil diff --git a/packer/builder_mock.hcl2spec.go b/packer/builder_mock.hcl2spec.go index 1166ebfd3..a58f302e0 100644 --- a/packer/builder_mock.hcl2spec.go +++ b/packer/builder_mock.hcl2spec.go @@ -10,17 +10,17 @@ import ( // FlatMockBuilder is an auto-generated flat version of MockBuilder. // Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. type FlatMockBuilder struct { - ArtifactId *string `cty:"artifact_id" hcl:"artifact_id"` - PrepareWarnings []string `cty:"prepare_warnings" hcl:"prepare_warnings"` - RunErrResult *bool `cty:"run_err_result" hcl:"run_err_result"` - RunNilResult *bool `cty:"run_nil_result" hcl:"run_nil_result"` - PrepareCalled *bool `cty:"prepare_called" hcl:"prepare_called"` - PrepareConfig []interface{} `cty:"prepare_config" hcl:"prepare_config"` - RunCalled *bool `cty:"run_called" hcl:"run_called"` - RunHook Hook `cty:"run_hook" hcl:"run_hook"` - RunUi Ui `cty:"run_ui" hcl:"run_ui"` - CancelCalled *bool `cty:"cancel_called" hcl:"cancel_called"` - GeneratedVars []string `cty:"generated_vars" hcl:"generated_vars"` + ArtifactId *string `cty:"artifact_id" hcl:"artifact_id"` + PrepareWarnings []string `cty:"prepare_warnings" hcl:"prepare_warnings"` + RunErrResult *bool `cty:"run_err_result" hcl:"run_err_result"` + RunNilResult *bool `cty:"run_nil_result" hcl:"run_nil_result"` + PrepareCalled *bool `cty:"prepare_called" hcl:"prepare_called"` + PrepareConfig []any `cty:"prepare_config" hcl:"prepare_config"` + RunCalled *bool `cty:"run_called" hcl:"run_called"` + RunHook Hook `cty:"run_hook" hcl:"run_hook"` + RunUi Ui `cty:"run_ui" hcl:"run_ui"` + CancelCalled *bool `cty:"cancel_called" hcl:"cancel_called"` + GeneratedVars []string `cty:"generated_vars" hcl:"generated_vars"` } // FlatMapstructure returns a new FlatMockBuilder. diff --git a/packer/communicator.go b/packer/communicator.go index 8e42a48c8..2eba29bd5 100644 --- a/packer/communicator.go +++ b/packer/communicator.go @@ -43,7 +43,7 @@ type RemoteCmd struct { m sync.Mutex exitChInit sync.Once - exitCh chan interface{} + exitCh chan any } // A Communicator is the interface used to communicate with the machine @@ -85,7 +85,7 @@ type Communicator interface { type ConfigurableCommunicator interface { HCL2Speccer - Configure(...interface{}) ([]string, error) + Configure(...any) ([]string, error) } // RunWithUi runs the remote command and streams the output to any configured @@ -215,7 +215,7 @@ func (r *RemoteCmd) ExitStatus() int { func (r *RemoteCmd) initchan() { r.exitChInit.Do(func() { if r.exitCh == nil { - r.exitCh = make(chan interface{}) + r.exitCh = make(chan any) } }) } diff --git a/packer/communicator_mock_test.go b/packer/communicator_mock_test.go index 3e6d79df6..d36a18ee4 100644 --- a/packer/communicator_mock_test.go +++ b/packer/communicator_mock_test.go @@ -8,7 +8,7 @@ import ( ) func TestMockCommunicator_impl(t *testing.T) { - var raw interface{} = new(MockCommunicator) + var raw any = new(MockCommunicator) if _, ok := raw.(Communicator); !ok { t.Fatal("should be a communicator") } diff --git a/packer/datasource.go b/packer/datasource.go index b6f095486..a9ff3a322 100644 --- a/packer/datasource.go +++ b/packer/datasource.go @@ -14,7 +14,7 @@ type Datasource interface { HCL2Speccer // Configure takes values from HCL2 and applies them to the struct - Configure(...interface{}) error + Configure(...any) error // OutputSpec is the HCL2 layout of the variable output, it will allow // Packer to validate whether someone is using the output of the data diff --git a/packer/datasource_mock.go b/packer/datasource_mock.go index 46636e18e..2573638a0 100644 --- a/packer/datasource_mock.go +++ b/packer/datasource_mock.go @@ -13,10 +13,10 @@ import ( type MockDatasource struct { Foo string - OutputSpecCalled bool `mapstructure-to-hcl2:",skip"` - ConfigureCalled bool `mapstructure-to-hcl2:",skip"` - ConfigureConfigs []interface{} `mapstructure-to-hcl2:",skip"` - ExecuteCalled bool `mapstructure-to-hcl2:",skip"` + OutputSpecCalled bool `mapstructure-to-hcl2:",skip"` + ConfigureCalled bool `mapstructure-to-hcl2:",skip"` + ConfigureConfigs []any `mapstructure-to-hcl2:",skip"` + ExecuteCalled bool `mapstructure-to-hcl2:",skip"` } type MockDatasourceResponse struct { @@ -32,7 +32,7 @@ func (d *MockDatasource) OutputSpec() hcldec.ObjectSpec { return (&MockDatasourceResponse{}).FlatMapstructure().HCL2Spec() } -func (d *MockDatasource) Configure(configs ...interface{}) error { +func (d *MockDatasource) Configure(configs ...any) error { configHelper.Decode(d, nil, configs...) d.ConfigureCalled = true d.ConfigureConfigs = configs diff --git a/packer/hook.go b/packer/hook.go index a7b254a49..9e34d928c 100644 --- a/packer/hook.go +++ b/packer/hook.go @@ -25,7 +25,7 @@ const HookCleanupProvision = "packer_cleanup_provision" // must be race-free. Cancel should attempt to cancel the hook in the quickest, // safest way possible. type Hook interface { - Run(context.Context, string, Ui, Communicator, interface{}) error + Run(context.Context, string, Ui, Communicator, any) error } // A Hook implementation that dispatches based on an internal mapping. @@ -36,7 +36,7 @@ type DispatchHook struct { // Runs the hook with the given name by dispatching it to the proper // hooks if a mapping exists. If a mapping doesn't exist, then nothing // happens. -func (h *DispatchHook) Run(ctx context.Context, name string, ui Ui, comm Communicator, data interface{}) error { +func (h *DispatchHook) Run(ctx context.Context, name string, ui Ui, comm Communicator, data any) error { hooks, ok := h.Mapping[name] if !ok { // No hooks for that name. No problem. diff --git a/packer/hook_mock.go b/packer/hook_mock.go index bc6966116..d4d36ab1d 100644 --- a/packer/hook_mock.go +++ b/packer/hook_mock.go @@ -13,12 +13,12 @@ type MockHook struct { RunCalled bool RunComm Communicator - RunData interface{} + RunData any RunName string RunUi Ui } -func (t *MockHook) Run(ctx context.Context, name string, ui Ui, comm Communicator, data interface{}) error { +func (t *MockHook) Run(ctx context.Context, name string, ui Ui, comm Communicator, data any) error { t.RunCalled = true t.RunComm = comm diff --git a/packer/hook_test.go b/packer/hook_test.go index a6bed31ea..9690f554b 100644 --- a/packer/hook_test.go +++ b/packer/hook_test.go @@ -43,7 +43,7 @@ type CancelHook struct { cancel func() } -func (h *CancelHook) Run(ctx context.Context, _ string, _ Ui, _ Communicator, _ interface{}) error { +func (h *CancelHook) Run(ctx context.Context, _ string, _ Ui, _ Communicator, _ any) error { h.cancel() <-ctx.Done() return ctx.Err() diff --git a/packer/multi_error_test.go b/packer/multi_error_test.go index aa14f4224..b418c0bd6 100644 --- a/packer/multi_error_test.go +++ b/packer/multi_error_test.go @@ -9,7 +9,7 @@ import ( ) func TestMultiError_Impl(t *testing.T) { - var raw interface{} = &MultiError{} + var raw any = &MultiError{} if _, ok := raw.(error); !ok { t.Fatal("MultiError must implement error") } diff --git a/packer/post_processor.go b/packer/post_processor.go index dcbd33d20..219929b48 100644 --- a/packer/post_processor.go +++ b/packer/post_processor.go @@ -18,7 +18,7 @@ type PostProcessor interface { // Configure is responsible for setting up configuration, storing // the state for later, and returning and errors, such as validation // errors. - Configure(...interface{}) error + Configure(...any) error // PostProcess takes a previously created Artifact and produces another // Artifact. If an error occurs, it should return that error. If `keep` is diff --git a/packer/provisioner.go b/packer/provisioner.go index af8b3b275..bf050af8c 100644 --- a/packer/provisioner.go +++ b/packer/provisioner.go @@ -13,11 +13,11 @@ type Provisioner interface { // Prepare is called with a set of configurations to setup the // internal state of the provisioner. The multiple configurations // should be merged in some sane way. - Prepare(...interface{}) error + Prepare(...any) error // Provision is called to actually provision the machine. A context is // given for cancellation, a UI is given to communicate with the user, and // a communicator is given that is guaranteed to be connected to some // machine so that provisioning can be done. - Provision(context.Context, Ui, Communicator, map[string]interface{}) error + Provision(context.Context, Ui, Communicator, map[string]any) error } diff --git a/packer/provisioner_mock.go b/packer/provisioner_mock.go index 07fbe0895..3fa656260 100644 --- a/packer/provisioner_mock.go +++ b/packer/provisioner_mock.go @@ -16,7 +16,7 @@ type MockProvisioner struct { ProvFunc func(context.Context) error PrepCalled bool - PrepConfigs []interface{} + PrepConfigs []any ProvCalled bool ProvRetried bool ProvCommunicator Communicator @@ -25,15 +25,15 @@ type MockProvisioner struct { func (tp *MockProvisioner) ConfigSpec() hcldec.ObjectSpec { return tp.FlatMapstructure().HCL2Spec() } -func (tp *MockProvisioner) FlatConfig() interface{} { return tp.FlatMapstructure() } +func (tp *MockProvisioner) FlatConfig() any { return tp.FlatMapstructure() } -func (t *MockProvisioner) Prepare(configs ...interface{}) error { +func (t *MockProvisioner) Prepare(configs ...any) error { t.PrepCalled = true t.PrepConfigs = configs return nil } -func (t *MockProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator, generatedData map[string]interface{}) error { +func (t *MockProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator, generatedData map[string]any) error { if t.ProvCalled { t.ProvRetried = true return nil diff --git a/packer/provisioner_mock.hcl2spec.go b/packer/provisioner_mock.hcl2spec.go index 0c0d4ebbc..4b2e317f5 100644 --- a/packer/provisioner_mock.hcl2spec.go +++ b/packer/provisioner_mock.hcl2spec.go @@ -10,12 +10,12 @@ import ( // FlatMockProvisioner is an auto-generated flat version of MockProvisioner. // Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. type FlatMockProvisioner struct { - PrepCalled *bool `cty:"prep_called" hcl:"prep_called"` - PrepConfigs []interface{} `cty:"prep_configs" hcl:"prep_configs"` - ProvCalled *bool `cty:"prov_called" hcl:"prov_called"` - ProvRetried *bool `cty:"prov_retried" hcl:"prov_retried"` - ProvCommunicator Communicator `cty:"prov_communicator" hcl:"prov_communicator"` - ProvUi Ui `cty:"prov_ui" hcl:"prov_ui"` + PrepCalled *bool `cty:"prep_called" hcl:"prep_called"` + PrepConfigs []any `cty:"prep_configs" hcl:"prep_configs"` + ProvCalled *bool `cty:"prov_called" hcl:"prov_called"` + ProvRetried *bool `cty:"prov_retried" hcl:"prov_retried"` + ProvCommunicator Communicator `cty:"prov_communicator" hcl:"prov_communicator"` + ProvUi Ui `cty:"prov_ui" hcl:"prov_ui"` } // FlatMapstructure returns a new FlatMockProvisioner. diff --git a/packer/registry/image/fromartifact_example_test.go b/packer/registry/image/fromartifact_example_test.go index 4cd8e1f12..3500f7847 100644 --- a/packer/registry/image/fromartifact_example_test.go +++ b/packer/registry/image/fromartifact_example_test.go @@ -29,7 +29,7 @@ func (a *simpleArtifact) String() string { return fmt.Sprintf("Imported image URL: %s", a.Id()) } -func (a *simpleArtifact) State(name string) interface{} { +func (a *simpleArtifact) State(name string) any { return nil } @@ -78,7 +78,7 @@ func ExampleSetLabels() { image_id: "service-id-123", } - hcimage, _ := image.FromArtifact(a, image.SetLabels(map[string]interface{}{"kernel": "4.0", "python": "3.5"})) + hcimage, _ := image.FromArtifact(a, image.SetLabels(map[string]any{"kernel": "4.0", "python": "3.5"})) fmt.Printf("%v", hcimage.Labels) // Unordered output: // map[kernel:4.0 python:3.5] diff --git a/packer/registry/image/frommappeddata_example_test.go b/packer/registry/image/frommappeddata_example_test.go index 25f3a7ba4..bcb4e221f 100644 --- a/packer/registry/image/frommappeddata_example_test.go +++ b/packer/registry/image/frommappeddata_example_test.go @@ -37,7 +37,7 @@ func (a *artifact) String() string { return a.Id() } -func (a *artifact) State(name string) interface{} { +func (a *artifact) State(name string) any { return nil } @@ -53,7 +53,7 @@ func ExampleFromMappedData() { }, } - f := func(key, value interface{}) (*image.Image, error) { + f := func(key, value any) (*image.Image, error) { v, ok := value.(string) if !ok { return nil, errors.New("for happycloud maps value should always be string") diff --git a/packer/registry/image/image.go b/packer/registry/image/image.go index c1ce0e21a..70daead1e 100644 --- a/packer/registry/image/image.go +++ b/packer/registry/image/image.go @@ -68,7 +68,7 @@ func (i *Image) String() string { // FromMappedData will make its best attempt to convert the input map into map[interface{}]interface{} before // calling f(k,v). The func f is responsible for type asserting the expected type for the key and value before // trying to create an Image from it. -func FromMappedData(mappedData interface{}, f func(key, value interface{}) (*Image, error)) ([]*Image, error) { +func FromMappedData(mappedData any, f func(key, value any) (*Image, error)) ([]*Image, error) { mapValue := reflect.ValueOf(mappedData) if mapValue.Kind() != reflect.Map { return nil, errors.New("error the incoming mappedData does not appear to be a map; found type to be" + mapValue.Kind().String()) @@ -153,7 +153,7 @@ func WithRegion(region string) func(*Image) error { // will be filtered only for keys whose values are of type string. // If you wish to override this behavior you may create your own ArtifactOverrideFunc // for manipulating and setting Image metadata. -func SetLabels(md map[string]interface{}) func(*Image) error { +func SetLabels(md map[string]any) func(*Image) error { return func(img *Image) error { if img.Labels == nil { img.Labels = make(map[string]string) diff --git a/packer/registry/image/image_test.go b/packer/registry/image/image_test.go index ca1e6417f..6d33c7977 100644 --- a/packer/registry/image/image_test.go +++ b/packer/registry/image/image_test.go @@ -12,7 +12,7 @@ import ( ) func TestFromMappedData_badInput(t *testing.T) { - _, err := FromMappedData([]string{"invalid"}, func(k, v interface{}) (*Image, error) { return nil, nil }) + _, err := FromMappedData([]string{"invalid"}, func(k, v any) (*Image, error) { return nil, nil }) if err == nil { t.Errorf("unexpected results for bad map input; expected err to be non-nil") } @@ -30,7 +30,7 @@ func TestFromMappedData(t *testing.T) { "east": "happycloud-2", } - f := func(key, value interface{}) (*Image, error) { + f := func(key, value any) (*Image, error) { v, ok := value.(string) if !ok { return nil, errors.New("for happycloud maps value should always be string") @@ -121,7 +121,7 @@ func TestFromArtifact_WithProvider(t *testing.T) { func TestFromArtifact_SetLabels(t *testing.T) { artifact := new(packer.MockArtifact) - artifact.StateValues = map[string]interface{}{ + artifact.StateValues = map[string]any{ "cloud": "foo", "non-string-value": 7, "slice-of-strings": []string{"foo", "bar"}, diff --git a/packerbuilderdata/generated_data.go b/packerbuilderdata/generated_data.go index a90626fa3..daa8fa8f2 100644 --- a/packerbuilderdata/generated_data.go +++ b/packerbuilderdata/generated_data.go @@ -24,10 +24,10 @@ type GeneratedData struct { State multistep.StateBag } -func (gd *GeneratedData) Put(key string, data interface{}) { - genData := make(map[string]interface{}) +func (gd *GeneratedData) Put(key string, data any) { + genData := make(map[string]any) if _, ok := gd.State.GetOk("generated_data"); ok { - genData = gd.State.Get("generated_data").(map[string]interface{}) + genData = gd.State.Get("generated_data").(map[string]any) } genData[key] = data gd.State.Put("generated_data", genData) diff --git a/packerbuilderdata/generated_data_test.go b/packerbuilderdata/generated_data_test.go index a5deb5135..b68c6aaf5 100644 --- a/packerbuilderdata/generated_data_test.go +++ b/packerbuilderdata/generated_data_test.go @@ -24,7 +24,7 @@ func TestGeneratedData_Put(t *testing.T) { t.Fatalf("BAD: StateBag should contain generated_data") } - generatedDataState := generatedData.State.Get("generated_data").(map[string]interface{}) + generatedDataState := generatedData.State.Get("generated_data").(map[string]any) if generatedDataState["data_key"] != expectedValue { t.Fatalf("Unexpected state for data_key: expected %#v got %#v\n", expectedValue, generatedDataState["data_key"]) } diff --git a/retry/utils_test.go b/retry/utils_test.go index 4483c2d53..c70788fc2 100644 --- a/retry/utils_test.go +++ b/retry/utils_test.go @@ -9,12 +9,12 @@ import ( "github.com/google/go-cmp/cmp" ) -func DeepAllowUnexported(vs ...interface{}) cmp.Option { +func DeepAllowUnexported(vs ...any) cmp.Option { m := make(map[reflect.Type]struct{}) for _, v := range vs { structTypes(reflect.ValueOf(v), m) } - var typs []interface{} + var typs []any for t := range m { typs = append(typs, reflect.New(t).Elem().Interface()) } diff --git a/rpc/artifact.go b/rpc/artifact.go index 1ad7661d0..f69076e83 100644 --- a/rpc/artifact.go +++ b/rpc/artifact.go @@ -20,65 +20,65 @@ type ArtifactServer struct { } func (a *artifact) BuilderId() (result string) { - a.client.Call(a.endpoint+".BuilderId", new(interface{}), &result) + a.client.Call(a.endpoint+".BuilderId", new(any), &result) return } func (a *artifact) Files() (result []string) { - a.client.Call(a.endpoint+".Files", new(interface{}), &result) + a.client.Call(a.endpoint+".Files", new(any), &result) return } func (a *artifact) Id() (result string) { - a.client.Call(a.endpoint+".Id", new(interface{}), &result) + a.client.Call(a.endpoint+".Id", new(any), &result) return } func (a *artifact) String() (result string) { - a.client.Call(a.endpoint+".String", new(interface{}), &result) + a.client.Call(a.endpoint+".String", new(any), &result) return } -func (a *artifact) State(name string) (result interface{}) { +func (a *artifact) State(name string) (result any) { a.client.Call(a.endpoint+".State", name, &result) return } func (a *artifact) Destroy() error { var result error - if err := a.client.Call(a.endpoint+".Destroy", new(interface{}), &result); err != nil { + if err := a.client.Call(a.endpoint+".Destroy", new(any), &result); err != nil { return err } return result } -func (s *ArtifactServer) BuilderId(args *interface{}, reply *string) error { +func (s *ArtifactServer) BuilderId(args *any, reply *string) error { *reply = s.artifact.BuilderId() return nil } -func (s *ArtifactServer) Files(args *interface{}, reply *[]string) error { +func (s *ArtifactServer) Files(args *any, reply *[]string) error { *reply = s.artifact.Files() return nil } -func (s *ArtifactServer) Id(args *interface{}, reply *string) error { +func (s *ArtifactServer) Id(args *any, reply *string) error { *reply = s.artifact.Id() return nil } -func (s *ArtifactServer) String(args *interface{}, reply *string) error { +func (s *ArtifactServer) String(args *any, reply *string) error { *reply = s.artifact.String() return nil } -func (s *ArtifactServer) State(name string, reply *interface{}) error { +func (s *ArtifactServer) State(name string, reply *any) error { *reply = s.artifact.State(name) return nil } -func (s *ArtifactServer) Destroy(args *interface{}, reply *error) error { +func (s *ArtifactServer) Destroy(args *any, reply *error) error { err := s.artifact.Destroy() if err != nil { err = NewBasicError(err) diff --git a/rpc/build.go b/rpc/build.go index 1e7147c2c..9bae5719f 100644 --- a/rpc/build.go +++ b/rpc/build.go @@ -32,13 +32,13 @@ type BuildPrepareResponse struct { } func (b *build) Name() (result string) { - b.client.Call("Build.Name", new(interface{}), &result) + b.client.Call("Build.Name", new(any), &result) return } func (b *build) Prepare() ([]string, error) { var resp BuildPrepareResponse - if cerr := b.client.Call("Build.Prepare", new(interface{}), &resp); cerr != nil { + if cerr := b.client.Call("Build.Prepare", new(any), &resp); cerr != nil { return nil, cerr } var err error = nil @@ -55,13 +55,13 @@ func (b *build) Run(ctx context.Context, ui packersdk.Ui) ([]packersdk.Artifact, server.RegisterUi(ui) go server.Serve() - done := make(chan interface{}) + done := make(chan any) defer close(done) go func() { select { case <-ctx.Done(): log.Printf("Cancelling build after context cancellation %v", ctx.Err()) - if err := b.client.Call("Build.Cancel", new(interface{}), new(interface{})); err != nil { + if err := b.client.Call("Build.Cancel", new(any), new(any)); err != nil { log.Printf("Error cancelling builder: %s", err) } case <-done: @@ -87,35 +87,35 @@ func (b *build) Run(ctx context.Context, ui packersdk.Ui) ([]packersdk.Artifact, } func (b *build) SetDebug(val bool) { - if err := b.client.Call("Build.SetDebug", val, new(interface{})); err != nil { + if err := b.client.Call("Build.SetDebug", val, new(any)); err != nil { panic(err) } } func (b *build) SetForce(val bool) { - if err := b.client.Call("Build.SetForce", val, new(interface{})); err != nil { + if err := b.client.Call("Build.SetForce", val, new(any)); err != nil { panic(err) } } func (b *build) SetOnError(val string) { - if err := b.client.Call("Build.SetOnError", val, new(interface{})); err != nil { + if err := b.client.Call("Build.SetOnError", val, new(any)); err != nil { panic(err) } } func (b *build) Cancel() { - if err := b.client.Call("Build.Cancel", new(interface{}), new(interface{})); err != nil { + if err := b.client.Call("Build.Cancel", new(any), new(any)); err != nil { panic(err) } } -func (b *BuildServer) Name(args *interface{}, reply *string) error { +func (b *BuildServer) Name(args *any, reply *string) error { *reply = b.build.Name() return nil } -func (b *BuildServer) Prepare(args *interface{}, resp *BuildPrepareResponse) error { +func (b *BuildServer) Prepare(args *any, resp *BuildPrepareResponse) error { warnings, err := b.build.Prepare() *resp = BuildPrepareResponse{ Warnings: warnings, @@ -153,22 +153,22 @@ func (b *BuildServer) Run(streamId uint32, reply *[]uint32) error { return nil } -func (b *BuildServer) SetDebug(val *bool, reply *interface{}) error { +func (b *BuildServer) SetDebug(val *bool, reply *any) error { b.build.SetDebug(*val) return nil } -func (b *BuildServer) SetForce(val *bool, reply *interface{}) error { +func (b *BuildServer) SetForce(val *bool, reply *any) error { b.build.SetForce(*val) return nil } -func (b *BuildServer) SetOnError(val *string, reply *interface{}) error { +func (b *BuildServer) SetOnError(val *string, reply *any) error { b.build.SetOnError(*val) return nil } -func (b *BuildServer) Cancel(args *interface{}, reply *interface{}) error { +func (b *BuildServer) Cancel(args *any, reply *any) error { if b.contextCancel != nil { b.contextCancel() } diff --git a/rpc/build_test.go b/rpc/build_test.go index c23d03c9c..feafa0db9 100644 --- a/rpc/build_test.go +++ b/rpc/build_test.go @@ -137,7 +137,7 @@ func TestBuild_cancel(t *testing.T) { b := new(testBuild) - done := make(chan interface{}) + done := make(chan any) b.runFn = func(ctx context.Context) { cancelTopCtx() <-ctx.Done() diff --git a/rpc/builder.go b/rpc/builder.go index 28424ce57..20b6dcd61 100644 --- a/rpc/builder.go +++ b/rpc/builder.go @@ -27,7 +27,7 @@ type BuilderServer struct { } type BuilderPrepareArgs struct { - Configs []interface{} + Configs []any } type BuilderPrepareResponse struct { @@ -36,7 +36,7 @@ type BuilderPrepareResponse struct { Error *BasicError } -func (b *builder) Prepare(config ...interface{}) ([]string, []string, error) { +func (b *builder) Prepare(config ...any) ([]string, []string, error) { config, err := encodeCTYValues(config) if err != nil { return nil, nil, err @@ -61,13 +61,13 @@ func (b *builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) server.RegisterUi(ui) go server.Serve() - done := make(chan interface{}) + done := make(chan any) defer close(done) go func() { select { case <-ctx.Done(): log.Printf("Cancelling builder after context cancellation %v", ctx.Err()) - if err := b.client.Call(b.endpoint+".Cancel", new(interface{}), new(interface{})); err != nil { + if err := b.client.Call(b.endpoint+".Cancel", new(any), new(any)); err != nil { log.Printf("Error cancelling builder: %s", err) } case <-done: @@ -137,7 +137,7 @@ func (b *BuilderServer) Run(streamId uint32, reply *uint32) error { return nil } -func (b *BuilderServer) Cancel(args *interface{}, reply *interface{}) error { +func (b *BuilderServer) Cancel(args *any, reply *any) error { b.contextCancel() return nil } diff --git a/rpc/builder_test.go b/rpc/builder_test.go index 1a5638faf..3a5b1e183 100644 --- a/rpc/builder_test.go +++ b/rpc/builder_test.go @@ -35,7 +35,7 @@ func TestBuilderPrepare(t *testing.T) { t.Fatal("should be called") } - expected := []interface{}{int64(42)} + expected := []any{int64(42)} if !reflect.DeepEqual(b.PrepareConfig, expected) { t.Fatalf("bad: %#v != %#v", b.PrepareConfig, expected) } diff --git a/rpc/common.go b/rpc/common.go index 2025197f4..07dc1e745 100644 --- a/rpc/common.go +++ b/rpc/common.go @@ -57,7 +57,7 @@ func (p *commonClient) ConfigSpec() hcldec.ObjectSpec { // decide later. The correct approach would probably be to return an error // in ConfigSpec but that will break a lot of things. resp := &ConfigSpecResponse{} - cerr := p.client.Call(p.endpoint+".ConfigSpec", new(interface{}), resp) + cerr := p.client.Call(p.endpoint+".ConfigSpec", new(any), resp) if cerr != nil { err := fmt.Errorf("ConfigSpec failed: %v", cerr) panic(err.Error()) @@ -90,7 +90,7 @@ func (p *commonClient) ConfigSpec() hcldec.ObjectSpec { return spec } -func (s *commonServer) ConfigSpec(_ interface{}, reply *ConfigSpecResponse) error { +func (s *commonServer) ConfigSpec(_ any, reply *ConfigSpecResponse) error { spec := s.selfConfigurable.ConfigSpec() if !s.useProto { diff --git a/rpc/communicator.go b/rpc/communicator.go index 73471da50..ef666acad 100644 --- a/rpc/communicator.go +++ b/rpc/communicator.go @@ -130,7 +130,7 @@ func (c *communicator) Start(ctx context.Context, cmd *packersdk.RemoteCmd) (err cmd.SetExited(finished.ExitStatus) }() - err = c.client.Call(c.endpoint+".Start", &args, new(interface{})) + err = c.client.Call(c.endpoint+".Start", &args, new(any)) return } @@ -148,7 +148,7 @@ func (c *communicator) Upload(path string, r io.Reader, fi *os.FileInfo) (err er args.FileInfo = NewFileInfo(*fi) } - err = c.client.Call(c.endpoint+".Upload", &args, new(interface{})) + err = c.client.Call(c.endpoint+".Upload", &args, new(any)) return } @@ -200,7 +200,7 @@ func (c *communicator) Download(path string, w io.Writer) (err error) { } // Start sending data to the RPC server - err = c.client.Call(c.endpoint+".Download", &args, new(interface{})) + err = c.client.Call(c.endpoint+".Download", &args, new(any)) // Wait for the RPC server to finish receiving the data before we return <-waitServer @@ -208,7 +208,7 @@ func (c *communicator) Download(path string, w io.Writer) (err error) { return } -func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface{}) error { +func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *any) error { ctx := context.TODO() // Build the RemoteCmd on this side so that it all pipes over @@ -289,7 +289,7 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface return nil } -func (c *CommunicatorServer) Upload(args *CommunicatorUploadArgs, reply *interface{}) (err error) { +func (c *CommunicatorServer) Upload(args *CommunicatorUploadArgs, reply *any) (err error) { readerC, err := c.mux.Dial(args.ReaderStreamId) if err != nil { return @@ -313,7 +313,7 @@ func (c *CommunicatorServer) DownloadDir(args *CommunicatorUploadDirArgs, reply return c.c.DownloadDir(args.Src, args.Dst, args.Exclude) } -func (c *CommunicatorServer) Download(args *CommunicatorDownloadArgs, reply *interface{}) (err error) { +func (c *CommunicatorServer) Download(args *CommunicatorDownloadArgs, reply *any) (err error) { writerC, err := c.mux.Dial(args.WriterStreamId) if err != nil { return diff --git a/rpc/communicator_test.go b/rpc/communicator_test.go index 21fdbf59a..4348f8adc 100644 --- a/rpc/communicator_test.go +++ b/rpc/communicator_test.go @@ -164,7 +164,7 @@ func TestCommunicatorRPC(t *testing.T) { } func TestCommunicator_ImplementsCommunicator(t *testing.T) { - var raw interface{} = Communicator(nil) + var raw any = Communicator(nil) if _, ok := raw.(packersdk.Communicator); !ok { t.Fatal("should be a Communicator") } diff --git a/rpc/cty_encode.go b/rpc/cty_encode.go index 5fc5450dd..fe10ba2fa 100644 --- a/rpc/cty_encode.go +++ b/rpc/cty_encode.go @@ -10,7 +10,7 @@ import ( // cty.Value is does not know how to encode itself through the wire so we // transform it to bytes. -func encodeCTYValues(config []interface{}) ([]interface{}, error) { +func encodeCTYValues(config []any) ([]any, error) { for i := range config { if v, ok := config[i].(cty.Value); ok { b, err := json.Marshal(v, cty.DynamicPseudoType) @@ -24,7 +24,7 @@ func encodeCTYValues(config []interface{}) ([]interface{}, error) { } // decodeCTYValues will try to decode a cty value when it finds a byte slice -func decodeCTYValues(config []interface{}) ([]interface{}, error) { +func decodeCTYValues(config []any) ([]any, error) { for i := range config { if b, ok := config[i].([]byte); ok { t, err := json.Unmarshal(b, cty.DynamicPseudoType) diff --git a/rpc/datasource.go b/rpc/datasource.go index 358f252b4..52a57942e 100644 --- a/rpc/datasource.go +++ b/rpc/datasource.go @@ -22,14 +22,14 @@ type datasource struct { } type DatasourceConfigureArgs struct { - Configs []interface{} + Configs []any } type DatasourceConfigureResponse struct { Error *BasicError } -func (d *datasource) Configure(configs ...interface{}) error { +func (d *datasource) Configure(configs ...any) error { configs, err := encodeCTYValues(configs) if err != nil { return err @@ -50,7 +50,7 @@ type OutputSpecResponse struct { func (d *datasource) OutputSpec() hcldec.ObjectSpec { resp := new(OutputSpecResponse) - if err := d.client.Call(d.endpoint+".OutputSpec", new(interface{}), resp); err != nil { + if err := d.client.Call(d.endpoint+".OutputSpec", new(any), resp); err != nil { err := fmt.Errorf("Datasource.OutputSpec failed: %v", err) panic(err.Error()) } @@ -80,7 +80,7 @@ type ExecuteResponse struct { func (d *datasource) Execute() (cty.Value, error) { resp := new(ExecuteResponse) - if err := d.client.Call(d.endpoint+".Execute", new(interface{}), resp); err != nil { + if err := d.client.Call(d.endpoint+".Execute", new(any), resp); err != nil { err := fmt.Errorf("Datasource.Execute failed: %v", err) return cty.NilVal, err } @@ -150,7 +150,7 @@ func (d *DatasourceServer) OutputSpec(args *DatasourceConfigureArgs, reply *Outp return err } -func (d *DatasourceServer) Execute(args *interface{}, reply *ExecuteResponse) error { +func (d *DatasourceServer) Execute(args *any, reply *ExecuteResponse) error { spec, err := d.d.Execute() reply.Error = NewBasicError(err) @@ -174,7 +174,7 @@ func (d *DatasourceServer) Execute(args *interface{}, reply *ExecuteResponse) er return err } -func (d *DatasourceServer) Cancel(args *interface{}, reply *interface{}) error { +func (d *DatasourceServer) Cancel(args *any, reply *any) error { if d.contextCancel != nil { d.contextCancel() } diff --git a/rpc/datasource_test.go b/rpc/datasource_test.go index 4ca26c362..881a71da4 100644 --- a/rpc/datasource_test.go +++ b/rpc/datasource_test.go @@ -14,7 +14,7 @@ import ( type testDatasource struct { configCalled bool - configVal []interface{} + configVal []any outputSpecCalled bool outputSpec hcldec.ObjectSpec @@ -25,7 +25,7 @@ type testDatasource struct { func (*testDatasource) ConfigSpec() hcldec.ObjectSpec { return nil } -func (d *testDatasource) Configure(configs ...interface{}) error { +func (d *testDatasource) Configure(configs ...any) error { d.configCalled = true d.configVal = configs return nil @@ -57,7 +57,7 @@ func TestDatasource(t *testing.T) { if !d.configCalled { t.Fatal("config should be called") } - expected := []interface{}{int64(42)} + expected := []any{int64(42)} if !reflect.DeepEqual(d.configVal, expected) { t.Fatalf("unknown config value: %#v", d.configVal) } @@ -89,7 +89,7 @@ func TestDatasource(t *testing.T) { } func TestDatasource_Implements(t *testing.T) { - var raw interface{} = new(datasource) + var raw any = new(datasource) if _, ok := raw.(packer.Datasource); !ok { t.Fatal("not a datasource") } diff --git a/rpc/fileinfo.go b/rpc/fileinfo.go index 0efd809eb..27a6d1381 100644 --- a/rpc/fileinfo.go +++ b/rpc/fileinfo.go @@ -32,5 +32,5 @@ func (fi fileInfo) ModTime() time.Time { } return fi.T } -func (fi fileInfo) IsDir() bool { return fi.M.IsDir() } -func (fi fileInfo) Sys() interface{} { return nil } +func (fi fileInfo) IsDir() bool { return fi.M.IsDir() } +func (fi fileInfo) Sys() any { return nil } diff --git a/rpc/fileinfo_test.go b/rpc/fileinfo_test.go index 78abd5675..85bb0319a 100644 --- a/rpc/fileinfo_test.go +++ b/rpc/fileinfo_test.go @@ -17,8 +17,8 @@ func (fi dummyFileInfo) Mode() os.FileMode { return 0644 } func (fi dummyFileInfo) ModTime() time.Time { return time.Time{}.Add(1 * time.Minute) } -func (fi dummyFileInfo) IsDir() bool { return false } -func (fi dummyFileInfo) Sys() interface{} { return nil } +func (fi dummyFileInfo) IsDir() bool { return false } +func (fi dummyFileInfo) Sys() any { return nil } func TestNewFileInfoNilPointer(t *testing.T) { fi := NewFileInfo(os.FileInfo(nil)) if fi != nil { diff --git a/rpc/hook.go b/rpc/hook.go index b6e622f2f..3b2c0b911 100644 --- a/rpc/hook.go +++ b/rpc/hook.go @@ -30,24 +30,24 @@ type HookServer struct { type HookRunArgs struct { Name string - Data interface{} + Data any StreamId uint32 } -func (h *hook) Run(ctx context.Context, name string, ui packersdk.Ui, comm packersdk.Communicator, data interface{}) error { +func (h *hook) Run(ctx context.Context, name string, ui packersdk.Ui, comm packersdk.Communicator, data any) error { nextId := h.mux.NextId() server := newServerWithMux(h.mux, nextId) server.RegisterCommunicator(comm) server.RegisterUi(ui) go server.Serve() - done := make(chan interface{}) + done := make(chan any) defer close(done) go func() { select { case <-ctx.Done(): log.Printf("Cancelling hook after context cancellation %v", ctx.Err()) - if err := h.client.Call(h.endpoint+".Cancel", new(interface{}), new(interface{})); err != nil { + if err := h.client.Call(h.endpoint+".Cancel", new(any), new(any)); err != nil { log.Printf("Error cancelling builder: %s", err) } case <-done: @@ -60,10 +60,10 @@ func (h *hook) Run(ctx context.Context, name string, ui packersdk.Ui, comm packe StreamId: nextId, } - return h.client.Call(h.endpoint+".Run", &args, new(interface{})) + return h.client.Call(h.endpoint+".Run", &args, new(any)) } -func (h *HookServer) Run(args *HookRunArgs, reply *interface{}) error { +func (h *HookServer) Run(args *HookRunArgs, reply *any) error { client, err := newClientWithMux(h.mux, args.StreamId) if err != nil { return NewBasicError(err) @@ -83,7 +83,7 @@ func (h *HookServer) Run(args *HookRunArgs, reply *interface{}) error { return nil } -func (h *HookServer) Cancel(args *interface{}, reply *interface{}) error { +func (h *HookServer) Cancel(args *any, reply *any) error { h.lock.Lock() if h.contextCancel != nil { h.contextCancel() diff --git a/rpc/init.go b/rpc/init.go index 08c890104..05dcf464b 100644 --- a/rpc/init.go +++ b/rpc/init.go @@ -22,6 +22,6 @@ var _ gob.GobEncoder = cty.Value{} func init() { gob.Register(new(map[string]string)) - gob.Register(make([]interface{}, 0)) + gob.Register(make([]any, 0)) gob.Register(new(BasicError)) } diff --git a/rpc/post_processor.go b/rpc/post_processor.go index d656daf1f..604326e35 100644 --- a/rpc/post_processor.go +++ b/rpc/post_processor.go @@ -27,7 +27,7 @@ type PostProcessorServer struct { } type PostProcessorConfigureArgs struct { - Configs []interface{} + Configs []any } type PostProcessorProcessResponse struct { @@ -37,13 +37,13 @@ type PostProcessorProcessResponse struct { StreamId uint32 } -func (p *postProcessor) Configure(raw ...interface{}) error { +func (p *postProcessor) Configure(raw ...any) error { raw, err := encodeCTYValues(raw) if err != nil { return err } args := &PostProcessorConfigureArgs{Configs: raw} - return p.client.Call(p.endpoint+".Configure", args, new(interface{})) + return p.client.Call(p.endpoint+".Configure", args, new(any)) } func (p *postProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, a packersdk.Artifact) (packersdk.Artifact, bool, bool, error) { @@ -53,14 +53,14 @@ func (p *postProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, a pack server.RegisterUi(ui) go server.Serve() - done := make(chan interface{}) + done := make(chan any) defer close(done) go func() { select { case <-ctx.Done(): log.Printf("Cancelling post-processor after context cancellation %v", ctx.Err()) - if err := p.client.Call(p.endpoint+".Cancel", new(interface{}), new(interface{})); err != nil { + if err := p.client.Call(p.endpoint+".Cancel", new(any), new(any)); err != nil { log.Printf("Error cancelling post-processor: %s", err) } case <-done: @@ -88,7 +88,7 @@ func (p *postProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, a pack return client.Artifact(), response.Keep, response.ForceOverride, nil } -func (p *PostProcessorServer) Configure(args *PostProcessorConfigureArgs, reply *interface{}) (err error) { +func (p *PostProcessorServer) Configure(args *PostProcessorConfigureArgs, reply *any) (err error) { config, err := decodeCTYValues(args.Configs) if err != nil { return err @@ -141,7 +141,7 @@ func (p *PostProcessorServer) PostProcess(streamId uint32, reply *PostProcessorP return nil } -func (b *PostProcessorServer) Cancel(args *interface{}, reply *interface{}) error { +func (b *PostProcessorServer) Cancel(args *any, reply *any) error { if b.contextCancel != nil { b.contextCancel() } diff --git a/rpc/post_processor_test.go b/rpc/post_processor_test.go index 188fd081e..f3d6c3e4b 100644 --- a/rpc/post_processor_test.go +++ b/rpc/post_processor_test.go @@ -16,7 +16,7 @@ var testPostProcessorArtifact = new(packersdk.MockArtifact) type TestPostProcessor struct { configCalled bool - configVal []interface{} + configVal []any ppCalled bool ppArtifact packersdk.Artifact ppArtifactId string @@ -27,7 +27,7 @@ type TestPostProcessor struct { func (*TestPostProcessor) ConfigSpec() hcldec.ObjectSpec { return nil } -func (pp *TestPostProcessor) Configure(v ...interface{}) error { +func (pp *TestPostProcessor) Configure(v ...any) error { pp.configCalled = true pp.configVal = v return nil @@ -67,7 +67,7 @@ func TestPostProcessorRPC(t *testing.T) { t.Fatal("config should be called") } - expected := []interface{}{int64(42)} + expected := []any{int64(42)} if !reflect.DeepEqual(p.configVal, expected) { t.Fatalf("unknown config value: %#v", p.configVal) } @@ -134,7 +134,7 @@ func TestPostProcessorRPC_cancel(t *testing.T) { } func TestPostProcessor_Implements(t *testing.T) { - var raw interface{} = new(postProcessor) + var raw any = new(postProcessor) if _, ok := raw.(packersdk.PostProcessor); !ok { t.Fatal("not a postprocessor") } diff --git a/rpc/provisioner.go b/rpc/provisioner.go index 04f2cb574..5c54c518f 100644 --- a/rpc/provisioner.go +++ b/rpc/provisioner.go @@ -27,38 +27,38 @@ type ProvisionerServer struct { } type ProvisionerPrepareArgs struct { - Configs []interface{} + Configs []any } -func (p *provisioner) Prepare(configs ...interface{}) error { +func (p *provisioner) Prepare(configs ...any) error { configs, err := encodeCTYValues(configs) if err != nil { return err } args := &ProvisionerPrepareArgs{configs} - return p.client.Call(p.endpoint+".Prepare", args, new(interface{})) + return p.client.Call(p.endpoint+".Prepare", args, new(any)) } type ProvisionerProvisionArgs struct { - GeneratedData map[string]interface{} + GeneratedData map[string]any StreamID uint32 } -func (p *provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]interface{}) error { +func (p *provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]any) error { nextId := p.mux.NextId() server := newServerWithMux(p.mux, nextId) server.RegisterCommunicator(comm) server.RegisterUi(ui) go server.Serve() - done := make(chan interface{}) + done := make(chan any) defer close(done) go func() { select { case <-ctx.Done(): log.Printf("Cancelling provisioner after context cancellation %v", ctx.Err()) - if err := p.client.Call(p.endpoint+".Cancel", new(interface{}), new(interface{})); err != nil { + if err := p.client.Call(p.endpoint+".Cancel", new(any), new(any)); err != nil { log.Printf("Error cancelling provisioner: %s", err) } case <-done: @@ -66,10 +66,10 @@ func (p *provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packe }() args := &ProvisionerProvisionArgs{generatedData, nextId} - return p.client.Call(p.endpoint+".Provision", args, new(interface{})) + return p.client.Call(p.endpoint+".Provision", args, new(any)) } -func (p *ProvisionerServer) Prepare(args *ProvisionerPrepareArgs, reply *interface{}) error { +func (p *ProvisionerServer) Prepare(args *ProvisionerPrepareArgs, reply *any) error { config, err := decodeCTYValues(args.Configs) if err != nil { return err @@ -77,7 +77,7 @@ func (p *ProvisionerServer) Prepare(args *ProvisionerPrepareArgs, reply *interfa return p.p.Prepare(config...) } -func (p *ProvisionerServer) Provision(args *ProvisionerProvisionArgs, reply *interface{}) error { +func (p *ProvisionerServer) Provision(args *ProvisionerProvisionArgs, reply *any) error { streamId := args.StreamID client, err := newClientWithMux(p.mux, streamId) if err != nil { @@ -95,7 +95,7 @@ func (p *ProvisionerServer) Provision(args *ProvisionerProvisionArgs, reply *int return nil } -func (p *ProvisionerServer) Cancel(args *interface{}, reply *interface{}) error { +func (p *ProvisionerServer) Cancel(args *any, reply *any) error { p.contextCancel() return nil } diff --git a/rpc/provisioner_test.go b/rpc/provisioner_test.go index b4be235c1..a20b1ff59 100644 --- a/rpc/provisioner_test.go +++ b/rpc/provisioner_test.go @@ -34,7 +34,7 @@ func TestProvisionerRPC(t *testing.T) { if !p.PrepCalled { t.Fatal("should be called") } - expected := []interface{}{int64(42)} + expected := []any{int64(42)} if !reflect.DeepEqual(p.PrepConfigs, expected) { t.Fatalf("bad: %#v", p.PrepConfigs) } @@ -42,7 +42,7 @@ func TestProvisionerRPC(t *testing.T) { // Test Provision ui := &testUi{} comm := &packersdk.MockCommunicator{} - if err := pClient.Provision(topCtx, ui, comm, make(map[string]interface{})); err == nil { + if err := pClient.Provision(topCtx, ui, comm, make(map[string]any)); err == nil { t.Fatalf("Provison should have err") } if !p.ProvCalled { diff --git a/rpc/ui.go b/rpc/ui.go index f6babe9ba..47949a0ca 100644 --- a/rpc/ui.go +++ b/rpc/ui.go @@ -23,7 +23,7 @@ var _ packersdk.Ui = new(Ui) // as part of a Golang RPC server. type UiServer struct { ui packersdk.Ui - register func(name string, rcvr interface{}) error + register func(name string, rcvr any) error } // The arguments sent to Ui.Machine @@ -44,7 +44,7 @@ func (u *Ui) Errorf(message string, args ...any) { u.Error(fmt.Sprintf(message, args...)) } func (u *Ui) Error(message string) { - if err := u.client.Call("Ui.Error", message, new(interface{})); err != nil { + if err := u.client.Call("Ui.Error", message, new(any)); err != nil { log.Printf("Error in Ui.Error RPC call: %s", err) } } @@ -55,14 +55,14 @@ func (u *Ui) Machine(t string, args ...string) { Args: args, } - if err := u.client.Call("Ui.Machine", rpcArgs, new(interface{})); err != nil { + if err := u.client.Call("Ui.Machine", rpcArgs, new(any)); err != nil { log.Printf("Error in Ui.Machine RPC call: %s", err) } } // Deprecated: Use `Say` instead. func (u *Ui) Message(message string) { - if err := u.client.Call("Ui.Message", message, new(interface{})); err != nil { + if err := u.client.Call("Ui.Message", message, new(any)); err != nil { log.Printf("Error in Ui.Message RPC call: %s", err) } } @@ -71,7 +71,7 @@ func (u *Ui) Sayf(message string, args ...any) { u.Say(fmt.Sprintf(message, args...)) } func (u *Ui) Say(message string) { - if err := u.client.Call("Ui.Say", message, new(interface{})); err != nil { + if err := u.client.Call("Ui.Say", message, new(any)); err != nil { log.Printf("Error in Ui.Say RPC call: %s", err) } } @@ -81,14 +81,14 @@ func (u *UiServer) Ask(query string, reply *string) (err error) { return } -func (u *UiServer) Error(message *string, reply *interface{}) error { +func (u *UiServer) Error(message *string, reply *any) error { u.ui.Error(*message) *reply = nil return nil } -func (u *UiServer) Machine(args *UiMachineArgs, reply *interface{}) error { +func (u *UiServer) Machine(args *UiMachineArgs, reply *any) error { u.ui.Machine(args.Category, args.Args...) *reply = nil @@ -96,13 +96,13 @@ func (u *UiServer) Machine(args *UiMachineArgs, reply *interface{}) error { } // Deprecated: Use `Say` instead. -func (u *UiServer) Message(message *string, reply *interface{}) error { +func (u *UiServer) Message(message *string, reply *any) error { u.ui.Message(*message) *reply = nil return nil } -func (u *UiServer) Say(message *string, reply *interface{}) error { +func (u *UiServer) Say(message *string, reply *any) error { u.ui.Say(*message) *reply = nil diff --git a/rpc/ui_progress_tracking.go b/rpc/ui_progress_tracking.go index 9ea768777..1bb2ebdc9 100644 --- a/rpc/ui_progress_tracking.go +++ b/rpc/ui_progress_tracking.go @@ -42,7 +42,7 @@ type ProgressTrackingClient struct { // Read will send len(b) over the wire instead of it's content func (u *ProgressTrackingClient) Read(b []byte) (read int, err error) { defer func() { - if err := u.client.Call("Ui"+u.id+".Add", read, new(interface{})); err != nil { + if err := u.client.Call("Ui"+u.id+".Add", read, new(any)); err != nil { log.Printf("Error in ProgressTrackingClient.Read RPC call: %s", err) } }() @@ -51,7 +51,7 @@ func (u *ProgressTrackingClient) Read(b []byte) (read int, err error) { func (u *ProgressTrackingClient) Close() error { log.Printf("closing") - if err := u.client.Call("Ui"+u.id+".Close", nil, new(interface{})); err != nil { + if err := u.client.Call("Ui"+u.id+".Close", nil, new(any)); err != nil { log.Printf("Error in ProgressTrackingClient.Close RPC call: %s", err) } return u.stream.Close() @@ -84,13 +84,13 @@ type ProgressTrackingServer struct { stream io.ReadCloser } -func (t *ProgressTrackingServer) Add(size int, _ *interface{}) error { +func (t *ProgressTrackingServer) Add(size int, _ *any) error { stubBytes := make([]byte, size) t.stream.Read(stubBytes) return nil } -func (t *ProgressTrackingServer) Close(_, _ *interface{}) error { +func (t *ProgressTrackingServer) Close(_, _ *any) error { t.stream.Close() return nil } diff --git a/sdk-internals/communicator/none/communicator_test.go b/sdk-internals/communicator/none/communicator_test.go index e583996db..4ec9e4c03 100644 --- a/sdk-internals/communicator/none/communicator_test.go +++ b/sdk-internals/communicator/none/communicator_test.go @@ -10,7 +10,7 @@ import ( ) func TestCommIsCommunicator(t *testing.T) { - var raw interface{} = &comm{} + var raw any = &comm{} if _, ok := raw.(packersdk.Communicator); !ok { t.Fatalf("comm must be a communicator") } diff --git a/sdk-internals/communicator/ssh/communicator_test.go b/sdk-internals/communicator/ssh/communicator_test.go index 84277e7f0..594c3bfbe 100644 --- a/sdk-internals/communicator/ssh/communicator_test.go +++ b/sdk-internals/communicator/ssh/communicator_test.go @@ -123,7 +123,7 @@ func newMockBrokenServer(t *testing.T) string { } func TestCommIsCommunicator(t *testing.T) { - var raw interface{} = &comm{} + var raw any = &comm{} if _, ok := raw.(packersdk.Communicator); !ok { t.Fatalf("comm must be a communicator") } diff --git a/sdk-internals/communicator/ssh/password_test.go b/sdk-internals/communicator/ssh/password_test.go index f6b0f7b0a..7ba5d9208 100644 --- a/sdk-internals/communicator/ssh/password_test.go +++ b/sdk-internals/communicator/ssh/password_test.go @@ -11,7 +11,7 @@ import ( ) func TestPasswordKeyboardInteractive_Impl(t *testing.T) { - var raw interface{} = PasswordKeyboardInteractive("foo") + var raw any = PasswordKeyboardInteractive("foo") if _, ok := raw.(ssh.KeyboardInteractiveChallenge); !ok { t.Fatal("PasswordKeyboardInteractive must implement KeyboardInteractiveChallenge") } diff --git a/shell-local/config.go b/shell-local/config.go index 53c9fb6bd..34428f95c 100644 --- a/shell-local/config.go +++ b/shell-local/config.go @@ -49,10 +49,10 @@ type Config struct { // GeneratedData ctx interpolate.Context - generatedData map[string]interface{} + generatedData map[string]any } -func Decode(config *Config, raws ...interface{}) error { +func Decode(config *Config, raws ...any) error { err := configHelper.Decode(config, &configHelper.DecodeOpts{ Interpolate: true, InterpolateContext: &config.ctx, diff --git a/shell-local/run.go b/shell-local/run.go index 2e45ea7c5..44ddf5ed2 100644 --- a/shell-local/run.go +++ b/shell-local/run.go @@ -21,13 +21,13 @@ import ( "github.com/hashicorp/packer-plugin-sdk/tmp" ) -func Run(ctx context.Context, ui packersdk.Ui, config *Config, generatedData map[string]interface{}) (bool, error) { +func Run(ctx context.Context, ui packersdk.Ui, config *Config, generatedData map[string]any) (bool, error) { if generatedData != nil { config.generatedData = generatedData } else { // No fear; probably just in the post-processor, not provisioner. // Make sure it's not a nil map so we can assign to it later. - config.generatedData = make(map[string]interface{}) + config.generatedData = make(map[string]any) } config.ctx.Data = generatedData // Check if shell-local can even execute against this runtime OS diff --git a/template/config/decode.go b/template/config/decode.go index c0bd827ba..49af9890c 100644 --- a/template/config/decode.go +++ b/template/config/decode.go @@ -52,7 +52,7 @@ var DefaultDecodeHookFuncs = []mapstructure.DecodeHookFunc{ // Decode decodes the configuration into the target and optionally // automatically interpolates all the configuration as it goes. -func Decode(target interface{}, config *DecodeOpts, raws ...interface{}) error { +func Decode(target any, config *DecodeOpts, raws ...any) error { // loop over raws once to get cty values from hcl, if that's a thing. for i, raw := range raws { // check for cty values and transform them to json then to a @@ -78,7 +78,7 @@ func Decode(target interface{}, config *DecodeOpts, raws ...interface{}) error { if err != nil { return err } - var raw map[string]interface{} + var raw map[string]any if err := json.Unmarshal(b, &raw); err != nil { return err } @@ -220,7 +220,7 @@ func Decode(target interface{}, config *DecodeOpts, raws ...interface{}) error { return nil } -func DetectContextData(raws ...interface{}) (map[interface{}]interface{}, []interface{}) { +func DetectContextData(raws ...any) (map[any]any, []any) { // In provisioners, the last value pulled from raws is the placeholder data // for build-specific variables. Pull these out to add to interpolation // context. @@ -233,7 +233,7 @@ func DetectContextData(raws ...interface{}) (map[interface{}]interface{}, []inte if pd, ok := placeholderData.(map[string]string); ok { if uuid, ok := pd["PackerRunUUID"]; ok { if strings.Contains(uuid, "Build_PackerRunUUID.") { - cast := make(map[interface{}]interface{}) + cast := make(map[any]any) for k, v := range pd { cast[k] = v } @@ -245,7 +245,7 @@ func DetectContextData(raws ...interface{}) (map[interface{}]interface{}, []inte // but with normal interface conversion across the rpc, it'll look like a // map[interface]interface, not a map[string]string - if pd, ok := placeholderData.(map[interface{}]interface{}); ok { + if pd, ok := placeholderData.(map[any]any); ok { if uuid, ok := pd["PackerRunUUID"]; ok { if strings.Contains(uuid.(string), "Build_PackerRunUUID.") { raws = raws[:len(raws)-1] @@ -259,7 +259,7 @@ func DetectContextData(raws ...interface{}) (map[interface{}]interface{}, []inte // DetectContext builds a base interpolate.Context, automatically // detecting things like user variables from the raw configuration params. -func DetectContext(raws ...interface{}) (*interpolate.Context, error) { +func DetectContext(raws ...any) (*interpolate.Context, error) { var s struct { BuildName string `mapstructure:"packer_build_name"` BuildType string `mapstructure:"packer_builder_type"` @@ -286,7 +286,7 @@ func DetectContext(raws ...interface{}) (*interpolate.Context, error) { }, nil } -func uint8ToStringHook(f reflect.Kind, t reflect.Kind, v interface{}) (interface{}, error) { +func uint8ToStringHook(f reflect.Kind, t reflect.Kind, v any) (any, error) { // We need to convert []uint8 to string. We have to do this // because internally Packer uses MsgPack for RPC and the MsgPack // codec turns strings into []uint8 @@ -302,7 +302,7 @@ func uint8ToStringHook(f reflect.Kind, t reflect.Kind, v interface{}) (interface return v, nil } -func stringToTrilean(f reflect.Type, t reflect.Type, v interface{}) (interface{}, error) { +func stringToTrilean(f reflect.Type, t reflect.Type, v any) (any, error) { // We have a custom data type, config, which we read from a string and // then cast to a *bool. Why? So that we can appropriately read "unset" // *bool values in order to intelligently default, even when the values are diff --git a/template/config/decode_test.go b/template/config/decode_test.go index 267f93d4c..ca5b1ffbf 100644 --- a/template/config/decode_test.go +++ b/template/config/decode_test.go @@ -21,13 +21,13 @@ func TestDecode(t *testing.T) { } cases := map[string]struct { - Input []interface{} + Input []any Output *Target Opts *DecodeOpts }{ "basic": { - []interface{}{ - map[string]interface{}{ + []any{ + map[string]any{ "name": "bar", "time": "5s", "trilean": "true", @@ -42,8 +42,8 @@ func TestDecode(t *testing.T) { }, "empty-string-trilean": { - []interface{}{ - map[string]interface{}{ + []any{ + map[string]any{ "trilean": "", }, }, @@ -54,11 +54,11 @@ func TestDecode(t *testing.T) { }, "variables": { - []interface{}{ - map[string]interface{}{ + []any{ + map[string]any{ "name": "{{user `name`}}", }, - map[string]interface{}{ + map[string]any{ "packer_user_variables": map[string]string{ "name": "bar", }, @@ -71,12 +71,12 @@ func TestDecode(t *testing.T) { }, "filter": { - []interface{}{ - map[string]interface{}{ + []any{ + map[string]any{ "name": "{{user `name`}}", "address": "{{user `name`}}", }, - map[string]interface{}{ + map[string]any{ "packer_user_variables": map[string]string{ "name": "bar", }, @@ -95,11 +95,11 @@ func TestDecode(t *testing.T) { }, "build name": { - []interface{}{ - map[string]interface{}{ + []any{ + map[string]any{ "name": "{{build_name}}", }, - map[string]interface{}{ + map[string]any{ "packer_build_name": "foo", }, }, @@ -110,11 +110,11 @@ func TestDecode(t *testing.T) { }, "build type": { - []interface{}{ - map[string]interface{}{ + []any{ + map[string]any{ "name": "{{build_type}}", }, - map[string]interface{}{ + map[string]any{ "packer_builder_type": "foo", }, }, @@ -145,14 +145,14 @@ func TestDecode_fixerRecommendations(t *testing.T) { cases := []struct { Reason string - Input []interface{} + Input []any Opts *DecodeOpts Expected string }{ { Reason: "If no plugin type is provided, don't try to match fixer options", - Input: []interface{}{ - map[string]interface{}{ + Input: []any{ + map[string]any{ "name": "bar", "iso_md5": "13123412341234", }, @@ -162,8 +162,8 @@ func TestDecode_fixerRecommendations(t *testing.T) { }, { Reason: "iso_md5 should always recommend packer fix regardless of plugin type", - Input: []interface{}{ - map[string]interface{}{ + Input: []any{ + map[string]any{ "name": "bar", "iso_md5": "13123412341234", }, @@ -173,8 +173,8 @@ func TestDecode_fixerRecommendations(t *testing.T) { }, { Reason: "filename option should generate a fixer recommendation for the manifest postprocessor", - Input: []interface{}{ - map[string]interface{}{ + Input: []any{ + map[string]any{ "name": "bar", "filename": "fakefilename", }, @@ -184,8 +184,8 @@ func TestDecode_fixerRecommendations(t *testing.T) { }, { Reason: "filename option should generate an unknown key error for other plugins", - Input: []interface{}{ - map[string]interface{}{ + Input: []any{ + map[string]any{ "name": "bar", "filename": "fakefilename", }, diff --git a/template/funcs.go b/template/funcs.go index 41a4cee72..590fae6b2 100644 --- a/template/funcs.go +++ b/template/funcs.go @@ -65,7 +65,7 @@ func Vault(path string, key string) (string, error) { "Original warnings from Vault call: %s", strings.Join(secret.Warnings, "; ")) } - if val, ok := data.(map[string]interface{})[key]; ok { + if val, ok := data.(map[string]any)[key]; ok { return val.(string), nil } return "", errors.New("Vault path does not contain the requested key") diff --git a/template/interpolate/aws/secretsmanager/secretsmanager.go b/template/interpolate/aws/secretsmanager/secretsmanager.go index d7d80e714..26e6ba147 100644 --- a/template/interpolate/aws/secretsmanager/secretsmanager.go +++ b/template/interpolate/aws/secretsmanager/secretsmanager.go @@ -89,7 +89,7 @@ func (c *Client) GetSecret(spec *SecretSpec, raw bool) (string, error) { } func getSecretValue(s *SecretString, spec *SecretSpec, raw bool) (string, error) { - var secretValue map[string]interface{} + var secretValue map[string]any blob := []byte(s.SecretString) //For those plaintext secrets just return the value or if raw is requested @@ -120,7 +120,7 @@ func getSecretValue(s *SecretString, spec *SecretSpec, raw bool) (string, error) return "", fmt.Errorf("No secret found for key %q", spec.Key) } -func getStringSecretValue(v interface{}) (string, error) { +func getStringSecretValue(v any) (string, error) { switch valueType := v.(type) { case string: return valueType, nil diff --git a/template/interpolate/funcs.go b/template/interpolate/funcs.go index 41bf60f4d..2d7125572 100644 --- a/template/interpolate/funcs.go +++ b/template/interpolate/funcs.go @@ -30,7 +30,7 @@ func init() { } // Funcs are the interpolation funcs that are available within interpolations. -var FuncGens = map[string]interface{}{ +var FuncGens = map[string]any{ "build_name": funcGenBuildName, "build_type": funcGenBuildType, "env": funcGenEnv, @@ -61,15 +61,15 @@ var ErrVariableNotSetString = "Error: variable not set:" // FuncGenerator is a function that given a context generates a template // function for the template. -type FuncGenerator func(*Context) interface{} +type FuncGenerator func(*Context) any // Funcs returns the functions that can be used for interpolation given // a context. func Funcs(ctx *Context) template.FuncMap { - result := make(map[string]interface{}) + result := make(map[string]any) for k, v := range FuncGens { switch v := v.(type) { - case func(*Context) interface{}: + case func(*Context) any: result[k] = v(ctx) default: result[k] = v @@ -82,7 +82,7 @@ func Funcs(ctx *Context) template.FuncMap { return template.FuncMap(result) } -func funcGenSplitter(ctx *Context) interface{} { +func funcGenSplitter(ctx *Context) any { return func(k string, s string, i int) (string, error) { // return func(s string) (string, error) { split := strings.Split(k, s) @@ -93,7 +93,7 @@ func funcGenSplitter(ctx *Context) interface{} { } } -func funcGenBuildName(ctx *Context) interface{} { +func funcGenBuildName(ctx *Context) any { return func() (string, error) { if ctx == nil || ctx.BuildName == "" { return "", errors.New("build_name not available") @@ -103,7 +103,7 @@ func funcGenBuildName(ctx *Context) interface{} { } } -func funcGenBuildType(ctx *Context) interface{} { +func funcGenBuildType(ctx *Context) any { return func() (string, error) { if ctx == nil || ctx.BuildType == "" { return "", errors.New("build_type not available") @@ -113,7 +113,7 @@ func funcGenBuildType(ctx *Context) interface{} { } } -func funcGenEnv(ctx *Context) interface{} { +func funcGenEnv(ctx *Context) any { return func(k string) (string, error) { if !ctx.EnableEnv { // The error message doesn't have to be that detailed since @@ -125,7 +125,7 @@ func funcGenEnv(ctx *Context) interface{} { } } -func funcGenIsotime(ctx *Context) interface{} { +func funcGenIsotime(ctx *Context) any { return func(format ...string) (string, error) { if len(format) == 0 { return InitTime.Format(time.RFC3339), nil @@ -139,19 +139,19 @@ func funcGenIsotime(ctx *Context) interface{} { } } -func funcGenStrftime(ctx *Context) interface{} { +func funcGenStrftime(ctx *Context) any { return func(format string) string { return strftime.Format(format, InitTime) } } -func funcGenPwd(ctx *Context) interface{} { +func funcGenPwd(ctx *Context) any { return func() (string, error) { return os.Getwd() } } -func funcGenTemplateDir(ctx *Context) interface{} { +func funcGenTemplateDir(ctx *Context) any { return func() (string, error) { if ctx == nil || ctx.TemplatePath == "" { return "", errors.New("template path not available") @@ -166,7 +166,7 @@ func funcGenTemplateDir(ctx *Context) interface{} { } } -func passthroughOrInterpolate(data map[interface{}]interface{}, s string) (string, error) { +func passthroughOrInterpolate(data map[any]any, s string) (string, error) { if heldPlace, ok := data[s]; ok { if hp, ok := heldPlace.(string); ok { // If we're in the first interpolation pass, the goal is to @@ -182,18 +182,18 @@ func passthroughOrInterpolate(data map[interface{}]interface{}, s string) (strin return "", fmt.Errorf("loaded data, but couldnt find %s in it.", s) } -func funcGenBuild(ctx *Context) interface{} { +func funcGenBuild(ctx *Context) any { // Depending on where the context data is coming from, it could take a few // different map types. The following switch standardizes the map types // so we can act on them correctly. return func(s string) (string, error) { switch data := ctx.Data.(type) { - case map[interface{}]interface{}: + case map[any]any: return passthroughOrInterpolate(data, s) - case map[string]interface{}: + case map[string]any: // convert to a map[interface{}]interface{} so we can use same // parsing on it - passed := make(map[interface{}]interface{}, len(data)) + passed := make(map[any]any, len(data)) for k, v := range data { passed[k] = v } @@ -201,7 +201,7 @@ func funcGenBuild(ctx *Context) interface{} { case map[string]string: // convert to a map[interface{}]interface{} so we can use same // parsing on it - passed := make(map[interface{}]interface{}, len(data)) + passed := make(map[any]any, len(data)) for k, v := range data { passed[k] = v } @@ -213,13 +213,13 @@ func funcGenBuild(ctx *Context) interface{} { } } -func funcGenTimestamp(ctx *Context) interface{} { +func funcGenTimestamp(ctx *Context) any { return func() string { return strconv.FormatInt(InitTime.Unix(), 10) } } -func funcGenUser(ctx *Context) interface{} { +func funcGenUser(ctx *Context) any { return func(k string) (string, error) { if ctx == nil || ctx.UserVariables == nil { return "", errors.New("no user variables are set in the interpolation context") @@ -237,13 +237,13 @@ func funcGenUser(ctx *Context) interface{} { } } -func funcGenUuid(ctx *Context) interface{} { +func funcGenUuid(ctx *Context) any { return func() string { return uuid.TimeOrderedUUID() } } -func funcGenPackerVersion(ctx *Context) interface{} { +func funcGenPackerVersion(ctx *Context) any { return func() (string, error) { if ctx == nil || ctx.CorePackerVersionString == "" { return "", errors.New("packer_version not available") @@ -253,7 +253,7 @@ func funcGenPackerVersion(ctx *Context) interface{} { } } -func funcGenConsul(ctx *Context) interface{} { +func funcGenConsul(ctx *Context) any { return func(key string) (string, error) { if !ctx.EnableEnv { // The error message doesn't have to be that detailed since @@ -265,7 +265,7 @@ func funcGenConsul(ctx *Context) interface{} { } } -func funcGenVault(ctx *Context) interface{} { +func funcGenVault(ctx *Context) any { return func(path string, key string) (string, error) { // Only allow interpolation from Vault when env vars are being read. if !ctx.EnableEnv { @@ -278,7 +278,7 @@ func funcGenVault(ctx *Context) interface{} { } } -func funcGenAwsSecrets(ctx *Context) interface{} { +func funcGenAwsSecrets(ctx *Context) any { return func(secret ...string) (string, error) { if !ctx.EnableEnv { // The error message doesn't have to be that detailed since @@ -305,7 +305,7 @@ func funcGenAwsSecrets(ctx *Context) interface{} { // That is, if the secret is a plaintext, both functions behave the same, // however, if the secret is an object, this will return the raw JSON object // from secrets manager, while the alternative errors without a key being specified. -func funcGenAwsRawSecrets(ctx *Context) interface{} { +func funcGenAwsRawSecrets(ctx *Context) any { return func(secretName string) (string, error) { if !ctx.EnableEnv { return "", errors.New("AWS Secrets Manager is only allowed in the variables section") @@ -314,7 +314,7 @@ func funcGenAwsRawSecrets(ctx *Context) interface{} { } } -func funcGenSed(ctx *Context) interface{} { +func funcGenSed(ctx *Context) any { return func(expression string, inputString string) (string, error) { return "", errors.New("template function `sed` is deprecated " + "use `replace` or `replace_all` instead." + diff --git a/template/interpolate/funcs_test.go b/template/interpolate/funcs_test.go index 1dd9caa91..0bad416b2 100644 --- a/template/interpolate/funcs_test.go +++ b/template/interpolate/funcs_test.go @@ -336,7 +336,7 @@ func TestFuncUser_nilUserVariables(t *testing.T) { func TestFuncPackerBuild(t *testing.T) { type cases struct { - DataMap interface{} + DataMap any ErrExpected bool Template string OutVal string @@ -373,35 +373,35 @@ func TestFuncPackerBuild(t *testing.T) { }, // Data map is a map[interface{}]interface{} and contains value { - DataMap: map[interface{}]interface{}{"PartyVar": "PartyVal"}, + DataMap: map[any]any{"PartyVar": "PartyVal"}, ErrExpected: false, Template: "{{ build `PartyVar` }}", OutVal: "PartyVal", }, // Data map is a map[interface{}]interface{} and contains value { - DataMap: map[interface{}]interface{}{"PartyVar": "PartyVal"}, + DataMap: map[any]any{"PartyVar": "PartyVal"}, ErrExpected: false, Template: "{{ build `PartyVar` }}", OutVal: "PartyVal", }, // Data map is a map[interface{}]interface{} and contains value with placeholder. { - DataMap: map[interface{}]interface{}{"PartyVar": "PartyVal" + packerbuilderdata.PlaceholderMsg}, + DataMap: map[any]any{"PartyVar": "PartyVal" + packerbuilderdata.PlaceholderMsg}, ErrExpected: false, Template: "{{ build `PartyVar` }}", OutVal: "{{.PartyVar}}", }, // Data map is a map[interface{}]interface{} and doesn't have value. { - DataMap: map[interface{}]interface{}{"BadVar": "PartyVal" + packerbuilderdata.PlaceholderMsg}, + DataMap: map[any]any{"BadVar": "PartyVal" + packerbuilderdata.PlaceholderMsg}, ErrExpected: true, Template: "{{ build `MissingVar` }}", OutVal: "", }, // Data map is a map[string]interface and contains value { - DataMap: map[string]interface{}{"PartyVar": "PartyVal"}, + DataMap: map[string]any{"PartyVar": "PartyVal"}, ErrExpected: false, Template: "{{ build `PartyVar` }}", OutVal: "PartyVal", diff --git a/template/interpolate/i.go b/template/interpolate/i.go index b3265c464..713b11cab 100644 --- a/template/interpolate/i.go +++ b/template/interpolate/i.go @@ -16,10 +16,10 @@ import ( // things such as available variables. type Context struct { // Data is the data for the template that is available - Data interface{} + Data any // Funcs are extra functions available in the template - Funcs map[string]interface{} + Funcs map[string]any // UserVariables is the mapping of user variables that the // "user" function reads from. @@ -114,7 +114,7 @@ func (i *I) Render(ictx *Context) (string, error) { } var result bytes.Buffer - var data interface{} + var data any if ictx != nil { data = ictx.Data } diff --git a/template/interpolate/render.go b/template/interpolate/render.go index d01a1dc29..447c04db8 100644 --- a/template/interpolate/render.go +++ b/template/interpolate/render.go @@ -28,9 +28,9 @@ type RenderFilter struct { // interface must decode into a map[string]interface{}, but is left // as an interface{} type to ease backwards compatibility with the way // arguments are passed around in Packer. -func RenderMap(v interface{}, ctx *Context, f *RenderFilter) (map[string]interface{}, error) { +func RenderMap(v any, ctx *Context, f *RenderFilter) (map[string]any, error) { // First decode it into the map - var m map[string]interface{} + var m map[string]any if err := mapstructure.Decode(v, &m); err != nil { return nil, err } @@ -58,7 +58,7 @@ func RenderMap(v interface{}, ctx *Context, f *RenderFilter) (map[string]interfa } // RenderInterface renders any value and returns the resulting value. -func RenderInterface(v interface{}, ctx *Context) (interface{}, error) { +func RenderInterface(v any, ctx *Context) (any, error) { f := func(v string) (string, error) { return RenderOnce(v, ctx) } @@ -79,7 +79,7 @@ func RenderInterface(v interface{}, ctx *Context) (interface{}, error) { } // ValidateInterface renders any value and returns the resulting value. -func ValidateInterface(v interface{}, ctx *Context) error { +func ValidateInterface(v any, ctx *Context) error { f := func(v string) (string, error) { return v, Validate(v, ctx) } @@ -148,14 +148,14 @@ type renderWalker struct { // Top is the top value of the walk. This might get replaced if the // top value needs to be modified. It is valid to read after any walk. // If it is nil, it means the top wasn't replaced. - Top interface{} + Top any key []string lastValue reflect.Value loc reflectwalk.Location cs []reflect.Value csKey []reflect.Value - csData interface{} + csData any sliceIndex int } diff --git a/template/interpolate/render_test.go b/template/interpolate/render_test.go index 3a7ac3f30..f3ab083c3 100644 --- a/template/interpolate/render_test.go +++ b/template/interpolate/render_test.go @@ -14,14 +14,14 @@ func TestRenderInterface(t *testing.T) { } cases := map[string]struct { - Input interface{} - Output interface{} + Input any + Output any }{ "basic": { - map[string]interface{}{ + map[string]any{ "foo": "{{upper `bar`}}", }, - map[string]interface{}{ + map[string]any{ "foo": "BAR", }, }, @@ -51,37 +51,37 @@ func TestRenderInterface(t *testing.T) { func TestRenderMap(t *testing.T) { cases := map[string]struct { - Input interface{} - Output interface{} + Input any + Output any Filter *RenderFilter }{ "basic": { - map[string]interface{}{ + map[string]any{ "foo": "{{upper `bar`}}", }, - map[string]interface{}{ + map[string]any{ "foo": "BAR", }, nil, }, "map keys shouldn't be interpolated": { - map[string]interface{}{ + map[string]any{ "{{foo}}": "{{upper `bar`}}", }, - map[string]interface{}{ + map[string]any{ "{{foo}}": "BAR", }, nil, }, "nested values": { - map[string]interface{}{ + map[string]any{ "foo": map[string]string{ "bar": "{{upper `baz`}}", }, }, - map[string]interface{}{ + map[string]any{ "foo": map[string]string{ "bar": "BAZ", }, @@ -94,12 +94,12 @@ func TestRenderMap(t *testing.T) { // https://github.com/mitchellh/reflectwalk/pull/22/commits/51d4c99fad9e9aa269e874bc3ad60313a574799f // TODO: open a PR to fix it. "nested value keys": { - map[string]interface{}{ + map[string]any{ "foo": map[string]string{ "{{upper `bar`}}": "{{upper `baz`}}", }, }, - map[string]interface{}{ + map[string]any{ "foo": map[string]string{ "BAR": "BAZ", }, @@ -108,13 +108,13 @@ func TestRenderMap(t *testing.T) { }, "filter": { - map[string]interface{}{ + map[string]any{ "bar": "{{upper `baz`}}", "foo": map[string]string{ "{{upper `bar`}}": "{{upper `baz`}}", }, }, - map[string]interface{}{ + map[string]any{ "bar": "BAZ", "foo": map[string]string{ "{{upper `bar`}}": "{{upper `baz`}}", @@ -126,13 +126,13 @@ func TestRenderMap(t *testing.T) { }, "filter case-insensitive": { - map[string]interface{}{ + map[string]any{ "bar": "{{upper `baz`}}", "foo": map[string]string{ "{{upper `bar`}}": "{{upper `baz`}}", }, }, - map[string]interface{}{ + map[string]any{ "bar": "BAZ", "foo": map[string]string{ "{{upper `bar`}}": "{{upper `baz`}}", diff --git a/template/parse.go b/template/parse.go index 5a33aa4d5..1928708ab 100644 --- a/template/parse.go +++ b/template/parse.go @@ -27,14 +27,14 @@ type rawTemplate struct { MinVersion string `mapstructure:"min_packer_version" json:"min_packer_version,omitempty"` Description string `json:"description,omitempty"` - Builders []interface{} `mapstructure:"builders" json:"builders,omitempty"` - Comments []map[string]string `json:"comments,omitempty"` - Push map[string]interface{} `json:"push,omitempty"` - PostProcessors []interface{} `mapstructure:"post-processors" json:"post-processors,omitempty"` - Provisioners []interface{} `json:"provisioners,omitempty"` - CleanupProvisioner interface{} `mapstructure:"error-cleanup-provisioner" json:"error-cleanup-provisioner,omitempty"` - Variables map[string]interface{} `json:"variables,omitempty"` - SensitiveVariables []string `mapstructure:"sensitive-variables" json:"sensitive-variables,omitempty"` + Builders []any `mapstructure:"builders" json:"builders,omitempty"` + Comments []map[string]string `json:"comments,omitempty"` + Push map[string]any `json:"push,omitempty"` + PostProcessors []any `mapstructure:"post-processors" json:"post-processors,omitempty"` + Provisioners []any `json:"provisioners,omitempty"` + CleanupProvisioner any `mapstructure:"error-cleanup-provisioner" json:"error-cleanup-provisioner,omitempty"` + Variables map[string]any `json:"variables,omitempty"` + SensitiveVariables []string `mapstructure:"sensitive-variables" json:"sensitive-variables,omitempty"` RawContents []byte `json:"-"` } @@ -61,7 +61,7 @@ func (r *rawTemplate) MarshalJSON() ([]byte, error) { return json.Marshal(m) } -func (r *rawTemplate) decodeProvisioner(raw interface{}) (Provisioner, error) { +func (r *rawTemplate) decodeProvisioner(raw any) (Provisioner, error) { var p Provisioner if err := r.weakDecoder(&p, nil).Decode(raw); err != nil { return p, fmt.Errorf("Error decoding provisioner: %s", err) @@ -74,7 +74,7 @@ func (r *rawTemplate) decodeProvisioner(raw interface{}) (Provisioner, error) { } // Set the raw configuration and delete any special keys - p.Config = raw.(map[string]interface{}) + p.Config = raw.(map[string]any) delete(p.Config, "except") delete(p.Config, "only") @@ -151,7 +151,7 @@ func (r *rawTemplate) Template() (*Template, error) { } // Set the raw configuration and delete any special keys - b.Config = rawB.(map[string]interface{}) + b.Config = rawB.(map[string]any) delete(b.Config, "name") delete(b.Config, "type") @@ -273,7 +273,7 @@ func (r *rawTemplate) Template() (*Template, error) { } func (r *rawTemplate) decoder( - result interface{}, + result any, md *mapstructure.Metadata) *mapstructure.Decoder { d, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ DecodeHook: mapstructure.StringToTimeDurationHookFunc(), @@ -290,7 +290,7 @@ func (r *rawTemplate) decoder( } func (r *rawTemplate) weakDecoder( - result interface{}, + result any, md *mapstructure.Metadata) *mapstructure.Decoder { d, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ WeaklyTypedInput: true, @@ -308,24 +308,24 @@ func (r *rawTemplate) weakDecoder( } func (r *rawTemplate) parsePostProcessor( - i int, raw interface{}) ([]map[string]interface{}, error) { + i int, raw any) ([]map[string]any, error) { switch v := raw.(type) { case string: - return []map[string]interface{}{ + return []map[string]any{ {"type": v}, }, nil - case map[string]interface{}: - return []map[string]interface{}{v}, nil - case []interface{}: + case map[string]any: + return []map[string]any{v}, nil + case []any: var err error - result := make([]map[string]interface{}, len(v)) + result := make([]map[string]any, len(v)) for j, innerRaw := range v { switch innerV := innerRaw.(type) { case string: - result[j] = map[string]interface{}{"type": innerV} - case map[string]interface{}: + result[j] = map[string]any{"type": innerV} + case map[string]any: result[j] = innerV - case []interface{}: + case []any: err = multierror.Append(err, fmt.Errorf( "post-processor %d.%d: sequence not allowed to be nested in a sequence", i+1, j+1)) @@ -351,7 +351,7 @@ func Parse(r io.Reader) (*Template, error) { // First, decode the object into an interface{} and search for duplicate fields. // We do this instead of the rawTemplate directly because we'd rather use mapstructure to // decode since it has richer errors. - var raw interface{} + var raw any buf, err := jsonUnmarshal(r, &raw) if err != nil { return nil, err @@ -378,7 +378,7 @@ func Parse(r io.Reader) (*Template, error) { if len(md.Unused) > 0 { sort.Strings(md.Unused) - unusedMap, ok := raw.(map[string]interface{}) + unusedMap, ok := raw.(map[string]any) if !ok { return nil, fmt.Errorf("Failed to convert unused root level keys to map") } @@ -410,7 +410,7 @@ func Parse(r io.Reader) (*Template, error) { return rawTpl.Template() } -func jsonUnmarshal(r io.Reader, raw *interface{}) (bytes.Buffer, error) { +func jsonUnmarshal(r io.Reader, raw *any) (bytes.Buffer, error) { // Create a buffer to copy what we read var buf bytes.Buffer if _, err := buf.ReadFrom(r); err != nil { diff --git a/template/parse_test.go b/template/parse_test.go index 822d44128..6c059acc4 100644 --- a/template/parse_test.go +++ b/template/parse_test.go @@ -49,7 +49,7 @@ func TestParse(t *testing.T) { "something": { Name: "something", Type: "something", - Config: map[string]interface{}{ + Config: map[string]any{ "foo": "bar", }, }, @@ -88,7 +88,7 @@ func TestParse(t *testing.T) { Provisioners: []*Provisioner{ { Type: "something", - Config: map[string]interface{}{ + Config: map[string]any{ "inline": "echo 'foo'", }, }, @@ -171,8 +171,8 @@ func TestParse(t *testing.T) { Provisioners: []*Provisioner{ { Type: "something", - Override: map[string]interface{}{ - "foo": map[string]interface{}{}, + Override: map[string]any{ + "foo": map[string]any{}, }, }, }, @@ -220,7 +220,7 @@ func TestParse(t *testing.T) { { Name: "foo", Type: "foo", - Config: map[string]interface{}{ + Config: map[string]any{ "foo": "bar", }, }, @@ -425,7 +425,7 @@ func TestParse(t *testing.T) { "amazon-ebs": { Name: "amazon-ebs", Type: "amazon-ebs", - Config: map[string]interface{}{ + Config: map[string]any{ "ami_name": "AMI Name", "instance_type": "t2.micro", "ssh_username": "ec2-user", @@ -435,7 +435,7 @@ func TestParse(t *testing.T) { "docker": { Name: "docker", Type: "docker", - Config: map[string]interface{}{ + Config: map[string]any{ "image": "ubuntu", "export_path": "image.tar", }, @@ -444,17 +444,17 @@ func TestParse(t *testing.T) { Provisioners: []*Provisioner{ { Type: "shell", - Config: map[string]interface{}{ + Config: map[string]any{ "script": "script.sh", }, }, { Type: "shell", - Config: map[string]interface{}{ + Config: map[string]any{ "script": "script.sh", }, - Override: map[string]interface{}{ - "docker": map[string]interface{}{ + Override: map[string]any{ + "docker": map[string]any{ "execute_command": "echo 'override'", }, }, @@ -478,8 +478,8 @@ func TestParse(t *testing.T) { { Name: "shell-local", Type: "shell-local", - Config: map[string]interface{}{ - "inline": []interface{}{"echo foo"}, + Config: map[string]any{ + "inline": []any{"echo foo"}, }, OnlyExcept: OnlyExcept{ Except: []string{"amazon-ebs"}, diff --git a/template/template.go b/template/template.go index 759751830..aa0d1d816 100644 --- a/template/template.go +++ b/template/template.go @@ -66,7 +66,7 @@ func (t *Template) Raw() (*rawTemplate, error) { for k, v := range t.Variables { if out.Variables == nil { - out.Variables = make(map[string]interface{}) + out.Variables = make(map[string]any) } out.Variables[k] = v @@ -77,9 +77,9 @@ func (t *Template) Raw() (*rawTemplate, error) { // Builder represents a builder configured in the template type Builder struct { - Name string `json:"name,omitempty"` - Type string `json:"type"` - Config map[string]interface{} `json:"config,omitempty"` + Name string `json:"name,omitempty"` + Type string `json:"type"` + Config map[string]any `json:"config,omitempty"` } // MarshalJSON conducts the necessary flattening of the Builder struct @@ -106,10 +106,10 @@ func (b *Builder) MarshalJSON() ([]byte, error) { type PostProcessor struct { OnlyExcept `mapstructure:",squash" json:",omitempty"` - Name string `json:"name,omitempty"` - Type string `json:"type"` - KeepInputArtifact *bool `mapstructure:"keep_input_artifact" json:"keep_input_artifact,omitempty"` - Config map[string]interface{} `json:"config,omitempty"` + Name string `json:"name,omitempty"` + Type string `json:"type"` + KeepInputArtifact *bool `mapstructure:"keep_input_artifact" json:"keep_input_artifact,omitempty"` + Config map[string]any `json:"config,omitempty"` } // MarshalJSON conducts the necessary flattening of the PostProcessor struct @@ -141,12 +141,12 @@ func (p *PostProcessor) MarshalJSON() ([]byte, error) { type Provisioner struct { OnlyExcept `mapstructure:",squash" json:",omitempty"` - Type string `json:"type"` - Config map[string]interface{} `json:"config,omitempty"` - Override map[string]interface{} `json:"override,omitempty"` - PauseBefore time.Duration `mapstructure:"pause_before" json:"pause_before,omitempty"` - MaxRetries string `mapstructure:"max_retries" json:"max_retries,omitempty"` - Timeout time.Duration `mapstructure:"timeout" json:"timeout,omitempty"` + Type string `json:"type"` + Config map[string]any `json:"config,omitempty"` + Override map[string]any `json:"override,omitempty"` + PauseBefore time.Duration `mapstructure:"pause_before" json:"pause_before,omitempty"` + MaxRetries string `mapstructure:"max_retries" json:"max_retries,omitempty"` + Timeout time.Duration `mapstructure:"timeout" json:"timeout,omitempty"` } // MarshalJSON conducts the necessary flattening of the Provisioner struct diff --git a/template/template.hcl2spec.go b/template/template.hcl2spec.go index d86915dcd..03130bc2e 100644 --- a/template/template.hcl2spec.go +++ b/template/template.hcl2spec.go @@ -10,14 +10,14 @@ import ( // FlatProvisioner is an auto-generated flat version of Provisioner. // Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. type FlatProvisioner struct { - Only []string `json:"only,omitempty" cty:"only" hcl:"only"` - Except []string `json:"except,omitempty" cty:"except" hcl:"except"` - Type *string `json:"type" cty:"type" hcl:"type"` - Config map[string]interface{} `json:"config,omitempty" cty:"config" hcl:"config"` - Override map[string]interface{} `json:"override,omitempty" cty:"override" hcl:"override"` - PauseBefore *string `mapstructure:"pause_before" json:"pause_before,omitempty" cty:"pause_before" hcl:"pause_before"` - MaxRetries *string `mapstructure:"max_retries" json:"max_retries,omitempty" cty:"max_retries" hcl:"max_retries"` - Timeout *string `mapstructure:"timeout" json:"timeout,omitempty" cty:"timeout" hcl:"timeout"` + Only []string `json:"only,omitempty" cty:"only" hcl:"only"` + Except []string `json:"except,omitempty" cty:"except" hcl:"except"` + Type *string `json:"type" cty:"type" hcl:"type"` + Config map[string]any `json:"config,omitempty" cty:"config" hcl:"config"` + Override map[string]any `json:"override,omitempty" cty:"override" hcl:"override"` + PauseBefore *string `mapstructure:"pause_before" json:"pause_before,omitempty" cty:"pause_before" hcl:"pause_before"` + MaxRetries *string `mapstructure:"max_retries" json:"max_retries,omitempty" cty:"max_retries" hcl:"max_retries"` + Timeout *string `mapstructure:"timeout" json:"timeout,omitempty" cty:"timeout" hcl:"timeout"` } // FlatMapstructure returns a new FlatProvisioner.