-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add default and custom validations for name field (#316)
**Issue number:[ADDON-74237](https://splunk.atlassian.net/browse/ADDON-74237)** ## Summary Added support for default and custom name field validation ### Changes * RestModel now has an additional parameter "special_fields" * RestEndpoint now has two additional methods for executing custom validations * _pre_request decorator has new method "basic_name_validation" for basic validations ### User experience Name field will be validated on the server side ## Checklist If your change doesn't seem to apply, please leave them unchecked. * [x] I have performed a self-review of this change * [x] Changes have been tested * [ ] Changes are documented * [x] PR title follows [conventional commit semantics](https://www.conventionalcommits.org/en/v1.0.0/) --------- Co-authored-by: mkolasinski-splunk <105011638+mkolasinski-splunk@users.noreply.github.com>
- Loading branch information
1 parent
21b6088
commit 1681309
Showing
8 changed files
with
273 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import import_declare_test | ||
|
||
from splunktaucclib.rest_handler.endpoint import ( | ||
field, | ||
validator, | ||
RestModel, | ||
DataInputModel, | ||
) | ||
from splunktaucclib.rest_handler import admin_external, util | ||
from splunktaucclib.rest_handler.admin_external import AdminExternalHandler | ||
import logging | ||
|
||
util.remove_http_proxy_env_vars() | ||
|
||
|
||
special_fields = [ | ||
field.RestField( | ||
"name", | ||
required=True, | ||
encrypted=False, | ||
default=None, | ||
validator=validator.AllOf( | ||
validator.Pattern( | ||
regex=r"""^[a-dA-D]\w*$""", | ||
), | ||
validator.String( | ||
max_len=100, | ||
min_len=1, | ||
), | ||
), | ||
) | ||
] | ||
|
||
fields = [ | ||
field.RestField( | ||
"interval", | ||
required=True, | ||
encrypted=False, | ||
default="300", | ||
validator=validator.Pattern( | ||
regex=r"""^(?:-1|\d+(?:\.\d+)?)$""", | ||
), | ||
), | ||
field.RestField("disabled", required=False, validator=None), | ||
] | ||
model = RestModel(fields, name=None, special_fields=special_fields) | ||
|
||
|
||
endpoint = DataInputModel( | ||
"demo", | ||
model, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
logging.getLogger().addHandler(logging.NullHandler()) | ||
admin_external.handle( | ||
endpoint, | ||
handler=AdminExternalHandler, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import import_declare_test | ||
|
||
from splunktaucclib.rest_handler.endpoint import ( | ||
field, | ||
validator, | ||
RestModel, | ||
MultipleModel, | ||
) | ||
from splunktaucclib.rest_handler import admin_external, util | ||
from splunktaucclib.rest_handler.admin_external import AdminExternalHandler | ||
import logging | ||
|
||
util.remove_http_proxy_env_vars() | ||
|
||
|
||
special_fields = [] | ||
|
||
fields_logging = [ | ||
field.RestField( | ||
"loglevel", required=True, encrypted=False, default="INFO", validator=None | ||
) | ||
] | ||
model_logging = RestModel(fields_logging, name="logging", special_fields=special_fields) | ||
|
||
|
||
endpoint = MultipleModel( | ||
"demo_settings", | ||
models=[model_logging], | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
logging.getLogger().addHandler(logging.NullHandler()) | ||
admin_external.handle( | ||
endpoint, | ||
handler=AdminExternalHandler, | ||
) |
Oops, something went wrong.