1# -*- coding: utf-8 -*- #
2# Copyright 2020 Google LLC. All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#    http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15"""Utility for making On-Demand Scanning API calls."""
16
17from __future__ import absolute_import
18from __future__ import division
19from __future__ import unicode_literals
20
21from googlecloudsdk.api_lib.util import apis
22
23PARENT_TEMPLATE = 'projects/{}/locations/{}'
24
25
26def GetClient(version):
27  return apis.GetClientInstance('ondemandscanning', version)
28
29
30def GetMessages(version):
31  return apis.GetMessagesModule('ondemandscanning', version)
32
33
34def AnalyzePackagesBeta(project, location, resource_uri, packages):
35  """Make an RPC to the On-Demand Scanning v1beta1 AnalyzePackages method."""
36  client = GetClient('v1beta1')
37  messages = GetMessages('v1beta1')
38  req = messages.OndemandscanningProjectsLocationsScansAnalyzePackagesRequest(
39      parent=PARENT_TEMPLATE.format(project, location),
40      analyzePackagesRequest=messages.AnalyzePackagesRequest(
41          packages=packages,
42          resourceUri=resource_uri),
43  )
44  return client.projects_locations_scans.AnalyzePackages(req)
45
46
47def AnalyzePackagesGA(project, location, resource_uri, packages):
48  """Make an RPC to the On-Demand Scanning v1 AnalyzePackages method."""
49  client = GetClient('v1')
50  messages = GetMessages('v1')
51  req = messages.OndemandscanningProjectsLocationsScansAnalyzePackagesRequest(
52      parent=PARENT_TEMPLATE.format(project, location),
53      analyzePackagesRequestV1=messages.AnalyzePackagesRequestV1(
54          packages=packages,
55          resourceUri=resource_uri),
56  )
57  return client.projects_locations_scans.AnalyzePackages(req)
58