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!: Use bool types for command parameters to be more consistent #4276

Merged
merged 3 commits 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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/edgexfoundry/edgex-go
require (
bitbucket.org/bertimus9/systemstat v0.0.0-20180207000608-0eeff89b0690
github.com/eclipse/paho.mqtt.golang v1.4.2
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.8
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.2
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.3
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.9
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.3
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.4
github.com/edgexfoundry/go-mod-secrets/v3 v3.0.0-dev.2
github.com/fxamacker/cbor/v2 v2.4.0
github.com/golang-jwt/jwt/v4 v4.4.3
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/eclipse/paho.mqtt.golang v1.4.2 h1:66wOzfUHSSI1zamx7jR6yMEI5EuHnT1G6rNA5PM12m4=
github.com/eclipse/paho.mqtt.golang v1.4.2/go.mod h1:JGt0RsEwEX+Xa/agj90YJ9d9DH2b7upDZMK9HRbFvCA=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.8 h1:BvIM4O8edFi/nhtJmfy4lh+keYG3VbHvfWjyXoyiESU=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.8/go.mod h1:2I6w1vDe1Hsq0woNy5L9SqRAho+xjpObhhlv1dI4avY=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.9 h1:YQRmArf08iSHOJ1xIXMchxfsbeguUPbG1Q1E0IVAUZA=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.9/go.mod h1:lJI+SO9B3dWOn/UfJ90fYQVR4wYddjEkvmAJqt/WdxA=
github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.2 h1:xp5MsP+qf/fuJxy8fT7k1N+c4j4C6w04qMCBXm6id7o=
github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.2/go.mod h1:1Vv4uWAo6r7k6jUlqVJW8JOL6YKVBc6sRL8Al3DrMck=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.2 h1:tleTxhbBISfDNn596rU71n+GOy27dMIme+v8Vl0uhpw=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.2/go.mod h1:7RwSq896VqelvSU7zYKs2tpZhgELVFECkiGf6XGLKfQ=
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.3 h1:+el2HxEt02uFXXBmHK8gWETPklNbPg4wvYln/4/ooHo=
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.3/go.mod h1:G0Vxoc8+JXwUqRH5ggyOZ/f/CIVPTswI5Ld7dI5uhIY=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.3 h1:Ia/y/w9w3SmXqIqJ+Vjmv6QrP49YJDpTY6262C1Jrzs=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.3/go.mod h1:7RwSq896VqelvSU7zYKs2tpZhgELVFECkiGf6XGLKfQ=
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.4 h1:swPZOjoQ/IUIWSJpZCmQENtP/plFRx5tgiCEZgnfxFU=
github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.4/go.mod h1:8pxuYvh2zcq1GuKqmk1MAuH1yuN40iOMmL0g2myIfwk=
github.com/edgexfoundry/go-mod-registry/v3 v3.0.0-dev.3 h1:QgZF9f70Cwpvkjw3tP1aiVGHc+yNFJNzW6hO8pDs3fg=
github.com/edgexfoundry/go-mod-registry/v3 v3.0.0-dev.3/go.mod h1:2w8v0sv+i21nY+DY6JV4PFxsNTuxpGAjlNFlFMTfZkk=
github.com/edgexfoundry/go-mod-secrets/v3 v3.0.0-dev.2 h1:Lu1gJr2fAUTuogE/SwgVgGpxDlMsC4PLE0Y8oXRUvkI=
Expand Down
12 changes: 6 additions & 6 deletions internal/core/command/controller/http/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ func (cc *CommandController) CommandsByDeviceName(w http.ResponseWriter, r *http
}

func validateGetCommandParameters(r *http.Request) (err errors.EdgeX) {
dsReturnEvent := utils.ParseQueryStringToString(r, common.ReturnEvent, common.ValueYes)
dsPushEvent := utils.ParseQueryStringToString(r, common.PushEvent, common.ValueNo)
if dsReturnEvent != common.ValueYes && dsReturnEvent != common.ValueNo {
return errors.NewCommonEdgeX(errors.KindContractInvalid, fmt.Sprintf("invalid query parameter, %s has to be %s or %s", dsReturnEvent, common.ValueYes, common.ValueNo), nil)
dsReturnEvent := utils.ParseQueryStringToString(r, common.ReturnEvent, common.ValueTrue)
dsPushEvent := utils.ParseQueryStringToString(r, common.PushEvent, common.ValueFalse)
if dsReturnEvent != common.ValueTrue && dsReturnEvent != common.ValueFalse {
return errors.NewCommonEdgeX(errors.KindContractInvalid, fmt.Sprintf("invalid query parameter, %s has to be %s or %s", dsReturnEvent, common.ValueTrue, common.ValueFalse), nil)
}
if dsPushEvent != common.ValueYes && dsPushEvent != common.ValueNo {
return errors.NewCommonEdgeX(errors.KindContractInvalid, fmt.Sprintf("invalid query parameter, %s has to be %s or %s", dsPushEvent, common.ValueYes, common.ValueNo), nil)
if dsPushEvent != common.ValueTrue && dsPushEvent != common.ValueFalse {
return errors.NewCommonEdgeX(errors.KindContractInvalid, fmt.Sprintf("invalid query parameter, %s has to be %s or %s", dsPushEvent, common.ValueTrue, common.ValueFalse), nil)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/core/command/controller/http/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (
testDeviceServiceName = "testDeviceService"
testCommandName = "testCommand"
testBaseAddress = "http://localhost:49990"
testQueryStrings = "a=1&b=2&ds-pushevent=no"
testQueryStrings = "a=1&b=2&ds-pushevent=false"
)

// NewMockDIC function returns a mock bootstrap di Container
Expand Down
4 changes: 2 additions & 2 deletions internal/core/command/controller/messaging/external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ func testCommandQueryPayload() types.MessageEnvelope {

func testCommandRequestPayload() types.MessageEnvelope {
payload := types.NewMessageEnvelopeForRequest(nil, map[string]string{
"ds-pushevent": "yes",
"ds-returnevent": "yes",
"ds-pushevent": common.ValueTrue,
"ds-returnevent": common.ValueTrue,
})

return payload
Expand Down
8 changes: 4 additions & 4 deletions internal/core/command/controller/messaging/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ func validateRequestTopic(prefix string, deviceName string, commandName string,
// validateGetCommandQueryParameters validates the value is valid for device service's reserved query parameters
func validateGetCommandQueryParameters(queryParams map[string]string) error {
if dsReturnEvent, ok := queryParams[common.ReturnEvent]; ok {
if dsReturnEvent != common.ValueYes && dsReturnEvent != common.ValueNo {
return fmt.Errorf("invalid query parameter, %s has to be '%s' or '%s'", common.ReturnEvent, common.ValueYes, common.ValueNo)
if dsReturnEvent != common.ValueTrue && dsReturnEvent != common.ValueFalse {
return fmt.Errorf("invalid query parameter, %s has to be '%s' or '%s'", common.ReturnEvent, common.ValueTrue, common.ValueFalse)
}
}
if dsPushEvent, ok := queryParams[common.PushEvent]; ok {
if dsPushEvent != common.ValueYes && dsPushEvent != common.ValueNo {
return fmt.Errorf("invalid query parameter, %s has to be '%s' or '%s'", common.PushEvent, common.ValueYes, common.ValueNo)
if dsPushEvent != common.ValueTrue && dsPushEvent != common.ValueFalse {
return fmt.Errorf("invalid query parameter, %s has to be '%s' or '%s'", common.PushEvent, common.ValueTrue, common.ValueFalse)
}
}

Expand Down
20 changes: 10 additions & 10 deletions openapi/v2/core-command.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -564,21 +564,21 @@ paths:
schema:
type: string
enum:
- yes
- no
default: no
example: yes
description: "If set to yes, a successful GET will result in an event being pushed to the EdgeX system"
- true
- false
default: false
example: true
description: "If set to true, a successful GET will result in an event being pushed to the EdgeX system"
- in: query
name: ds-returnevent
schema:
type: string
enum:
- yes
- no
default: yes
example: no
description: "If set to no, there will be no Event returned in the http response"
- true
- false
default: true
example: false
description: "If set to false, there will be no Event returned in the http response"
responses:
'200':
description: "OK"
Expand Down