Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOISSUE - Add LoRa route map validation and fix LoRa messages URL #491

Merged
merged 7 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/addons/lora-adapter/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
MF_LORA_ADAPTER_LOG_LEVEL: debug
MF_THINGS_ES_URL: things-redis:6379
MF_LORA_ADAPTER_ROUTEMAP_URL: lora-redis:6379
MF_LORA_ADAPTER_LORA_MESSAGE_URL: tcp://159.65.205.240:1883
MF_LORA_ADAPTER_LORA_MESSAGE_URL: tcp://mainflux.io:1883
MF_LORA_ADAPTER_HTTP_PORT: 8187
MF_NATS_URL: nats://nats:4222
ports:
Expand Down
31 changes: 27 additions & 4 deletions lora/redis/streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ const (
channelRemove = channelPrefix + "remove"
)

var (
// ErrMetadataType indicates an ivalid metadata type.
ErrMetadataType = errors.New("metadatada is not of type lora")

// ErrMetadataAppID indicates a missing application ID in channel metadata.
ErrMetadataAppID = errors.New("application ID not found in channel metadatada")

// ErrMetadataDevEUI indicates a missing device EUI in thing metadata.
ErrMetadataDevEUI = errors.New("device EUI not found in channel metadatada")
)

// EventStore represents event source for things and channels provisioning.
type EventStore interface {
// Subscribes to geven subject and receives events.
Expand Down Expand Up @@ -155,7 +166,10 @@ func (es eventStore) handleCreateThing(cte createThingEvent) error {
}

if em.Type != protocol {
return errors.New("Lora protocol not found in thing metadatada")
return ErrMetadataType
}
if em.DevEUI != "" {
return ErrMetadataDevEUI
}

return es.svc.CreateThing(cte.id, em.DevEUI)
Expand All @@ -168,7 +182,10 @@ func (es eventStore) handleUpdateThing(ute updateThingEvent) error {
}

if em.Type != protocol {
return errors.New("Lora protocol not found in thing metadatada")
return ErrMetadataType
}
if em.DevEUI != "" {
return ErrMetadataDevEUI
}

return es.svc.CreateThing(ute.id, em.DevEUI)
Expand All @@ -185,7 +202,10 @@ func (es eventStore) handleCreateChannel(cce createChannelEvent) error {
}

if cm.Type != protocol {
return errors.New("Lora protocol not found in channel metadatada")
return ErrMetadataType
}
if cm.AppID != "" {
return ErrMetadataAppID
}

return es.svc.CreateChannel(cce.id, cm.AppID)
Expand All @@ -198,7 +218,10 @@ func (es eventStore) handleUpdateChannel(uce updateChannelEvent) error {
}

if cm.Type != protocol {
return errors.New("Lora protocol not found in channel metadatada")
return ErrMetadataType
}
if cm.AppID != "" {
return ErrMetadataAppID
}

return es.svc.UpdateChannel(uce.id, cm.AppID)
Expand Down
4 changes: 2 additions & 2 deletions lora/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ var (
ErrMalformedMessage = errors.New("malformed message received")

// ErrNotFoundDev indicates a non-existent route map for a device EUI.
ErrNotFoundDev = errors.New("route map not found for device EUI")
ErrNotFoundDev = errors.New("route map not found for this device EUI")

// ErrNotFoundApp indicates a non-existent route map for an application ID.
ErrNotFoundApp = errors.New("route map not found for application ID")
ErrNotFoundApp = errors.New("route map not found for this application ID")
)

// Service specifies an API that must be fullfiled by the domain service
Expand Down