def main(output):
    """
    Generate a c7n-org gcp projects config file
    """

    client = Session().client('cloudresourcemanager', 'v1', 'projects')

    results = []
    for page in client.execute_paged_query('list', {}):
        for project in page.get('projects', []):

            if project['lifecycleState'] != 'ACTIVE':
                continue

            project_info = {
                'project_id': project['projectId'],
                'name': project['name'],
            }

            if 'labels' in project:
                project_info['tags'] = [
                    'label:%s:%s' % (k, v) for k, v in project.get('labels', {}).items()]
            results.append(project_info)

    output.write(
        yaml.safe_dump({'projects': results}, default_flow_style=False))
def main ( output ) : client = Session ( ) . client ( 'cloudresourcemanager' , 'v1' , 'projects' ) results = [ ] for page in client . execute_paged_query ( 'list' , { } ) : for project in page . get ( 'projects' , [ ] ) : if project [ 'lifecycleState' ] != 'ACTIVE' : continue project_info = { 'project_id' : project [ 'projectId' ] , 'name' : project [ 'name' ] , } if 'labels' in project : project_info [ 'tags' ] = [ 'label:%s:%s' % ( k , v ) for k , v in project . get ( 'labels' , { } ) . items ( ) ] results . append ( project_info ) output . write ( yaml . safe_dump ( { 'projects' : results } , default_flow_style = False ) )
Generate a c7n-org gcp projects config file