-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstPasswordUpdate.py
More file actions
60 lines (52 loc) · 1.74 KB
/
stPasswordUpdate.py
File metadata and controls
60 lines (52 loc) · 1.74 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
import json
import warnings
from textwrap import indent
import dotenv
from func import *
import hvac
siteToMigrate = [{'hrisy': 'SMB'}]
# SETTINGS
warnings.filterwarnings("ignore", category=DeprecationWarning)
dotenv_path = ".env"
dotenv.load_dotenv(dotenv_path)
hashiToken = os.environ.get("VAULT_TOKEN")
hashiHost = os.environ.get("VAULT_HOST")
# Authenticate with ST
s_source, source_ST = Authenticate("ST_NON_PROD")
s_source.verify = False
s_source.headers.update({'Accept': 'application/json'})
s_target, target_ST = Authenticate("ST_PROD")
s_target.verify = False
s_target.headers.update({'Accept': 'application/json'})
s_target.headers.update({'Content-Type': 'application/json'})
# VARS
vault = 'SecureTransport'
tier = 'production'
# Hashi Authentication
client = hvac.Client(
url=hashiHost,
token=hashiToken,
verify=False
)
# EXPORT FROM SOURCE ST
resource = "sites/"
for sites in siteToMigrate:
for k, v in sites.items():
params = {'account': k, 'name': v}
res = s_target.get(target_ST + resource, params=params)
site = res.json()['result'][0]
path = f'accounts/{k}/sites/{tier}/{v}'
read_response = read_secret_version(client, vault, path)
data = read_response['data'].get('data', {})
del data['siteName']
for key, value in data.items():
site['customProperties'][key] = value
payload = [
{
"op": "replace",
"path": f"/customProperties/{key}",
"value": f"{value}"
}
]
response = s_target.patch(target_ST + resource + site['id'], json=payload)
logging.info(f"Password update status {response.status_code}; Message: {response.text}")