From 5ac727cb30f387c701a3da18f5a1e2f0935215f2 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 15 Mar 2019 09:43:32 +0000 Subject: [PATCH 1/2] addition metatron auth --- pymetis/clients/charts.py | 19 +++++++++++++++++-- pymetis/clients/dashboards.py | 19 +++++++++++++++++-- pymetis/clients/datasources.py | 24 ++++++++++++++++++++++-- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/pymetis/clients/charts.py b/pymetis/clients/charts.py index c2cc675..1c1badd 100644 --- a/pymetis/clients/charts.py +++ b/pymetis/clients/charts.py @@ -2,6 +2,21 @@ def get(hostname, port, did): - headers = {'Accept': 'application/json', 'Content-Type': 'application/json'} + loginHeaders = {'Authorization': 'Basic cG9sYXJpc19jbGllbnQ6cG9sYXJpcw==', 'Content-Type' : 'application/x-www-form-urlencoded'} + loginData = {'grant_type':'password', 'scope':'write', 'username':'polaris', 'password':'polaris'} + loginUrl = "http://" + hostname + ":" + port + "/oauth/token" + res = requests.post(loginUrl, loginData, headers=loginHeaders).json() + + # login check + #print(res) + + token_type = res["token_type"] + token = res["access_token"] + auth = token_type + ' ' + token + + #auth value check + #print('auth:' + auth) + + headers = {'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': auth} url = "http://" + hostname + ":" + port + "/api/widgets/" + did + "/data" - return requests.post(url, headers=headers).json() \ No newline at end of file + return requests.post(url, headers=headers).json() diff --git a/pymetis/clients/dashboards.py b/pymetis/clients/dashboards.py index 893031b..697112f 100644 --- a/pymetis/clients/dashboards.py +++ b/pymetis/clients/dashboards.py @@ -2,6 +2,21 @@ def get(hostname, port, did): - headers = {'Accept': 'application/json', 'Content-Type': 'application/json'} + loginHeaders = {'Authorization': 'Basic cG9sYXJpc19jbGllbnQ6cG9sYXJpcw==', 'Content-Type' : 'application/x-www-form-urlencoded'} + loginData = {'grant_type':'password', 'scope':'write', 'username':'polaris', 'password':'polaris'} + loginUrl = "http://" + hostname + ":" + port + "/oauth/token" + res = requests.post(loginUrl, loginData, headers=loginHeaders).json() + + # login check + #print(res) + + token_type = res["token_type"] + token = res["access_token"] + auth = token_type + ' ' + token + + #auth value check + #print('auth:' + auth) + + headers = {'Accept': 'application/json', 'Content-Type': 'application/json','Authorization': auth} url = "http://" + hostname + ":" + port + "/api/dashboards/" + did + "/data" - return requests.post(url, headers=headers).json() \ No newline at end of file + return requests.post(url, headers=headers).json() diff --git a/pymetis/clients/datasources.py b/pymetis/clients/datasources.py index 235c097..aa8e4b6 100644 --- a/pymetis/clients/datasources.py +++ b/pymetis/clients/datasources.py @@ -2,6 +2,26 @@ def get(hostname, port, did): - headers = {'Accept': 'application/json', 'Content-Type': 'application/json'} + + loginHeaders = {'Authorization': 'Basic cG9sYXJpc19jbGllbnQ6cG9sYXJpcw==', 'Content-Type' : 'application/x-www-form-urlencoded'} + loginData = {'grant_type':'password', 'scope':'write', 'username':'polaris', 'password':'polaris'} + loginUrl = "http://" + hostname + ":" + port + "/oauth/token" + res = requests.post(loginUrl, loginData, headers=loginHeaders).json() + + # login check + #print(res) + + token_type = res["token_type"] + token = res["access_token"] + auth = token_type + ' ' + token + + #auth value check + #print('auth:' + auth) + + headers = {'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': auth} url = "http://" + hostname + ":" + port + "/api/datasources/" + did + "/data" - return requests.post(url, headers=headers).json() \ No newline at end of file + + # url value check + #print('url:' + url) + + return requests.post(url, headers=headers).json() From 61cad72a4f6e639fb705d39c3c7f840c64cb1e95 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 29 Mar 2019 13:05:11 +0000 Subject: [PATCH 2/2] add row limit --- pymetis/clients/charts.py | 4 ++-- pymetis/clients/dashboards.py | 4 ++-- pymetis/clients/datasources.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pymetis/clients/charts.py b/pymetis/clients/charts.py index 1c1badd..a20d43a 100644 --- a/pymetis/clients/charts.py +++ b/pymetis/clients/charts.py @@ -1,7 +1,7 @@ import requests -def get(hostname, port, did): +def get(hostname, port, did, limit): loginHeaders = {'Authorization': 'Basic cG9sYXJpc19jbGllbnQ6cG9sYXJpcw==', 'Content-Type' : 'application/x-www-form-urlencoded'} loginData = {'grant_type':'password', 'scope':'write', 'username':'polaris', 'password':'polaris'} loginUrl = "http://" + hostname + ":" + port + "/oauth/token" @@ -18,5 +18,5 @@ def get(hostname, port, did): #print('auth:' + auth) headers = {'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': auth} - url = "http://" + hostname + ":" + port + "/api/widgets/" + did + "/data" + url = "http://" + hostname + ":" + port + "/api/widgets/" + did + "/data?limit=" + limit return requests.post(url, headers=headers).json() diff --git a/pymetis/clients/dashboards.py b/pymetis/clients/dashboards.py index 697112f..93f23dc 100644 --- a/pymetis/clients/dashboards.py +++ b/pymetis/clients/dashboards.py @@ -1,7 +1,7 @@ import requests -def get(hostname, port, did): +def get(hostname, port, did, limit): loginHeaders = {'Authorization': 'Basic cG9sYXJpc19jbGllbnQ6cG9sYXJpcw==', 'Content-Type' : 'application/x-www-form-urlencoded'} loginData = {'grant_type':'password', 'scope':'write', 'username':'polaris', 'password':'polaris'} loginUrl = "http://" + hostname + ":" + port + "/oauth/token" @@ -18,5 +18,5 @@ def get(hostname, port, did): #print('auth:' + auth) headers = {'Accept': 'application/json', 'Content-Type': 'application/json','Authorization': auth} - url = "http://" + hostname + ":" + port + "/api/dashboards/" + did + "/data" + url = "http://" + hostname + ":" + port + "/api/dashboards/" + did + "/data?limit=" + limit return requests.post(url, headers=headers).json() diff --git a/pymetis/clients/datasources.py b/pymetis/clients/datasources.py index aa8e4b6..6523eec 100644 --- a/pymetis/clients/datasources.py +++ b/pymetis/clients/datasources.py @@ -1,7 +1,7 @@ import requests -def get(hostname, port, did): +def get(hostname, port, did, limit): loginHeaders = {'Authorization': 'Basic cG9sYXJpc19jbGllbnQ6cG9sYXJpcw==', 'Content-Type' : 'application/x-www-form-urlencoded'} loginData = {'grant_type':'password', 'scope':'write', 'username':'polaris', 'password':'polaris'} @@ -19,7 +19,7 @@ def get(hostname, port, did): #print('auth:' + auth) headers = {'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': auth} - url = "http://" + hostname + ":" + port + "/api/datasources/" + did + "/data" + url = "http://" + hostname + ":" + port + "/api/datasources/" + did + "/data?limit=" + limit # url value check #print('url:' + url)