auth inside param reading
This commit is contained in:
@@ -9,21 +9,19 @@ $$
|
|||||||
import string
|
import string
|
||||||
|
|
||||||
try:
|
try:
|
||||||
params = plpy.execute("select c.host, c.port, c.timeout, c.username, c.password from cartodb._CDB_Group_API_Conf() c;")[0]
|
params = plpy.execute("select c.host, c.port, c.timeout, c.auth from cartodb._CDB_Group_API_Conf() c;")[0]
|
||||||
if params['host'] is None:
|
if params['host'] is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
client = httplib.HTTPConnection(params['host'], params['port'], False, params['timeout'])
|
client = httplib.HTTPConnection(params['host'], params['port'], False, params['timeout'])
|
||||||
body = '{ "name": "%s", "database_role": "%s" }' % (group_name, group_role)
|
body = '{ "name": "%s", "database_role": "%s" }' % (group_name, group_role)
|
||||||
auth = plpy.execute("SELECT cartodb._CDB_Group_API_Auth('%s', '%s') as auth" % (params['username'], params['password']))[0]['auth']
|
headers = { 'Authorization': ('Basic %s' % params['auth']), 'Content-Type': 'application/json' }
|
||||||
headers = { 'Authorization': ('Basic %s' % auth), 'Content-Type': 'application/json' }
|
|
||||||
client.request('POST', '/api/v1/databases/%s/groups' % database_name, body, headers)
|
client.request('POST', '/api/v1/databases/%s/groups' % database_name, body, headers)
|
||||||
response = client.getresponse()
|
response = client.getresponse()
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
plpy.warning('group creation error: ' + str(err))
|
plpy.warning('group creation error: ' + str(err))
|
||||||
raise err
|
raise err
|
||||||
|
|
||||||
$$ LANGUAGE 'plpythonu' VOLATILE;
|
$$ LANGUAGE 'plpythonu' VOLATILE;
|
||||||
|
|
||||||
CREATE OR REPLACE
|
CREATE OR REPLACE
|
||||||
@@ -34,20 +32,18 @@ $$
|
|||||||
import string
|
import string
|
||||||
|
|
||||||
try:
|
try:
|
||||||
params = plpy.execute("select c.host, c.port, c.timeout, c.username, c.password from cartodb._CDB_Group_API_Conf() c;")[0]
|
params = plpy.execute("select c.host, c.port, c.timeout, c.auth from cartodb._CDB_Group_API_Conf() c;")[0]
|
||||||
if params['host'] is None:
|
if params['host'] is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
client = httplib.HTTPConnection(params['host'], params['port'], False, params['timeout'])
|
client = httplib.HTTPConnection(params['host'], params['port'], False, params['timeout'])
|
||||||
auth = plpy.execute("SELECT cartodb._CDB_Group_API_Auth('%s', '%s') as auth" % (params['username'], params['password']))[0]['auth']
|
headers = { 'Authorization': ('Basic %s' % params['auth']), 'Content-Type': 'application/json' }
|
||||||
headers = { 'Authorization': ('Basic %s' % auth), 'Content-Type': 'application/json' }
|
|
||||||
client.request('DELETE', '/api/v1/databases/%s/groups/%s' % (database_name, group_name), '', headers)
|
client.request('DELETE', '/api/v1/databases/%s/groups/%s' % (database_name, group_name), '', headers)
|
||||||
response = client.getresponse()
|
response = client.getresponse()
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
plpy.warning('group creation error: ' + str(err))
|
plpy.warning('group creation error: ' + str(err))
|
||||||
raise err
|
raise err
|
||||||
|
|
||||||
$$ LANGUAGE 'plpythonu' VOLATILE;
|
$$ LANGUAGE 'plpythonu' VOLATILE;
|
||||||
|
|
||||||
DO LANGUAGE 'plpgsql' $$
|
DO LANGUAGE 'plpgsql' $$
|
||||||
@@ -61,8 +57,7 @@ CREATE TYPE _CDB_Group_API_Params AS (
|
|||||||
host text,
|
host text,
|
||||||
port int,
|
port int,
|
||||||
timeout int,
|
timeout int,
|
||||||
username text,
|
auth text
|
||||||
password text
|
|
||||||
);
|
);
|
||||||
|
|
||||||
-- This must be explicitally extracted because "composite types are currently not supported".
|
-- This must be explicitally extracted because "composite types are currently not supported".
|
||||||
@@ -77,7 +72,8 @@ $$
|
|||||||
else:
|
else:
|
||||||
import json
|
import json
|
||||||
params = json.loads(conf)
|
params = json.loads(conf)
|
||||||
return { "host": params['host'], "port": params['port'], 'timeout': params['timeout'], 'username': params['username'], 'password': params['password'] }
|
auth = plpy.execute("SELECT cartodb._CDB_Group_API_Auth('%s', '%s') as auth" % (params['username'], params['password']))[0]['auth']
|
||||||
|
return { "host": params['host'], "port": params['port'], 'timeout': params['timeout'], 'auth': auth }
|
||||||
# return params
|
# return params
|
||||||
$$ LANGUAGE 'plpythonu' VOLATILE;
|
$$ LANGUAGE 'plpythonu' VOLATILE;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user