apache-drill

How to pass access tokens from REST client in Apache Drill?


I've setup Apache Drill, created http storage plugin and set its configuration as here:

{
  "type": "http",
  "cacheResults": false,
  "connections": {
    "accounts": {
      "url": "https://my.datasource.url",
      "method": "GET",
      "headers": {
        "Authorization": "Bearer access_token...",
        "Accept": "application/json"
      },
      "authType": "none",
      "userName": null,
      "password": null,
      "postBody": null,
      "params": null,
      "dataPath": "QueryResponse/Account",
      "requireTail": false,
      "inputType": "json"
    }
  },
  "timeout": 0,
  "proxyHost": null,
  "proxyPort": 0,
  "proxyType": "direct",
  "proxyUsername": null,
  "proxyPassword": null,
  "enabled": true
}

I am able to run queries through rest call (as well as from web ui and odbc) as here:

{
  "queryType": "SQL",
  "query": "select * from myds.accounts"
}

The problem is, access token is short lived and multiple users need to access these data sources with their own access tokens, so saving token withing connection doesn't work for me.
Is there any way I could send access token from the client at the time of sending query? I have no preference of using either Rest API or ODBC, any of them would be good as far as it solves my problem. Thanks


Solution

  • It may be possible to specify some of the configuration at query time. The example below demonstrates, in the file system plugin, how to use the table() function to alter the configuration options at runtime. In this case, we're specifying which sheet to query in an excel file.

    SELECT *
    FROM table(dfs.`excel/test_data.xlsx` (type => 'excel', sheetName =>'secondSheet'))
    

    I don't know if this will work for the REST plugin or not, but it's worth a try. (It is admittedly a bit of a hack)

    Another option, which would require modification to the plugin, would be to create special variables that could be specified at query time. For instance, we could create a _headers variable so that you could insert items into the headers at query time. Thus, a query might look like:

    SELECT...
    FROM ...
    WHERE _headers="Authorization=1234"
    

    I'm really wondering what the best way to accomplish this is. I'm sure you're not the only one with this issue.