-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathadd_generic_devices_from_csv.py
More file actions
68 lines (62 loc) · 1.96 KB
/
add_generic_devices_from_csv.py
File metadata and controls
68 lines (62 loc) · 1.96 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
import duo_client
import argparse
import csv
def arg_parser():
parser = argparse.ArgumentParser()
parser.add_argument(
'--infile',
required=True,
help='The path to the input CSV file.'
)
parser.add_argument(
'--device_id_column',
default='device_id',
help='The name of the column in the csv file that has the device ID',
)
parser.add_argument(
'--mkey',
required=len(MKEY_CREDENTIALS.keys())>1,
help='The Duo Device API managment key: ',
choices=MKEY_CREDENTIALS.keys()
)
parser.add_argument(
'--ikey',
required=len(MKEY_CREDENTIALS.keys())>1,
help='The Duo Device API integration key: ',
choices=MKEY_CREDENTIALS.keys()
)
parser.add_argument(
'--skey',
required=len(MKEY_CREDENTIALS.keys())>1,
help='The Duo Device API secret key: ',
choices=MKEY_CREDENTIALS.keys()
)
parser.add_argument(
'--host',
required=len(MKEY_CREDENTIALS.keys())>1,
help='The Duo Device API hostname ("api-....duosecurity.com"): ',
choices=MKEY_CREDENTIALS.keys()
)
return parser
def upload_identifiers(device_api, csvfile, device_id_column):
device_ids = []
with open(args.infile) as csvfile:
reader = csv.DictReader(csvfile, skipinitialspace=True)
for row in reader:
if row[device_id_column]:
device_ids.append({'device_id': row[device_id_column]})
if not len(device_ids):
raise ValueError(
f'No device IDs read from input column: {device_id_column}')
self.device_api.activate_cache_with_devices(device_ids)
def main():
parser = arg_parser()
args = parser.parse_args()
device_api = duo_client.client.Client(
ikey=args.ikey,
skey=args.skey,
host=args.host,
mkey=args.mkey
)
upload_identifiers(device_api, args.infile, args.device_id_column)