Kodi plugin and URL with basic authentication - plugins

I'm writing KODI plugin, where I'm trying to play resources from external service. Access of resources requires basic authentication.
I was following this tutorial of how to write add-on. They call addDirectoryItem method in xbmcplugin.
url = 'http://localhost/some_video.mkv'
li = xbmcgui.ListItem(foldername + ' Video', iconImage='DefaultVideo.png')
xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)
It accepts url as string. I cannot find any option, how to do authentication part.

Kodi player allows to pass custom HTTP headers, including authentication headers, to a remote server like the following:
from urllib import quote
url = 'http://some.server/video.mkv|Header1={0}&Header2={1}'.format(
quote(header1_value),
quote(header2_value)
)
That is, after a pipe | you can pass a set of header=value pairs separated by &. Header values must be URL-quoted.

Related

Calling Orthanc's REST Api from Lua returns a "URI Badly Formatted" error

I am trying to anonymize images before sending them to another Orthanc server.
According to the documentation on anonymization, Orthanc can anonymize images through the REST api:
http://book.orthanc-server.com/users/anonymization.html
Orthanc allows to anonymize a single DICOM instance and to download
the resulting anonymized DICOM file. Example:
$ curl http://localhost:8042/instances/6e67da51-d119d6ae-c5667437-87b9a8a5-0f07c49f/anonymize -X POST -d '{}' > Anonymized.dcm
According to the documentation page on Lua scripts, Lua scripts can take advantage of the REST API:
Lua scripts have full access to the REST API of Orthanc
The page goes on to describe how to use call the REST API from Lua:
functions:
RestApiGet(uri, builtin)
RestApiPost(uri, body, builtin)
RestApiPut(uri, body, builtin)
RestApiDelete(uri, builtin)
The uri arguments specifies the URI against which to make the request, and body is a string containing the body of POST/PUT request.
This means that I should be able to call the REST API from Lua by combining the functions above.
However when calling the RestApiPost as described in the documentation.
instances = RestApiGet(http://localhost:8042/instances, true)
I get the following error
E0313 17:40:40.851840 LuaScripting.cpp:358] Lua: Badly formatted URI
E0313 17:40:40.851884 LuaScripting.cpp:361] Lua: Error in RestApiPost() for URI: http://localhost:8042/instances/b38a8ef0-909f8ac0-7eca907a-75c98187-8e5339f4/anonymize
It's worth noting that I can call this endpoint correctly from curl and from my browser. Removing the 'http://' section didn't solve the issue.
The RestApiGet function and its family expect the developer to format the uri parameter without 'http://localhost:8042' as follows:
'/instances'
These functions only work for using the REST API provided by the Orthanc the Lua script is running on, so it already knows that you will use the localhost and it will use the correct http scheme and 8042 port automatically.
As described in http://book.orthanc-server.com/users/lua.html#general-purpose-functions, the function HttpGet(url, headers) and its family are the general form of this function and allow the developer to query any http endpoint.

How to send request with a set http_header in Erlang Package a SOAP github package

I am using this erlang-package on Github to work with WSDL and SOAP, and I am only using the package for Client generation! I have not erlang knowledge at all - only basic elixir.
My Problem:
How can I send a request with an authorization header?
Lets say the code to test my service looks like the following:
connectionCheck() ->
'WsdlService_client':connectionCheck(
#'P:connectionCheck'{
clientSoftwareKennung = "Elixir"},
_Soap_headers = [],
_Soap_options = [{url,"http://localhost:8091/myservice/v2.0/connectionCheck"}]).
Which parameter needs to be filled in and what do the parameters look like when I need the following header in the resulting http-request?
Authorization: Basic <placeholder encodeded user password>
Thanks!
I was able to solve it by myself.
If you need to pass some http-Headers to your Soap-Request you can do it like that:
_Soap_options = [{url,"http://localhost:8091/myservice/v2.0/connectionCheck"},{http_headers, [{"Authorization","Basic Encoded User-Pass"}]}]).

