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

Validate JSON config #240

Merged
merged 3 commits into from
Aug 10, 2017
Merged

Validate JSON config #240

merged 3 commits into from
Aug 10, 2017

Conversation

adambabik
Copy link
Contributor

@adambabik adambabik commented Aug 7, 2017

Related to issue #149.

Changes

  • exposed ValidateNodeConfig(),
  • extended NodeConfig interface with Validate() method,
  • added validate tag to some NodeConfig fields.

Validated fields

  • field type thanks to Go JSON unmarshalling,
  • required fields.

Error formatting

{
  "status": true | false,
  "message": "string",
  "field_errors": [
    {
      "paramater": "string",
      "errors": [
        {
          "message": "string"
        },
        ...
      ]
    },
    ...
  ]
}

Todo:

  • better error formatting (some help from ClojureTeam is required),
  • add validation for the rest of the fields.

@adambabik adambabik force-pushed the feature/validate-json-config-#149 branch from 1021016 to c7add9a Compare August 8, 2017 13:36
@adambabik adambabik requested a review from MarinX August 8, 2017 20:51
@adambabik
Copy link
Contributor Author

I consider this done at this point of time. I tried to make the validation more restrict but each time I was hit by some tests that allowed a given configuration. E.g. NetworkId might be arbitrary as we allow private networks, checking key paths is done later, not during loading configuration and almost all fields are optional as we provide defaults.

@tiabc tiabc self-requested a review August 9, 2017 18:01
Copy link
Contributor

@MarinX MarinX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmd/statusd/utils.go
func testValidateNodeConfig
Please move this testing function to testing package eg. if you are testing utils create utils_test.go. We dont want to have an testing functions inside packages.

geth/params/validator.go
func NewValidator()
Can we simplify by return validator.New() ?

geth/common/types.go

  • APIDetailedResponse
  • APIFieldError
  • APIError

Why this API prefix ? Can we simplify to something idiomatic ?
Eg. Response, Field, Error

We are using single char to point to the struct, so please, stick with that.
Ex.
func (fe APIFieldError) Error()
We can just use "f" or "e".

@adambabik
Copy link
Contributor Author

@MarinX it would be easier to reply to comments directly attached to source files, if it's possible.

cmd/statusd/utils.go
func testValidateNodeConfig
Please move this testing function to testing package eg. if you are testing utils create utils_test.go. We dont want to have an testing functions inside packages.

You can't compile *_test.go files with cgo support and that test calls a cgo function. I am following the pattern we established but this whole file will be refactored. There is an issue for that.

geth/params/validator.go
func NewValidator()
Can we simplify by return validator.New() ?

👍 There are no custom validators, it can be simplified.

geth/common/types.go
APIDetailedResponse
APIFieldError
APIError
Why this API prefix ? Can we simplify to something idiomatic ?
Eg. Response, Field, Error

Also following convention here. In my opinion we shouldn't have something like common/types.go at all but each subpackage could have types.go file. Again, it will be easier to refactor if I am consistent now.

We are using single char to point to the struct, so please, stick with that.
Ex.
func (fe APIFieldError) Error()
We can just use "f" or "e".

👍 Yeah, I will change this.

@adambabik adambabik force-pushed the feature/validate-json-config-#149 branch from 058b7bb to 557eba3 Compare August 10, 2017 08:35
@tiabc
Copy link
Contributor

tiabc commented Aug 10, 2017

@MarinX, you're saying right things but not in the right time. We have a set of rules which should follow to avoid hell with merging: https://hackmd.io/s/rkgqzRWIb
@adambabik said absolutely right that it's easier to refactor if he now follows the pattern. If you have thoughts for improving code quality, you're welcome to add what's missing in #200

@MarinX
Copy link
Contributor

MarinX commented Aug 10, 2017

Seems like a plan.
Approving it then.

@adambabik adambabik force-pushed the feature/validate-json-config-#149 branch from 557eba3 to f31da35 Compare August 10, 2017 15:24
@tiabc tiabc merged commit 7433828 into develop Aug 10, 2017
@adambabik adambabik deleted the feature/validate-json-config-#149 branch October 29, 2017 22:35
@pedropombeiro
Copy link
Contributor

@adambabik I noticed what seems a mismatch in the value for the warning level. It is mentioned as being WARNING in https://github.com/status-im/status-go/blob/develop/geth/params/config.go#L292, but WARN in https://github.com/status-im/status-go/blob/develop/cmd/statusd/main.go#L33. Which one is correct? I've contemplated both possible values for https://github.com/status-im/status-react/pull/2803/files#diff-f0c84ad5ab89ec75142eeb77847c830cR73, but would rather be sure.

@adambabik
Copy link
Contributor Author

@pedropombeiro
Copy link
Contributor

@adambabik do you want me to change the code in https://github.com/status-im/status-go/blob/develop/geth/params/config.go#L292 to WARN? Otherwise there should be a mapping further up the call chain, in places like https://github.com/status-im/status-go/blob/develop/cmd/statusd/main.go#L103. I realize it's not an issue today because the WARN level probably isn't being used by anyone, but it would still be better to have these layers harmonized and working together.

@adambabik
Copy link
Contributor Author

@pombeirp

do you want me to change the code in https://github.com/status-im/status-go/blob/develop/geth/params/config.go#L292 to WARN?

Yes, please. For now, that should be quite enough, however, I am not sure status-react validates config before starting a node.

@pedropombeiro
Copy link
Contributor

@adambabik yeah, even if it doesn't, it will avoid inducing people new to the codebase in error. I initially used WARNING instead of WARN after looking at this code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants