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

refactor(sdk): change all factory methods and receiver functions to u… #1261

Merged
merged 1 commit into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions pkg/transforms/aesprotection.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ type AESProtection struct {

// NewAESProtection creates, initializes and returns a new instance of AESProtection configured
// to retrieve the encryption key from the Secret Store
func NewAESProtection(secretPath string, secretName string) AESProtection {
return AESProtection{
func NewAESProtection(secretPath string, secretName string) *AESProtection {
return &AESProtection{
SecretPath: secretPath,
SecretName: secretName,
}
Expand All @@ -46,7 +46,7 @@ func NewAESProtection(secretPath string, secretName string) AESProtection {
// Encrypt encrypts a string, []byte, or json.Marshaller type using AES 256 encryption.
// It also signs the data using a SHA512 hash.
// It will return a Base64 encode []byte of the encrypted data.
func (protection AESProtection) Encrypt(ctx interfaces.AppFunctionContext, data interface{}) (bool, interface{}) {
func (protection *AESProtection) Encrypt(ctx interfaces.AppFunctionContext, data interface{}) (bool, interface{}) {
if data == nil {
return false, fmt.Errorf("function Encrypt in pipeline '%s': No Data Received", ctx.PipelineId())
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/transforms/compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type Compression struct {
}

// NewCompression creates, initializes and returns a new instance of Compression
func NewCompression() Compression {
return Compression{}
func NewCompression() *Compression {
return &Compression{}
}

// CompressWithGZIP compresses data received as either a string,[]byte, or json.Marshaller using gzip algorithm
Expand Down
8 changes: 4 additions & 4 deletions pkg/transforms/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ type Conversion struct {
}

// NewConversion creates, initializes and returns a new instance of Conversion
func NewConversion() Conversion {
return Conversion{}
func NewConversion() *Conversion {
return &Conversion{}
}

// TransformToXML transforms an EdgeX event to XML.
// It will return an error and stop the pipeline if a non-edgex event is received or if no data is received.
func (f Conversion) TransformToXML(ctx interfaces.AppFunctionContext, data interface{}) (continuePipeline bool, stringType interface{}) {
func (f *Conversion) TransformToXML(ctx interfaces.AppFunctionContext, data interface{}) (continuePipeline bool, stringType interface{}) {
if data == nil {
return false, fmt.Errorf("function TransformToXML in pipeline '%s': No Data Received", ctx.PipelineId())
}
Expand All @@ -59,7 +59,7 @@ func (f Conversion) TransformToXML(ctx interfaces.AppFunctionContext, data inter

// TransformToJSON transforms an EdgeX event to JSON.
// It will return an error and stop the pipeline if a non-edgex event is received or if no data is received.
func (f Conversion) TransformToJSON(ctx interfaces.AppFunctionContext, data interface{}) (continuePipeline bool, stringType interface{}) {
func (f *Conversion) TransformToJSON(ctx interfaces.AppFunctionContext, data interface{}) (continuePipeline bool, stringType interface{}) {
if data == nil {
return false, fmt.Errorf("function TransformToJSON in pipeline '%s': No Data Received", ctx.PipelineId())
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/transforms/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ type Filter struct {

// NewFilterFor creates, initializes and returns a new instance of Filter
// that defaults FilterOut to false, so it is filtering for specified values
func NewFilterFor(filterValues []string) Filter {
return Filter{FilterValues: filterValues, FilterOut: false}
func NewFilterFor(filterValues []string) *Filter {
return &Filter{FilterValues: filterValues, FilterOut: false}
}

// NewFilterOut creates, initializes and returns a new instance of Filter
// that defaults FilterOut to true, so it is filtering out specified values
func NewFilterOut(filterValues []string) Filter {
return Filter{FilterValues: filterValues, FilterOut: true}
func NewFilterOut(filterValues []string) *Filter {
return &Filter{FilterValues: filterValues, FilterOut: true}
}

// FilterByProfileName filters based on the specified Device Profile, aka Class of Device.
// If FilterOut is false, it filters out those Events not associated with the specified Device Profile listed in FilterValues.
// If FilterOut is true, it out those Events that are associated with the specified Device Profile listed in FilterValues.
func (f Filter) FilterByProfileName(ctx interfaces.AppFunctionContext, data interface{}) (continuePipeline bool, result interface{}) {
func (f *Filter) FilterByProfileName(ctx interfaces.AppFunctionContext, data interface{}) (continuePipeline bool, result interface{}) {
f.ctx = ctx
event, err := f.setupForFiltering("FilterByProfileName", "ProfileName", ctx.LoggingClient(), data)
if err != nil {
Expand All @@ -66,7 +66,7 @@ func (f Filter) FilterByProfileName(ctx interfaces.AppFunctionContext, data inte
// FilterByDeviceName filters based on the specified Device Names, aka Instance of a Device.
// If FilterOut is false, it filters out those Events not associated with the specified Device Names listed in FilterValues.
// If FilterOut is true, it out those Events that are associated with the specified Device Names listed in FilterValues.
func (f Filter) FilterByDeviceName(ctx interfaces.AppFunctionContext, data interface{}) (continuePipeline bool, result interface{}) {
func (f *Filter) FilterByDeviceName(ctx interfaces.AppFunctionContext, data interface{}) (continuePipeline bool, result interface{}) {
f.ctx = ctx
event, err := f.setupForFiltering("FilterByDeviceName", "DeviceName", ctx.LoggingClient(), data)
if err != nil {
Expand All @@ -84,7 +84,7 @@ func (f Filter) FilterByDeviceName(ctx interfaces.AppFunctionContext, data inter
// FilterBySourceName filters based on the specified Source for the Event, aka resource or command name.
// If FilterOut is false, it filters out those Events not associated with the specified Source listed in FilterValues.
// If FilterOut is true, it out those Events that are associated with the specified Source listed in FilterValues.
func (f Filter) FilterBySourceName(ctx interfaces.AppFunctionContext, data interface{}) (continuePipeline bool, result interface{}) {
func (f *Filter) FilterBySourceName(ctx interfaces.AppFunctionContext, data interface{}) (continuePipeline bool, result interface{}) {
f.ctx = ctx
event, err := f.setupForFiltering("FilterBySourceName", "SourceName", ctx.LoggingClient(), data)
if err != nil {
Expand All @@ -103,7 +103,7 @@ func (f Filter) FilterBySourceName(ctx interfaces.AppFunctionContext, data inter
// If FilterOut is false, it filters out those Event Readings not associated with the specified Resource Names listed in FilterValues.
// If FilterOut is true, it out those Event Readings that are associated with the specified Resource Names listed in FilterValues.
// This function will return an error and stop the pipeline if a non-edgex event is received or if no data is received.
func (f Filter) FilterByResourceName(ctx interfaces.AppFunctionContext, data interface{}) (continuePipeline bool, result interface{}) {
func (f *Filter) FilterByResourceName(ctx interfaces.AppFunctionContext, data interface{}) (continuePipeline bool, result interface{}) {
f.ctx = ctx
existingEvent, err := f.setupForFiltering("FilterByResourceName", "ResourceName", ctx.LoggingClient(), data)
if err != nil {
Expand Down Expand Up @@ -166,7 +166,7 @@ func (f Filter) FilterByResourceName(ctx interfaces.AppFunctionContext, data int
return false, nil
}

func (f Filter) setupForFiltering(funcName string, filterProperty string, lc logger.LoggingClient, data interface{}) (*dtos.Event, error) {
func (f *Filter) setupForFiltering(funcName string, filterProperty string, lc logger.LoggingClient, data interface{}) (*dtos.Event, error) {
mode := "For"
if f.FilterOut {
mode = "Out"
Expand All @@ -185,7 +185,7 @@ func (f Filter) setupForFiltering(funcName string, filterProperty string, lc log
return &event, nil
}

func (f Filter) doEventFilter(filterProperty string, value string, lc logger.LoggingClient) bool {
func (f *Filter) doEventFilter(filterProperty string, value string, lc logger.LoggingClient) bool {
// No names to filter for, so pass events through rather than filtering them all out.
if len(f.FilterValues) == 0 {
return true
Expand Down
8 changes: 4 additions & 4 deletions pkg/transforms/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestFilter_FilterByProfileName(t *testing.T) {

for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
var filter Filter
var filter *Filter
if test.FilterOut {
filter = NewFilterOut(test.Filters)
} else {
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestFilter_FilterByDeviceName(t *testing.T) {

for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
var filter Filter
var filter *Filter
if test.FilterOut {
filter = NewFilterOut(test.Filters)
} else {
Expand Down Expand Up @@ -167,7 +167,7 @@ func TestFilter_FilterBySourceName(t *testing.T) {

for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
var filter Filter
var filter *Filter
if test.FilterOut {
filter = NewFilterOut(test.Filters)
} else {
Expand Down Expand Up @@ -247,7 +247,7 @@ func TestFilter_FilterByResourceName(t *testing.T) {

for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
var filter Filter
var filter *Filter
if test.FilterOut {
filter = NewFilterOut(test.Filters)
} else {
Expand Down
6 changes: 3 additions & 3 deletions pkg/transforms/jsonlogic.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ type JSONLogic struct {
}

// NewJSONLogic creates, initializes and returns a new instance of HTTPSender
func NewJSONLogic(rule string) JSONLogic {
return JSONLogic{
func NewJSONLogic(rule string) *JSONLogic {
return &JSONLogic{
Rule: rule,
}
}

// Evaluate ...
func (logic JSONLogic) Evaluate(ctx interfaces.AppFunctionContext, data interface{}) (bool, interface{}) {
func (logic *JSONLogic) Evaluate(ctx interfaces.AppFunctionContext, data interface{}) (bool, interface{}) {
if data == nil {
// We didn't receive a result
return false, fmt.Errorf("function Evaluate in pipeline '%s': No Data Received", ctx.PipelineId())
Expand Down
6 changes: 3 additions & 3 deletions pkg/transforms/responsedata.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ type ResponseData struct {
}

// NewResponseData creates, initializes and returns a new instance of ResponseData
func NewResponseData() ResponseData {
return ResponseData{}
func NewResponseData() *ResponseData {
return &ResponseData{}
}

// SetResponseData sets the response data to that passed in from the previous function.
// It will return an error and stop the pipeline if the input data is not of type []byte, string or json.Marshaller
func (f ResponseData) SetResponseData(ctx interfaces.AppFunctionContext, data interface{}) (bool, interface{}) {
func (f *ResponseData) SetResponseData(ctx interfaces.AppFunctionContext, data interface{}) (bool, interface{}) {

ctx.LoggingClient().Debugf("Setting response data in pipeline '%s'", ctx.PipelineId())

Expand Down
4 changes: 2 additions & 2 deletions pkg/transforms/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type Tags struct {
}

// NewTags creates, initializes and returns a new instance of Tags using generic interface values
func NewTags(tags map[string]interface{}) Tags {
return Tags{
func NewTags(tags map[string]interface{}) *Tags {
return &Tags{
tags: tags,
}
}
Expand Down