forked from influxdata/influxdb-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtutorial_authorization.py
32 lines (23 loc) · 966 Bytes
/
tutorial_authorization.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- coding: utf-8 -*-
"""Tutorial how to authorize InfluxDB client by custom Authorization token."""
import argparse
from influxdb import InfluxDBClient
def main(token='my-token'):
"""Instantiate a connection to the InfluxDB."""
client = InfluxDBClient(username=None, password=None,
headers={"Authorization": token})
print("Use authorization token: " + token)
version = client.ping()
print("Successfully connected to InfluxDB: " + version)
pass
def parse_args():
"""Parse the args from main."""
parser = argparse.ArgumentParser(
description='example code to play with InfluxDB')
parser.add_argument('--token', type=str, required=False,
default='my-token',
help='Authorization token for the proxy that is ahead the InfluxDB.')
return parser.parse_args()
if __name__ == '__main__':
args = parse_args()
main(token=args.token)