Skip to content

Commit 0d83a61

Browse files
authored
feat: migrate mapstructure lib to new fork (#5354)
* feat: migrate mapstructure lib to new fork the original mapstructure library has been archived and it is no longer being developed. A fork has been created and bumped to a new major version. Migrate to the new fork and update imports and tests. The Error public type has been removed and the library is using error wrapping. * lint: fix linter issues
1 parent a9de876 commit 0d83a61

File tree

9 files changed

+76
-89
lines changed

9 files changed

+76
-89
lines changed

NOTICE.txt

+62-62
Original file line numberDiff line numberDiff line change
@@ -3040,6 +3040,37 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30403040
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30413041

30423042

3043+
--------------------------------------------------------------------------------
3044+
Dependency : github.com/go-viper/mapstructure/v2
3045+
Version: v2.1.0
3046+
Licence type (autodetected): MIT
3047+
--------------------------------------------------------------------------------
3048+
3049+
Contents of probable licence file $GOMODCACHE/github.com/go-viper/mapstructure/v2@v2.1.0/LICENSE:
3050+
3051+
The MIT License (MIT)
3052+
3053+
Copyright (c) 2013 Mitchell Hashimoto
3054+
3055+
Permission is hereby granted, free of charge, to any person obtaining a copy
3056+
of this software and associated documentation files (the "Software"), to deal
3057+
in the Software without restriction, including without limitation the rights
3058+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3059+
copies of the Software, and to permit persons to whom the Software is
3060+
furnished to do so, subject to the following conditions:
3061+
3062+
The above copyright notice and this permission notice shall be included in
3063+
all copies or substantial portions of the Software.
3064+
3065+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3066+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3067+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3068+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3069+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3070+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3071+
THE SOFTWARE.
3072+
3073+
30433074
--------------------------------------------------------------------------------
30443075
Dependency : github.com/gofrs/flock
30453076
Version: v0.8.1
@@ -3932,37 +3963,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39323963
THE SOFTWARE.
39333964

39343965

3935-
--------------------------------------------------------------------------------
3936-
Dependency : github.com/mitchellh/mapstructure
3937-
Version: v1.5.1-0.20231216201459-8508981c8b6c
3938-
Licence type (autodetected): MIT
3939-
--------------------------------------------------------------------------------
3940-
3941-
Contents of probable licence file $GOMODCACHE/github.com/mitchellh/mapstructure@v1.5.1-0.20231216201459-8508981c8b6c/LICENSE:
3942-
3943-
The MIT License (MIT)
3944-
3945-
Copyright (c) 2013 Mitchell Hashimoto
3946-
3947-
Permission is hereby granted, free of charge, to any person obtaining a copy
3948-
of this software and associated documentation files (the "Software"), to deal
3949-
in the Software without restriction, including without limitation the rights
3950-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3951-
copies of the Software, and to permit persons to whom the Software is
3952-
furnished to do so, subject to the following conditions:
3953-
3954-
The above copyright notice and this permission notice shall be included in
3955-
all copies or substantial portions of the Software.
3956-
3957-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3958-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3959-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3960-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3961-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3962-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3963-
THE SOFTWARE.
3964-
3965-
39663966
--------------------------------------------------------------------------------
39673967
Dependency : github.com/oklog/ulid/v2
39683968
Version: v2.1.0
@@ -24901,37 +24901,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2490124901
THE SOFTWARE.
2490224902

2490324903

24904-
--------------------------------------------------------------------------------
24905-
Dependency : github.com/go-viper/mapstructure/v2
24906-
Version: v2.0.0
24907-
Licence type (autodetected): MIT
24908-
--------------------------------------------------------------------------------
24909-
24910-
Contents of probable licence file $GOMODCACHE/github.com/go-viper/mapstructure/v2@v2.0.0/LICENSE:
24911-
24912-
The MIT License (MIT)
24913-
24914-
Copyright (c) 2013 Mitchell Hashimoto
24915-
24916-
Permission is hereby granted, free of charge, to any person obtaining a copy
24917-
of this software and associated documentation files (the "Software"), to deal
24918-
in the Software without restriction, including without limitation the rights
24919-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
24920-
copies of the Software, and to permit persons to whom the Software is
24921-
furnished to do so, subject to the following conditions:
24922-
24923-
The above copyright notice and this permission notice shall be included in
24924-
all copies or substantial portions of the Software.
24925-
24926-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24927-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24928-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24929-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24930-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24931-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24932-
THE SOFTWARE.
24933-
24934-
2493524904
--------------------------------------------------------------------------------
2493624905
Dependency : github.com/go-zookeeper/zk
2493724906
Version: v1.0.3
@@ -37996,6 +37965,37 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3799637965
THE SOFTWARE.
3799737966

3799837967

37968+
--------------------------------------------------------------------------------
37969+
Dependency : github.com/mitchellh/mapstructure
37970+
Version: v1.5.1-0.20231216201459-8508981c8b6c
37971+
Licence type (autodetected): MIT
37972+
--------------------------------------------------------------------------------
37973+
37974+
Contents of probable licence file $GOMODCACHE/github.com/mitchellh/mapstructure@v1.5.1-0.20231216201459-8508981c8b6c/LICENSE:
37975+
37976+
The MIT License (MIT)
37977+
37978+
Copyright (c) 2013 Mitchell Hashimoto
37979+
37980+
Permission is hereby granted, free of charge, to any person obtaining a copy
37981+
of this software and associated documentation files (the "Software"), to deal
37982+
in the Software without restriction, including without limitation the rights
37983+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
37984+
copies of the Software, and to permit persons to whom the Software is
37985+
furnished to do so, subject to the following conditions:
37986+
37987+
The above copyright notice and this permission notice shall be included in
37988+
all copies or substantial portions of the Software.
37989+
37990+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37991+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37992+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37993+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37994+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37995+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
37996+
THE SOFTWARE.
37997+
37998+
3799937999
--------------------------------------------------------------------------------
3800038000
Dependency : github.com/mitchellh/reflectwalk
3800138001
Version: v1.0.2

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ require (
2525
github.com/elastic/opentelemetry-collector-components/processor/elasticinframetricsprocessor v0.9.0
2626
github.com/fatih/color v1.16.0
2727
github.com/fsnotify/fsnotify v1.7.0
28+
github.com/go-viper/mapstructure/v2 v2.1.0
2829
github.com/gofrs/flock v0.8.1
2930
github.com/gofrs/uuid/v5 v5.2.0
3031
github.com/google/go-cmp v0.6.0
@@ -37,7 +38,6 @@ require (
3738
github.com/kardianos/service v1.2.1-0.20210728001519-a323c3813bc7
3839
github.com/magefile/mage v1.15.0
3940
github.com/mitchellh/hashstructure v1.1.0
40-
github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c
4141
github.com/oklog/ulid/v2 v2.1.0
4242
github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension v0.106.1
4343
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver v0.106.1
@@ -182,7 +182,6 @@ require (
182182
github.com/go-openapi/jsonreference v0.20.4 // indirect
183183
github.com/go-openapi/swag v0.22.9 // indirect
184184
github.com/go-resty/resty/v2 v2.13.1 // indirect
185-
github.com/go-viper/mapstructure/v2 v2.0.0 // indirect
186185
github.com/go-zookeeper/zk v1.0.3 // indirect
187186
github.com/gobuffalo/here v0.6.7 // indirect
188187
github.com/gobwas/glob v0.2.3 // indirect
@@ -255,6 +254,7 @@ require (
255254
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
256255
github.com/mitchellh/copystructure v1.2.0 // indirect
257256
github.com/mitchellh/go-homedir v1.1.0 // indirect
257+
github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c // indirect
258258
github.com/mitchellh/reflectwalk v1.0.2 // indirect
259259
github.com/moby/docker-image-spec v1.3.1 // indirect
260260
github.com/moby/spdystream v0.2.0 // indirect

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -915,8 +915,8 @@ github.com/go-resty/resty/v2 v2.13.1/go.mod h1:GznXlLxkq6Nh4sU59rPmUw3VtgpO3aS96
915915
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
916916
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
917917
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
918-
github.com/go-viper/mapstructure/v2 v2.0.0 h1:dhn8MZ1gZ0mzeodTG3jt5Vj/o87xZKuNAprG2mQfMfc=
919-
github.com/go-viper/mapstructure/v2 v2.0.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
918+
github.com/go-viper/mapstructure/v2 v2.1.0 h1:gHnMa2Y/pIxElCH2GlZZ1lZSsn6XMtufpGyP1XxdC/w=
919+
github.com/go-viper/mapstructure/v2 v2.1.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
920920
github.com/go-zookeeper/zk v1.0.3 h1:7M2kwOsc//9VeeFiPtf+uSJlVpU66x9Ba5+8XK7/TDg=
921921
github.com/go-zookeeper/zk v1.0.3/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw=
922922
github.com/gobuffalo/here v0.6.0/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PLa8Y5fM=

internal/pkg/agent/protection/config_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ package protection
77
import (
88
"testing"
99

10+
"github.com/go-viper/mapstructure/v2"
1011
"github.com/google/go-cmp/cmp"
11-
"github.com/mitchellh/mapstructure"
1212
)
1313

1414
func TestConfigDeserializer(t *testing.T) {

internal/pkg/agent/protection/policy.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
"github.com/elastic/elastic-agent/pkg/core/logger"
1414

15-
"github.com/mitchellh/mapstructure"
15+
"github.com/go-viper/mapstructure/v2"
1616
)
1717

1818
var (
@@ -166,12 +166,12 @@ func getPolicySignedDataAndSignature(policy map[string]interface{}) (data, signa
166166

167167
data, err = getBytes(signed, "data")
168168
if err != nil {
169-
return
169+
return nil, nil, err
170170
}
171171

172172
signature, err = getBytes(signed, "signature")
173173
if err != nil {
174-
return
174+
return nil, nil, err
175175
}
176176

177177
return data, signature, err

internal/pkg/fleetapi/action.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"strings"
1111
"time"
1212

13-
"github.com/mitchellh/mapstructure"
13+
"github.com/go-viper/mapstructure/v2"
1414

1515
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
1616
)

pkg/component/component_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ func TestToComponents(t *testing.T) {
634634
ID: "filestream-default-filestream-1",
635635
Type: client.UnitTypeInput,
636636
LogLevel: defaultUnitLogLevel,
637-
Err: errors.New("1 decoding error(s): 'meta' expected a map, got 'slice'"),
637+
Err: fmt.Errorf("decoding error: %w", fmt.Errorf("decoding failed due to the following error(s):\n\n%w", errors.Join(errors.New("'meta' expected a map, got 'slice'")))),
638638
},
639639
},
640640
},
@@ -722,7 +722,7 @@ func TestToComponents(t *testing.T) {
722722
ID: "cloudbeat-default-cloudbeat-1-unit",
723723
Type: client.UnitTypeInput,
724724
LogLevel: defaultUnitLogLevel,
725-
Err: errors.New("1 decoding error(s): 'meta' expected a map, got 'slice'"),
725+
Err: fmt.Errorf("decoding error: %w", fmt.Errorf("decoding failed due to the following error(s):\n\n%w", errors.Join(errors.New("'meta' expected a map, got 'slice'")))),
726726
},
727727
},
728728
},

pkg/component/config.go

+2-15
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"reflect"
1212
"strings"
1313

14-
"github.com/mitchellh/mapstructure"
14+
"github.com/go-viper/mapstructure/v2"
1515
"google.golang.org/protobuf/types/known/structpb"
1616

1717
"github.com/elastic/elastic-agent-client/v7/pkg/proto"
@@ -94,7 +94,7 @@ func ExpectedConfig(cfg map[string]interface{}) (*proto.UnitExpectedConfig, erro
9494
}
9595

9696
if err := decoder.Decode(cfg); err != nil {
97-
return nil, rewrapErr(err)
97+
return nil, fmt.Errorf("decoding error: %w", err)
9898
}
9999

100100
if err := setSource(result, cfg); err != nil {
@@ -276,16 +276,3 @@ func getJSONFieldName(field reflect.StructField) string {
276276
split := strings.Split(tag, ",")
277277
return strings.TrimSpace(split[0])
278278
}
279-
280-
func rewrapErr(err error) error {
281-
var me *mapstructure.Error
282-
if !errors.As(err, &me) {
283-
return err
284-
}
285-
errs := me.WrappedErrors()
286-
points := make([]string, 0, len(errs))
287-
for _, e := range errs {
288-
points = append(points, e.Error())
289-
}
290-
return fmt.Errorf("%d decoding error(s): %s", len(errs), strings.Join(points, ", "))
291-
}

pkg/component/config_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func TestExpectedConfig(t *testing.T) {
183183
},
184184
},
185185
},
186-
Err: errors.New("1 decoding error(s): 'meta' expected a map, got 'slice'"),
186+
Err: errors.New("decoding error: decoding failed due to the following error(s):\n\n'meta' expected a map, got 'slice'"),
187187
},
188188
}
189189

0 commit comments

Comments
 (0)