#!/usr/bin/env python

# Copyright 2019 Google, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from googleapiclient.discovery import build
from googleapiclient.errors import Error

client_service = build('jobs', 'v3')
project_id = 'projects/' + os.environ['GOOGLE_CLOUD_PROJECT']

try:
    # Execute a query to list all companies.  Only query parameter in this case
    # is the parent project.
    response = client_service.projects().companies().list(
        parent=project_id).execute()
    if response.get('companies') is not None:
        print('Companies:')
        for company in response.get('companies'):
            print('%s: %s, %s' % (company.get('displayName'),
                                  company.get('name'), company.get('size')))
    else:
        print('No companies')

except Error as e:
    print('Got exception while listing companies')
    raise e
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,