Why is GorillaMux not allowing me to pass in a URL as a parameter?

I'm building a URL shortener API and I'm trying to pass a URL into a function using GorillaMux. The route handler is like so:
router.HandleFunc("/new/{url}", createURL)
The only thing is, if I pass in: https://www.google.com (as in localhost:8080/new/https://www.google.com) then it responds with 404 page not found and the URL is changed to https:/www.google.com.
I've tried adding a regexp pattern in with the {url} bit like so: {url:[a-zA-Z0-9/]+} but that didn't seem to work and seems a bit overkill since I'm checking the url is correct elsewhere.
You need to encode it so that the slash in the parameter was not confused as a part of the url:
localhost:8080/new/https%3A%2F%2Fwww.google.com

How to get the original request URI in api gateway?

From a lambda implemented api gateway resource, how to get the original request URI. Or even just the original path?
Lacking a better way I'm currently using the following three variables that I pass down to the lambda using the default request template:
$context.resourcePath contains the path with variable names ex: "/blah/{var}"
$input.params().path contains the variable names and values ex: {"var":"something"}
$context.stage contains the stage ex: "prod"
That's quite a hassle since it requires path variable substitution to get the original call path:
/prod/blah/something
How can I get the original URL or URI?
I'm not finding anything in the documentation that lets you get the original call URI. I can add a feature request to consider adding it. Can you describe your use case. Why do you want to get the original URI?
I found a 'workaround'.
If you create a custom domain name with a BasePathMapping, and call the API using this custom domain, the original request uri actually has your stage name in there:
Call directly to the API gateway:
curl -v 'https://some-id.execute-api.eu-central-1.amazonaws.com/v1/ping'
...
request.url: https://some-id.execute-api.eu-central-1.amazonaws.com/ping'
But if we call it through te custom domain (which is actually a cloudfront distribution):
curl -v -X GET https://api.our.domain.name.com/v1/ping
...
request.url: https://api.our.domain.name.com/v1/ping
In my opinion, the direct call gives you an INCORRECT request url in the lambda function, as the url very clearly has the stage name in there.
This breaks the routing middleware of at least flask.
Any update on the feature request?

How to use URI as a REST resource?

I am building a RESTful API for retrieving and storing comments in threads.
A comment thread is identified by an arbitrary URI -- usually this is the URL of the web page where the comment thread is related to. This design is very similar to what Disqus uses with their system.
This way, on every web page, querying the related comment thread doesn't require storing any additional data at the client -- all that is needed is the canonical URL to the page in question.
My current implementation attempts to make an URI work as a resource by encoding the URI as a string as follows:
/comments/https%3A%2F%2Fexample.org%2Ffoo%2F2345%3Ffoo%3Dbar%26baz%3Dxyz
However, before dispatching it to my application, the request URI always gets decoded by my server to
/comments/https://example.org/foo/2345?foo=bar&baz=xyz
This isn't working because the decoded resource name now has path delimiters and a query string in it causing routing in my API to get confused (my routing configuration assumes the request path contains /comments/ followed by a string).
I could double-encode them or using some other encoding scheme than URI encode, but then that would add complexity to the clients, which I'm trying to avoid.
I have two specific questions:
Is my URI design something I should continue working with or is there a better (best?) practice for doing what I'm trying to do?
I'm serving API requests with a Go process implemented using Martini 'microframework'. Is there something Go or Martini specific that I should do to make the URI-encoded resource names to stay encoded?
Perhaps a way to hint to the routing subsystem that the resource name is not just a string but a URL-encoded string?
I don't know about your url scheme for your application, but single % encoded values are valid in a url in place of the chars they represent, and should be decoded by the server, what you are seeing is what I would expect. If you need to pass url reserved characters as a value and not have them decoded as part of the url, you will need to double % encode them. It's a fairly common practice, the complexity added to the client & server will not be that much, and a short comment will do rightly.
In short, If you need to pass url chars, double % encode them, it's fine.