• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 Google Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15################################################################################
16"""Cloud function that requests coverage builds."""
17import base64
18
19import google.auth
20from google.cloud import ndb
21
22import build_and_run_coverage
23import request_build
24
25BASE_PROJECT = 'oss-fuzz-base'
26
27
28def get_build_steps(project_name, image_project, base_images_project):
29  """Retrieve build steps."""
30  build_config = request_build.get_empty_config()
31  project_yaml_contents, dockerfile_lines = request_build.get_project_data(
32      project_name)
33  return build_and_run_coverage.get_build_steps(project_name,
34                                                project_yaml_contents,
35                                                dockerfile_lines, image_project,
36                                                base_images_project,
37                                                build_config)
38
39
40def request_coverage_build(event, context):
41  """Entry point for coverage build cloud function."""
42  del context  # Unused.
43  if 'data' in event:
44    project_name = base64.b64decode(event['data']).decode('utf-8')
45  else:
46    raise RuntimeError('Project name missing from payload')
47
48  with ndb.Client().context():
49    credentials, cloud_project = google.auth.default()
50    build_steps = get_build_steps(project_name, cloud_project, BASE_PROJECT)
51    if not build_steps:
52      return
53    request_build.run_build(project_name,
54                            build_steps,
55                            credentials,
56                            build_and_run_coverage.COVERAGE_BUILD_TYPE,
57                            cloud_project=cloud_project)
58