forked from Azure/azure-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrub_vcr_auth.py
51 lines (46 loc) · 2.22 KB
/
scrub_vcr_auth.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long
import os
import tempfile
COMMAND_MODULE_PREFIX = 'azure-cli-'
PATH_TO_COMMAND_MODULES = os.path.abspath(os.path.join(os.path.abspath(__file__),
'..', '..', 'src',#'..', '..', '..', '..',
'command_modules'))
command_modules = []
insecure_cassettes = []
for name in os.listdir(PATH_TO_COMMAND_MODULES):
full_module_path = os.path.join(PATH_TO_COMMAND_MODULES, name)
if name.startswith(COMMAND_MODULE_PREFIX) and os.path.isdir(full_module_path):
command_modules += [(name, full_module_path)]
for name, fullpath in command_modules:
path_to_recordings = os.path.join(fullpath, 'azure', 'cli', 'command_modules',
name.replace(COMMAND_MODULE_PREFIX, ''),
'tests', 'recordings')
if not os.path.isdir(path_to_recordings):
continue
for name in os.listdir(path_to_recordings):
if not str.endswith(name, '.yaml'):
continue
src_path = os.path.join(path_to_recordings, name)
t = tempfile.NamedTemporaryFile('r+')
with open(src_path, 'r') as f:
for line in f:
if 'authorization: [bearer' in line.lower():
insecure_cassettes.append(name)
else:
t.write(line)
t.seek(0)
with open(src_path, 'w') as f:
for line in t:
f.write(line)
t.close()
insecure_cassettes = list(set(insecure_cassettes))
if insecure_cassettes:
print('Bearer tokens removed from the following cassettes:')
for cassette in insecure_cassettes:
print('\t{}'.format(cassette))
else:
print('All cassettes free from Bearer tokens!')