oasis-open / openc2-lycan-python

OASIS TC Open Repository: A GitHub public repository for development of a python library to transform between data-interchange formats (such as JSON) and python language objects
https://github.com/oasis-open/openc2-lycan-python
Other
11 stars 12 forks source link

Args validation #32

Closed twodayslate closed 4 years ago

twodayslate commented 4 years ago

From the specification:

start_time, stop_time, duration:

  • If none are specified, then start_time is now, stop_time is never, and duration is infinity.
  • Only two of the three are allowed on any given Command and the third is derived from the equation stop_time = start_time + duration.
  • If only start_time is specified then stop_time is never and duration is infinity.
  • If only stop_time is specified then start_time is now and duration is derived.
  • If only duration is specified then start_time is now and stop_time is derived.

There currently isn't any validation on openc2.Args. For example if all three are defined that would be out of specification. Should that be handled by this library or should the consumer handle those checks? Some make sense to have the consumer check the value/apply default values. I would also think an error should be thrown if stop_time is less than start_time tho. The "MUST" language isn't present in this section so it isn't clear on the desired behavior.

Additionally, the three values above are defined as the following:

Value is the number of milliseconds since 00:00:00 UTC, 1 January 1970

Currently if a float is given (i.e. 2.2) the value is valid (appears to be rounded down). Should this throw an error or is that acceptable behavior?

Lastly, the specification states that the integer must be positive.

I can create a PR for this depending on your answer if applicable.

Thanks

mstair commented 4 years ago

Agree the library should validate those args, I know I didn't fully validate against the spec for all scenarios.

I'd love a PR :)

twodayslate commented 4 years ago

This is complete. I did not implement the float check. If you would like that please let me know.