Skip to content

Commit 274d201

Browse files
authored
Merge pull request #204 from TheThingsNetwork/fix/tts-8558-strip-ids-dev-addr
Strip dev_addr from ids in TTS exporter
2 parents 5f3093d + 762abd8 commit 274d201

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@
2020

2121
# macOS related
2222
*.DS_store
23+
24+
# Go
25+
**/vendor/*

CHANGELOG.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1818

1919
### Fixed
2020

21+
- Strip ids.dev_addr from exported devices
22+
2123
## [v0.12.0] (2024-03-13)
2224

2325
### Added
@@ -145,6 +147,3 @@ NOTE: These links should respect backports. See https://github.com/TheThingsNetw
145147
-->
146148

147149
[unreleased]: https://github.com/TheThingsNetwork/lorawan-stack-migrate/v0.7.0...master
148-
[0.7.0]: https://github.com/TheThingsNetwork/lorawan-stack-migrate/compare/v0.6.0...v0.7.0
149-
[0.6.0]: https://github.com/TheThingsNetwork/lorawan-stack-migrate/compare/v0.5.0...v0.6.0
150-
[0.5.0]: https://github.com/TheThingsNetwork/lorawan-stack-migrate/compare/v0.4.0...v0.5.0

pkg/source/tts/source.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,15 @@ func (s Source) ExportDevice(devID string) (*ttnpb.EndDevice, error) {
7373
if err := validateDeviceIds(dev.Ids, res.Ids); err != nil {
7474
return nil, err
7575
}
76-
paths := ttnpb.AddFields(nsPaths, ttnpb.AddFields(asPaths, ttnpb.AddFields(jsPaths, "ids.dev_addr")...)...)
76+
paths := ttnpb.AddFields(nsPaths, ttnpb.AddFields(asPaths, jsPaths...)...)
7777
if err := dev.SetFields(res, paths...); err != nil {
7878
return nil, err
7979
}
80+
// Clear ids.dev_addr (denormalized session state) so the export can be
81+
// re-imported via the CLI; session.dev_addr remains the source of truth.
82+
if dev.Ids != nil {
83+
dev.Ids.DevAddr = nil
84+
}
8085
// Clear all "{server}_address" fields from exported device
8186
if err := dev.SetFields(nil, "application_server_address", "join_server_address", "network_server_address"); err != nil {
8287
return nil, err
@@ -108,7 +113,10 @@ func (s Source) ExportDevice(devID string) (*ttnpb.EndDevice, error) {
108113
}
109114

110115
// Iterator implements source.Source.
111-
func (s Source) Iterator(bool) iterator.Iterator {
116+
func (s Source) Iterator(isApplication bool) iterator.Iterator {
117+
if isApplication && s.config.AppID != "" {
118+
return iterator.NewListIterator([]string{s.config.AppID})
119+
}
112120
return iterator.NewReaderIterator(os.Stdin, '\n')
113121
}
114122

0 commit comments

Comments
 (0)