diff --git a/app/importer/importer.go b/app/exporter/exporter.go similarity index 92% rename from app/importer/importer.go rename to app/exporter/exporter.go index a47bff8..d945273 100755 --- a/app/importer/importer.go +++ b/app/exporter/exporter.go @@ -13,7 +13,7 @@ // Arduino software without disclosing the source code of your own applications. // To purchase a commercial license, send an email to license@arduino.cc. -package importer +package exporter import ( "context" @@ -28,7 +28,7 @@ import ( "github.com/sirupsen/logrus" ) -func StartImport(ctx context.Context, logger *logrus.Entry, key, secret, orgid string, tagsF *string, resolution, timeWindowMinutes int, destinationS3Bucket string, aggregationStat string, compress bool) error { +func StartExporter(ctx context.Context, logger *logrus.Entry, key, secret, orgid string, tagsF *string, resolution, timeWindowMinutes int, destinationS3Bucket string, aggregationStat string, compress bool) error { // Init client iotcl, err := iot.NewClient(key, secret, orgid) diff --git a/business/tsextractor/tsextractor.go b/business/tsextractor/tsextractor.go index 4874cec..412a536 100755 --- a/business/tsextractor/tsextractor.go +++ b/business/tsextractor/tsextractor.go @@ -17,6 +17,7 @@ package tsextractor import ( "context" + "encoding/json" "fmt" "strconv" "strings" @@ -309,7 +310,7 @@ func (a *TsExtractor) populateStringTSDataIntoS3( if value == nil { continue } - samples = append(samples, composeRow(ts, thingID, thing.Name, propertyID, propertyName, propertyType, interfaceToString(value), "")) + samples = append(samples, composeRow(ts, thingID, thing.Name, propertyID, propertyName, propertyType, a.interfaceToString(value), "")) } } @@ -369,7 +370,7 @@ func (a *TsExtractor) populateRawTSDataIntoS3( if value == nil { continue } - samples = append(samples, composeRawRow(ts, thingID, thing.Name, propertyID, propertyName, propertyType, interfaceToString(value))) + samples = append(samples, composeRawRow(ts, thingID, thing.Name, propertyID, propertyName, propertyType, a.interfaceToString(value))) } } @@ -384,7 +385,7 @@ func (a *TsExtractor) populateRawTSDataIntoS3( return nil } -func interfaceToString(value interface{}) string { +func (a *TsExtractor) interfaceToString(value interface{}) string { switch v := value.(type) { case string: return v @@ -394,6 +395,13 @@ func interfaceToString(value interface{}) string { return strconv.FormatFloat(v, 'f', -1, 64) case bool: return strconv.FormatBool(v) + case map[string]any: + encoded, err := json.Marshal(v) + if err != nil { + a.logger.Error("Error encoding map to json: ", err) + return fmt.Sprintf("%v", v) + } + return string(encoded) default: return fmt.Sprintf("%v", v) } diff --git a/lambda.go b/lambda.go index f6a6cbb..fecf6be 100755 --- a/lambda.go +++ b/lambda.go @@ -20,7 +20,7 @@ import ( "errors" "os" - "github.com/arduino/aws-s3-integration/app/importer" + "github.com/arduino/aws-s3-integration/app/exporter" "github.com/arduino/aws-s3-integration/internal/parameters" "github.com/aws/aws-lambda-go/lambda" "github.com/sirupsen/logrus" @@ -177,7 +177,7 @@ func HandleRequest(ctx context.Context, event *AWSS3ImportTrigger) (*string, err logger.Infoln("data extraction time windows:", extractionWindowMinutes, "minutes") logger.Infoln("file compression enabled:", enabledCompression) - err = importer.StartImport(ctx, logger, *apikey, *apiSecret, organizationId, tags, *resolution, *extractionWindowMinutes, *destinationS3Bucket, *aggregationStat, enabledCompression) + err = exporter.StartExporter(ctx, logger, *apikey, *apiSecret, organizationId, tags, *resolution, *extractionWindowMinutes, *destinationS3Bucket, *aggregationStat, enabledCompression) if err != nil { return nil, err } diff --git a/resources/test/localexecution.go b/resources/test/localexecution.go index 2c5dd2a..c2ef272 100644 --- a/resources/test/localexecution.go +++ b/resources/test/localexecution.go @@ -5,7 +5,7 @@ import ( "errors" "os" - "github.com/arduino/aws-s3-integration/app/importer" + "github.com/arduino/aws-s3-integration/app/exporter" "github.com/arduino/aws-s3-integration/internal/parameters" "github.com/sirupsen/logrus" ) @@ -89,7 +89,7 @@ func HandleRequest(ctx context.Context, dev bool) (*string, error) { logger.Infoln("tags:", *tags) } - err = importer.StartImport(ctx, logger, *apikey, *apiSecret, organizationId, tags, *resolution, TimeExtractionWindowMinutes, *destinationS3Bucket, "MAX", true) + err = exporter.StartExporter(ctx, logger, *apikey, *apiSecret, organizationId, tags, *resolution, TimeExtractionWindowMinutes, *destinationS3Bucket, "MAX", true) if err != nil { return nil, err }