forked from mikeghen/python_api_samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproduction_project_catchup.py
More file actions
54 lines (43 loc) · 1.53 KB
/
production_project_catchup.py
File metadata and controls
54 lines (43 loc) · 1.53 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
import yaml ### install the pyyaml package
from lookerapi import LookerApi
from datetime import datetime
from pprint import pprint
from argparse import ArgumentParser
### ------- HERE ARE PARAMETERS TO CONFIGURE -------
host = 'localhost'
project_name = 'hub'
branch_name = 'dev-spoke-spoke-pwrc'
user_id = 945
role_to_add_id = 136
### ------- OPEN THE CONFIG FILE and INSTANTIATE API -------
f = open('config.yml')
params = yaml.load(f)
f.close()
my_host = params['hosts'][host]['host']
my_secret = params['hosts'][host]['secret']
my_token = params['hosts'][host]['token']
looker = LookerApi(host=my_host,
token=my_token,
secret = my_secret)
#add role to get access to core model
roles = looker.get_user_role(user_id,"id")
roles_source = roles.copy()
roles.append({"id":role_to_add_id})
looker.set_user_role(user_id,roles)
#begin issuing calls as the user who needs to catch up to production
looker.login_user(user_id)
looker.update_session_workspace()
looker.switch_git_branch(project_name,branch_name)
looker.reset_to_production(project_name)
#
# #might need to use ref in production catch up rather than reset to prod but seems fine in testing
# #alternate would be PUT /projects/{project_id}/git_branch with {"ref":"master_ref"} as body which we could get as the admin
#
# # #need to go back to old authentication with admin
admin_looker = LookerApi(host=my_host,
token=my_token,
secret = my_secret)
#
# # #remove role added
#
admin_looker.set_user_role(user_id,body=roles_source)