DataONEorg / bookkeeper

Bookkeeper keeps track of DataONE product subscriptions and quotas for researchers using the extended services.
Other
1 stars 2 forks source link

ListQuota method return all quotas if there is no match #43

Closed taojing2002 closed 4 years ago

taojing2002 commented 4 years ago

I ran this command:

curl -k  -v  -H "Authorization: Bearer ${token}" "https://docker-dev-ucsb-1.test.dataone.org:30443/bookkeeper/v1/quotas?subscriber=foo&quotaType=portal&requestor=foo"

It should return not found status or null quota list. However it returned:

{"quotas":[{"id":3,"object":"quota","quotaType":"portal","softLimit":1.0,"hardLimit":1.0,"unit":"portal"},{"id":6,"object":"quota","quotaType":"portal","softLimit":5.0,"hardLimit":5.0,"usage":0.0,"unit":"portal","subscriptionId":3,"subject":"https://orcid.org/0000-0002-1678-0975"},{"id":4,"object":"quota","quotaType":"portal","softLimit":5.0,"hardLimit":5.0,"usage":0.0,"unit":"portal","subscriptionId":1,"subject":"CN=opc,DC=dataone,DC=org"},{"id":10,"object":"quota","quotaType":"portal","softLimit":5.0,"hardLimit":5.0,"usage":5.0,"unit":"portal","subscriptionId":7,"subject":"CN=Robert Nahf A579,O=Google,C=US,DC=cilogon,DC=org"}]}
gothub commented 4 years ago

The correct URL param name for both listQuotas() and listUsages() is subscribers (plural). For the first command above, the parameter subscribers seems to have been ignored by bookkeeper, resulting in no subscribers being specified. If a subscriber is not specified, the expected behavior is to return all quotas the requestor has rights to see, and for an admin requestor, that is all quotas. So the fix is to use the param name subscribers.

The second problem relates to to the requestor param. Bookkeeper was just logging an error for an unknown (to DataONE) id. This has been fixed so that an unknown id causes an exception to be thrown and the service will return this status and message:

{
    "code": 417,
    "message": "The requested quotas couldn't be listed: Couldn't retrieve subject from DataONE: 'foo'. org.dataone.service.exceptions.NotFound: [LDAP: error code 32 - No Such Object]"
}

This was fixed in commit fa1d31b1098d286d52b72461a546470e7f95c9f8