Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic params from udf with OAuth integration? #329

Closed
x2on opened this issue Mar 7, 2012 · 9 comments
Closed

Dynamic params from udf with OAuth integration? #329

x2on opened this issue Mar 7, 2012 · 9 comments
Assignees
Labels

Comments

@x2on
Copy link

x2on commented Mar 7, 2012

How is it possible to use udf functions in statement which are considered in the OAuth Part.
On my example below the request uses the udf parameter, but the OAuth uri doesn't know the parameter from the udf.

Any ideas?

im using the following select statement

select * from testtable where param('test')

the create table statement:

create table testtable
    on select get from "http://rest.example.com/function/testValue={testValue}" 
    using patch "testPatch.js"

and patch:

exports['udf'] = function() {
  return {
        'testValue' : function(a) {
            if (a == 'test') {
                return 'TESTVALUE'
            }
            else {
                return 'OTHERVALUE'
            }
        }
    };
};

var uriTemplate = require('ql.io-uri-template');

var OAuth= require('oauth').OAuth;

exports['patch headers'] = function(options) {
    var h = options.headers;

    var uri = uriTemplate.parse(options.statement.uri).format(options.params);

    var oa = new OAuth("",
    "",
    "Key", "Secret",
    "1.0", "http://localhost:3000/oauth/callback", "HMAC-SHA1", null);

    var orderedParameters = oa._prepareParameters("",
        "", "GET",
        uri);

    var authorization = oa._buildAuthorizationHeaders(orderedParameters);

    h["Authorization"] = authorization;

    return h;
};
@s3u
Copy link
Member

s3u commented Mar 7, 2012

Not sure I understand the question, but allow me to clarify how UDFs work.

The purpose if udf is to allow a patch to manufacture params using some inputs from selects. Here is an example.

select * from foo where bar(2, 3)

Let's say, bar returns the min of 2 and 3. Then the params will hold

params = {
    "bar": 2
}

Please see https://github.com/ql-io/ql.io/blob/master/modules/engine/test/patch/udf.[js|ql] for an example. The params computed should be available for OAuth work.

@x2on
Copy link
Author

x2on commented Mar 8, 2012

I think that this is exactly what im doing or?

But in the OAuth patch headers

var uri = uriTemplate.parse(options.statement.uri).format(options.params);

doesn't contain this parameter...

@s3u
Copy link
Member

s3u commented Mar 9, 2012

Thanks. Checking ...

@ghost ghost assigned s3u Mar 9, 2012
@s3u
Copy link
Member

s3u commented Mar 12, 2012

Here is the example I just tried.

exports['udf'] = function() {
    return {
        'p1' : function(arg) {
            return arg
        },
        'p2' : function(a, b) {
            return Number(a) + Number(b);
        }
    };
};

exports['patch uri'] = function(args) {
    console.log(args.params.p1);
    console.log(args.params.p2);
    return args.uri;
}

Given a statement

select * from patch.udf where p1("v1") and p2("2", "3")'

this prints

v1
5

on the console.

Can you try with the latest from npm?

@s3u
Copy link
Member

s3u commented Mar 13, 2012

I added a test to verify that this is working.

#354

@s3u s3u closed this as completed Mar 13, 2012
@x2on
Copy link
Author

x2on commented Mar 15, 2012

But this only works if "p1" or "p2" is not a query parameter defined in the create table statement. If you define it as a parameter like the testValue above then the params are undefined.

How could i define that "p1" should be used as the "testvalue" above?

@s3u
Copy link
Member

s3u commented Mar 16, 2012

I see it. Working on a fix. Sorry for hastily closing.

@s3u s3u reopened this Mar 16, 2012
@s3u
Copy link
Member

s3u commented Mar 21, 2012

#385 has the fix.

@s3u s3u closed this as completed Mar 21, 2012
@s3u
Copy link
Member

s3u commented Mar 22, 2012

Pushed to npm.

ql.io-engine-0.4.23 has the fix.

narayanaag pushed a commit to narayanaag/ql.io that referenced this issue Apr 5, 2022
narayanaag pushed a commit to narayanaag/ql.io that referenced this issue Apr 5, 2022
narayanaag pushed a commit to narayanaag/ql.io that referenced this issue Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants