Skip to content
Permalink
12d11a0a27
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
42 lines (30 sloc) 1.37 KB
import get_folders_native
import google.auth
from google.cloud import resourcemanager_v3
credentials, project_id = google.auth.default()
client = resourcemanager_v3.ProjectsClient(credentials=credentials)
from settings import APPS_SCRIPT_FOLDER_ID, EXCLUDED_PROJECTS, ORGANIZATION_ID
def init_projects():
projects = {}
for id, folder in get_folders_native.folders.items():
proj_list = client.list_projects(parent=folder['folder'].name).projects
for proj in proj_list:
project_id = proj.project_id
if proj.parent != APPS_SCRIPT_FOLDER_ID:
projects[project_id] = {
'project': proj
}
return projects
def get_iam_policy(project_id):
if project_id not in EXCLUDED_PROJECTS:
policy = client.get_iam_policy(resource=project_id)
return policy
#get_iam_policy_cmd = IAM_POLICY_CMD + ' ' + project_id
#return json.loads(subprocess.check_output(get_iam_policy_cmd,
# shell=True,
# stderr=subprocess.STDOUT))
projects = init_projects()
for project_id in projects:
if 'iam_policy' not in projects[project_id].keys():
projects[project_id]['iam_policy'] = get_iam_policy(project_id=projects[project_id]['project'].name)
#write_projects(projects=projects)