On the get method from MonitoringSensorResultResource.php there is a $url variable that uses the route name hardcoded. My suggestion is to use the current route name (\Drupal::routeMatch()->getRouteName() but using DI).
The reason behind this would be to be able to have my own RestResource extending from it and being able to define a different uri_path and authentication methods. To be more specific, I do not want to rely on the basic_auth module, as things stand, I must install the basic_auth module for that sensor to work. That module brings issues with environments using basic auth at the webserver level (Nginx).
Comments
Comment #2
emersonreis.devComment #3
emersonreis.devI'm happy to work on a patch for this. If I get time I will look at doing it tomorrow, but it would be good to have an input from the maintainers.
Comment #4
berdirOpen to improving things. Not aware that we have a hardcoded dependency on basic auth, I would assume that's just the optional configuration? Not quite sure how to avoid hardcoding that though, especially on the list level.
Comment #5
emersonreis.devHere is the patch.
Basically, what this does is it allows developers to have their own RestResource extending MonitoringSensorResultResource without depending on basic_auth. This allows developers to use different authentication methods and not having basic_auth enabled. This is my use case.
At the moment, I need to enable basic_auth because otherwise, the optional config will not be enabled and the route 'rest.monitoring-sensor-result.GET' will not exist, thus throwing an exception. But I don't need that route nor basic_auth, I have my own RestResource with my own authentication method.
This does not remove the basic_auth dependency as that would probably be a discussion for another issue!
Comment #7
emersonreis.devFixing tests
Comment #8
emersonreis.devComment #9
emersonreis.devComment #10
berdirbut that's exactly my point from above. now you point the list route. but that's not the idea, that doesn't make sense. the list route doesn't have an id argument, it's the list.
Agree with this a problem, always been aware of that, but your solution doesn't work.
Still don't quite get the basic auth argument though. The problem is hardcoding the config entity name, we don't care what authentication method is in there As a workaround, you could just name your own rest config the same :)
Comment #11
emersonreis.devI see. I totally misunderstood the purpose of the URI on the response! My apologies.
I am attaching a new patch, let me know if this makes sense.
Comment #12
emersonreis.devAn example of how a custom RestResource would look like
Comment #13
emersonreis.dev