Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix of issue, now unsetting can be done passing "nil" to appengine devices send-data

Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
  • Loading branch information
eddbbt committed Nov 17, 2023
1 parent da15c68 commit 8f29348
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions cmd/appengine/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -1079,14 +1079,25 @@ func devicesSendDataF(command *cobra.Command, args []string) error {
}

var parsedPayloadData interface{}

fmt.Println(payloadData)

if err := payloadType.IsValid(); err == nil {
if parsedPayloadData, err = parseSendDataPayload(payloadData, payloadType); err != nil {

if payloadData == "nil" {
parsedPayloadData = nil
}else{
if parsedPayloadData, err = parseSendDataPayload(payloadData, payloadType); err != nil {
return err
}
}


} else {
// We have to treat it as an aggregate.
aggrPayload := map[string]interface{}{}
if err := json.Unmarshal([]byte(payloadData), &aggrPayload); err != nil {
fmt.Println("A")
return err
}

Expand All @@ -1099,6 +1110,7 @@ func devicesSendDataF(command *cobra.Command, args []string) error {
fullPath := fmt.Sprintf("%s/%s", interfacePath, k)
mapping, err := interfaces.InterfaceMappingFromPath(iface, fullPath)
if err != nil {
fmt.Println("B")
return err
}

Expand Down Expand Up @@ -1148,8 +1160,16 @@ func devicesSendDataF(command *cobra.Command, args []string) error {
var sendDataCall client.AstarteRequest

if !skipRealmManagementChecks {
// We can delegate the entirety of this to astarte-go
sendDataCall, err = astarteAPIClient.SendData(realm, deviceID, deviceIdentifierType, iface, interfacePath, parsedPayloadData)

if parsedPayloadData==nil {
// We can delegate the entirety of this to astarte-go
sendDataCall, err = astarteAPIClient.UnsetProperty(realm, deviceID, deviceIdentifierType, interfaceName, interfacePath)
}else{
// We can delegate the entirety of this to astarte-go
sendDataCall, err = astarteAPIClient.SendData(realm, deviceID, deviceIdentifierType, iface, interfacePath, parsedPayloadData)
}


} else {
// Don't risk it. Use raw functions and trust the server to fail, in case.
switch interfaceTypeString {
Expand Down

0 comments on commit 8f29348

Please sign in to comment.