diff --git a/pkg/commands/export.go b/pkg/commands/export.go index 7f0c0c0..2bfc66d 100644 --- a/pkg/commands/export.go +++ b/pkg/commands/export.go @@ -38,7 +38,7 @@ func Export(cmd *cobra.Command, args []string, f func(s source.Source, item stri var iter iterator.Iterator switch len(args) { case 0: - iter = s.Iterator() + iter = s.Iterator(cmd.Name() == "application") default: iter = iterator.NewListIterator(args) } diff --git a/pkg/source/chirpstack/source.go b/pkg/source/chirpstack/source.go index 4e5350f..b8c1a8e 100644 --- a/pkg/source/chirpstack/source.go +++ b/pkg/source/chirpstack/source.go @@ -81,7 +81,7 @@ func createNewSource(cfg *config.Config) source.CreateSource { } // Iterator implements source.Source. -func (s Source) Iterator() iterator.Iterator { +func (s Source) Iterator(bool) iterator.Iterator { return iterator.NewReaderIterator(os.Stdin, '\n') } diff --git a/pkg/source/firefly/source.go b/pkg/source/firefly/source.go index d6353e7..2645b75 100644 --- a/pkg/source/firefly/source.go +++ b/pkg/source/firefly/source.go @@ -16,6 +16,7 @@ package firefly import ( "context" + "os" "github.com/TheThingsNetwork/go-utils/random" "go.thethings.network/lorawan-stack/v3/pkg/networkserver/mac" @@ -52,7 +53,10 @@ func createNewSource(cfg *Config) source.CreateSource { } // Iterator implements source.Source. -func (s Source) Iterator() iterator.Iterator { +func (s Source) Iterator(isApplication bool) iterator.Iterator { + if !isApplication { + return iterator.NewReaderIterator(os.Stdin, '\n') + } if s.all { // The Firefly LNS does not group devices by an application. // When the "all" flag is set, we get all devices accessible by the API key. @@ -84,7 +88,6 @@ func (s Source) ExportDevice(devEUIString string) (*ttnpb.EndDevice, error) { if err := joinEUI.UnmarshalText([]byte(s.joinEUI)); err != nil { return nil, err } - v3dev := &ttnpb.EndDevice{ Name: ffdev.Name, Description: ffdev.Description, @@ -102,7 +105,6 @@ func (s Source) ExportDevice(devEUIString string) (*ttnpb.EndDevice, error) { LorawanVersion: s.derivedMacVersion, LorawanPhyVersion: s.derivedPhyVersion, } - if ffdev.Location != nil { v3dev.Locations = map[string]*ttnpb.Location{ "user": { @@ -136,10 +138,10 @@ func (s Source) ExportDevice(devEUIString string) (*ttnpb.EndDevice, error) { if err != nil { return nil, err } - // This cannot be empty - v3dev.Session.StartedAt = timestamppb.Now() - v3dev.Session.Keys.SessionKeyId = random.Bytes(16) - + if v3dev.SupportsJoin { + v3dev.Session.StartedAt = timestamppb.Now() + v3dev.Session.Keys.SessionKeyId = random.Bytes(16) + } v3dev.Session.Keys.AppSKey.Key, err = util.UnmarshalTextToBytes(&types.AES128Key{}, ffdev.ApplicationSessionKey) if err != nil { return nil, err diff --git a/pkg/source/source.go b/pkg/source/source.go index af1eccc..2de5849 100644 --- a/pkg/source/source.go +++ b/pkg/source/source.go @@ -57,7 +57,7 @@ type Source interface { // Close cleans up and terminates any open connections. Close() error // Iterator returns an iterator for devices. - Iterator() iterator.Iterator + Iterator(isApplication bool) iterator.Iterator } // CreateSource is a function that constructs a new Source. diff --git a/pkg/source/ttnv2/source.go b/pkg/source/ttnv2/source.go index aeb931a..ebd666e 100644 --- a/pkg/source/ttnv2/source.go +++ b/pkg/source/ttnv2/source.go @@ -194,7 +194,7 @@ func (s *Source) ExportDevice(devID string) (*ttnpb.EndDevice, error) { } // Iterator implements source.Source. -func (s *Source) Iterator() iterator.Iterator { +func (s *Source) Iterator(bool) iterator.Iterator { return iterator.NewReaderIterator(os.Stdin, '\n') } diff --git a/pkg/source/tts/source.go b/pkg/source/tts/source.go index 8258534..ae2940a 100644 --- a/pkg/source/tts/source.go +++ b/pkg/source/tts/source.go @@ -124,7 +124,7 @@ func (s Source) ExportDevice(devID string) (*ttnpb.EndDevice, error) { } // Iterator implements source.Source. -func (s Source) Iterator() iterator.Iterator { +func (s Source) Iterator(bool) iterator.Iterator { return iterator.NewReaderIterator(os.Stdin, '\n') }