[Kimchi-devel] [RFC] Validating entries at login

Aline Manera alinefm at linux.vnet.ibm.com
Tue Jan 31 12:30:31 UTC 2017


Hi Ramon,

Does the WokRoot class have set self.api_schema attribute to get the 
right data?

It should have something like:

self.api_schema = json.load(<path>)

Regards,
Aline Manera

On 01/30/2017 04:41 PM, Ramon Medeiros wrote:
>
>
> On 1/30/17 3:30 PM, Aline Manera wrote:
>> Hi Ramon,
>>
>> There is a function in src/wok/control/utils.py called model_fn() 
>> which determines the model function name used by controller.
>> I think you need to use the same function in your code and then 
>> update API.json accordingly.
>>
> model_fn returned wokroot_login, which i already tried. May i missing 
> something on API.json?
>> On 01/27/2017 12:26 PM, Ramon Medeiros wrote:
>>> Just adding more information:
>>>
>>> at the pdb output, you can see "wokroot_login" as method. I have 
>>> already tried this one at API.json
>>>
>>>
>>> On 1/27/17 12:24 PM, Ramon Medeiros wrote:
>>>> Propose: valid strings username and password with API.json
>>>>
>>>> Issue: validator is not recognizing method
>>>>
>>>>
>>>> Just saw that src/wok/control/utils.py has a method 
>>>> validate_params, that reads API and validate the output of 
>>>> request_params. I've added this changes to code:
>>>>
>>>> diff --git a/src/wok/API.json b/src/wok/API.json
>>>> index 8965db9..3faa31b 100644
>>>> --- a/src/wok/API.json
>>>> +++ b/src/wok/API.json
>>>> @@ -2,5 +2,24 @@
>>>>      "$schema": "http://json-schema.org/draft-03/schema#",
>>>>      "title": "Wok API",
>>>>      "description": "Json schema for Wok API",
>>>> -    "type": "object"
>>>> +    "type": "object",
>>>> +    "properties": {
>>>> +        "login": {
>>>> +            "type": "object",
>>>> +            "properties": {
>>>> +                "username": {
>>>> +                    "description": "Username",
>>>> +                    "required": true,
>>>> +                    "type": "string",
>>>> +                    "error": "WOKAUTH0003E"
>>>> +                },
>>>> +                "password": {
>>>> +                    "description": "Password",
>>>> +                    "required": true,
>>>> +                    "type": "string",
>>>> +                    "error": "WOKAUTH0003E"
>>>> +                }
>>>> +            }
>>>> +        }
>>>> +    }
>>>>  }
>>>> diff --git a/src/wok/root.py b/src/wok/root.py
>>>> index e4cecae..55e1886 100644
>>>> --- a/src/wok/root.py
>>>> +++ b/src/wok/root.py
>>>> @@ -32,7 +32,7 @@ from wok.i18n import messages
>>>>  from wok.config import paths as wok_paths
>>>>  from wok.control import sub_nodes
>>>>  from wok.control.base import Resource
>>>> -from wok.control.utils import parse_request
>>>> +from wok.control.utils import parse_request, validate_params
>>>>  from wok.exception import MissingParameter, UnauthorizedError
>>>>  from wok.reqlogger import log_request
>>>>
>>>> @@ -170,6 +170,8 @@ class WokRoot(Root):
>>>>
>>>>          try:
>>>>              params = parse_request()
>>>> +            validate_params(params, self, "login")
>>>>              username = params['username']
>>>>              password = params['password']
>>>>          except KeyError, item:
>>>>
>>>>
>>>> Debugging the code, i just saw that the action_name passed to 
>>>> validate_params (login) is not found by the validator:
>>>>
>>>>  /root/WOK/src/wok/control/utils.py(109)validate_params()
>>>> -> validator.validate(request)
>>>> (Pdb) s
>>>> --Call--
>>>> > 
>>>> /usr/lib/python2.7/site-packages/jsonschema/validators.py(121)validate() 
>>>>
>>>> -> def validate(self, *args, **kwargs):
>>>> (Pdb) n
>>>> > 
>>>> /usr/lib/python2.7/site-packages/jsonschema/validators.py(122)validate() 
>>>>
>>>> -> for error in self.iter_errors(*args, **kwargs):
>>>> (Pdb) s
>>>> --Call--
>>>> > 
>>>> /usr/lib/python2.7/site-packages/jsonschema/validators.py(78)iter_errors()
>>>> -> def iter_errors(self, instance, _schema=None):
>>>> (Pdb) n
>>>> > 
>>>> /usr/lib/python2.7/site-packages/jsonschema/validators.py(79)iter_errors()
>>>> -> if _schema is None:
>>>> (Pdb)
>>>> > 
>>>> /usr/lib/python2.7/site-packages/jsonschema/validators.py(80)iter_errors()
>>>> -> _schema = self.schema
>>>> (Pdb)
>>>> > 
>>>> /usr/lib/python2.7/site-packages/jsonschema/validators.py(82)iter_errors()
>>>> -> scope = _schema.get(u"id")
>>>> (Pdb)
>>>> > 
>>>> /usr/lib/python2.7/site-packages/jsonschema/validators.py(83)iter_errors()
>>>> -> if scope:
>>>> (Pdb) print _schema
>>>> {u'$schema': u'http://json-schema.org/draft-03/schema#', u'type': 
>>>> u'object', u'description': u'Json schema for Wok API', 
>>>> u'properties': {u'wokroot_login': {u'type': u'object', 
>>>> u'properties': {u'username': {u'required': True, u'type': 
>>>> u'string', u'description': u'Username', u'error': u'WOKAUTH0003E'}, 
>>>> u'password': {u'required': True, u'type': u'string', 
>>>> u'description': u'Password', u'error': u'WOKAUTH0003E'}}}}, 
>>>> u'title': u'Wok API'}
>>>> (Pdb) n
>>>> > 
>>>> /usr/lib/python2.7/site-packages/jsonschema/validators.py(85)iter_errors()
>>>> -> try:
>>>> (Pdb)
>>>> > 
>>>> /usr/lib/python2.7/site-packages/jsonschema/validators.py(86)iter_errors()
>>>> -> ref = _schema.get(u"$ref")
>>>>
>>>> How i can know the correct one?
>>>>
>>>> _______________________________________________
>>>> Kimchi-devel mailing list
>>>> Kimchi-devel at ovirt.org
>>>> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>>>>
>>>
>>> _______________________________________________
>>> Kimchi-devel mailing list
>>> Kimchi-devel at ovirt.org
>>> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>>>
>>
>



More information about the Kimchi-devel mailing list