Skip to content

Commit 26752c6

Browse files
authored
Add get_grafeas_client method. (googleapis#8381)
1 parent 387b8e5 commit 26752c6

7 files changed

Lines changed: 112 additions & 67 deletions

File tree

containeranalysis/google/cloud/devtools/containeranalysis_v1/gapic/container_analysis_client.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
from google.iam.v1 import policy_pb2
4040

4141

42+
from grafeas import grafeas_v1
43+
from grafeas.grafeas_v1.gapic.transports import grafeas_grpc_transport
44+
4245
_GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution(
4346
"google-cloud-containeranalysis"
4447
).version
@@ -194,6 +197,18 @@ def __init__(
194197
# timeout, and the like.
195198
self._inner_api_calls = {}
196199

200+
def get_grafeas_client(self):
201+
"""Returns an equivalent grafeas client.
202+
203+
Returns:
204+
A :class:`~grafeas.grafeas_v1.GrafeasClient` instance.
205+
"""
206+
grafeas_transport = grafeas_grpc_transport.GrafeasGrpcTransport(
207+
self.SERVICE_ADDRESS, self.transport._OAUTH_SCOPES
208+
)
209+
210+
return grafeas_v1.GrafeasClient(grafeas_transport)
211+
197212
# Service calls
198213
def set_iam_policy(
199214
self,

containeranalysis/google/cloud/devtools/containeranalysis_v1/proto/containeranalysis.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ option go_package = "google.golang.org/genproto/googleapis/devtools/containerana
2727
option java_multiple_files = true;
2828
option java_package = "com.google.containeranalysis.v1";
2929
option objc_class_prefix = "GCA";
30+
option ruby_package = "Google::Cloud::ContainerAnalysis::V1";
3031

3132
// Retrieves analysis results of Cloud components such as Docker container
3233
// images. The Container Analysis API is an implementation of the

containeranalysis/google/cloud/devtools/containeranalysis_v1/proto/containeranalysis_pb2.py

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

containeranalysis/noxfile.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323

2424
LOCAL_DEPS = (os.path.join("..", "api_core"), os.path.join("..", "core"))
2525

26+
BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
27+
28+
if os.path.exists("samples"):
29+
BLACK_PATHS.append("samples")
30+
31+
2632
@nox.session(python="3.7")
2733
def lint(session):
2834
"""Run linters.
@@ -31,13 +37,7 @@ def lint(session):
3137
serious code quality issues.
3238
"""
3339
session.install("flake8", "black", *LOCAL_DEPS)
34-
session.run(
35-
"black",
36-
"--check",
37-
"google",
38-
"tests",
39-
"docs",
40-
)
40+
session.run("black", "--check", *BLACK_PATHS)
4141
session.run("flake8", "google", "tests")
4242

4343

@@ -46,18 +46,13 @@ def blacken(session):
4646
"""Run black.
4747
4848
Format code to uniform standard.
49-
49+
5050
This currently uses Python 3.6 due to the automated Kokoro run of synthtool.
5151
That run uses an image that doesn't have 3.6 installed. Before updating this
5252
check the state of the `gcp_ubuntu_config` we use for that Kokoro run.
5353
"""
5454
session.install("black")
55-
session.run(
56-
"black",
57-
"google",
58-
"tests",
59-
"docs",
60-
)
55+
session.run("black", *BLACK_PATHS)
6156

6257

6358
@nox.session(python="3.7")
@@ -83,7 +78,7 @@ def default(session):
8378
"--cov-append",
8479
"--cov-config=.coveragerc",
8580
"--cov-report=",
86-
"--cov-fail-under=51",
81+
"--cov-fail-under=0",
8782
os.path.join("tests", "unit"),
8883
*session.posargs,
8984
)
@@ -140,21 +135,24 @@ def cover(session):
140135

141136
session.run("coverage", "erase")
142137

138+
143139
@nox.session(python="3.7")
144140
def docs(session):
145141
"""Build the docs for this library."""
146142

147-
session.install('-e', '.')
148-
session.install('sphinx', 'alabaster', 'recommonmark')
143+
session.install("-e", ".")
144+
session.install("sphinx", "alabaster", "recommonmark")
149145

150-
shutil.rmtree(os.path.join('docs', '_build'), ignore_errors=True)
146+
shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
151147
session.run(
152-
'sphinx-build',
153-
'-W', # warnings as errors
154-
'-T', # show full traceback on exception
155-
'-N', # no colors
156-
'-b', 'html',
157-
'-d', os.path.join('docs', '_build', 'doctrees', ''),
158-
os.path.join('docs', ''),
159-
os.path.join('docs', '_build', 'html', ''),
148+
"sphinx-build",
149+
"-W", # warnings as errors
150+
"-T", # show full traceback on exception
151+
"-N", # no colors
152+
"-b",
153+
"html",
154+
"-d",
155+
os.path.join("docs", "_build", "doctrees", ""),
156+
os.path.join("docs", ""),
157+
os.path.join("docs", "_build", "html", ""),
160158
)

containeranalysis/setup.py

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,61 +20,60 @@
2020
import setuptools
2121

2222

23-
24-
name = 'google-cloud-containeranalysis'
25-
description = 'Container Analysis API API client library'
26-
version = '0.1.0'
27-
release_status = '3 - Alpha'
23+
name = "google-cloud-containeranalysis"
24+
description = "Container Analysis API API client library"
25+
version = "0.1.0"
26+
release_status = "3 - Alpha"
2827
dependencies = [
29-
'google-api-core[grpc] >= 1.4.1, < 2.0.0dev',
30-
'grpc-google-iam-v1 >= 0.11.1, < 0.12dev',
31-
'enum34; python_version < "3.4"',
28+
"google-api-core[grpc] >= 1.4.1, < 2.0.0dev",
29+
"grpc-google-iam-v1 >= 0.11.1, < 0.12dev",
30+
'enum34; python_version < "3.4"',
31+
"grafeas",
3232
]
3333

3434

35-
3635
package_root = os.path.abspath(os.path.dirname(__file__))
3736

38-
readme_filename = os.path.join(package_root, 'README.rst')
39-
with io.open(readme_filename, encoding='utf-8') as readme_file:
37+
readme_filename = os.path.join(package_root, "README.rst")
38+
with io.open(readme_filename, encoding="utf-8") as readme_file:
4039
readme = readme_file.read()
4140

4241
packages = [
43-
package for package in setuptools.find_packages()
44-
if package.startswith('google')]
42+
package for package in setuptools.find_packages() if package.startswith("google")
43+
]
4544

46-
namespaces = ['google']
47-
if 'google.cloud' in packages:
48-
namespaces.append('google.cloud')
45+
namespaces = ["google"]
46+
if "google.cloud" in packages:
47+
namespaces.append("google.cloud")
4948

5049

5150
setuptools.setup(
5251
name=name,
5352
version=version,
5453
description=description,
5554
long_description=readme,
56-
author='Google LLC',
57-
author_email='googleapis-packages@google.com',
58-
license='Apache 2.0',
59-
url='https://github.com/googleapis/google-cloud-python',
55+
author="Google LLC",
56+
author_email="googleapis-packages@google.com",
57+
license="Apache 2.0",
58+
url="https://github.com/googleapis/google-cloud-python",
6059
classifiers=[
6160
release_status,
62-
'Intended Audience :: Developers',
63-
'License :: OSI Approved :: Apache Software License',
64-
'Programming Language :: Python',
65-
'Programming Language :: Python :: 2',
66-
'Programming Language :: Python :: 2.7',
67-
'Programming Language :: Python :: 3',
68-
'Programming Language :: Python :: 3.4',
69-
'Programming Language :: Python :: 3.5',
70-
'Programming Language :: Python :: 3.6',
71-
'Operating System :: OS Independent',
72-
'Topic :: Internet',
61+
"Intended Audience :: Developers",
62+
"License :: OSI Approved :: Apache Software License",
63+
"Programming Language :: Python",
64+
"Programming Language :: Python :: 2",
65+
"Programming Language :: Python :: 2.7",
66+
"Programming Language :: Python :: 3",
67+
"Programming Language :: Python :: 3.4",
68+
"Programming Language :: Python :: 3.5",
69+
"Programming Language :: Python :: 3.6",
70+
"Operating System :: OS Independent",
71+
"Topic :: Internet",
7372
],
74-
platforms='Posix; MacOS X; Windows',
73+
platforms="Posix; MacOS X; Windows",
7574
packages=packages,
7675
namespace_packages=namespaces,
7776
install_requires=dependencies,
7877
include_package_data=True,
7978
zip_safe=False,
80-
)
79+
)

containeranalysis/synth.metadata

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
2-
"updateTime": "2019-06-05T22:45:41.734439Z",
2+
"updateTime": "2019-06-18T00:23:56.692141Z",
33
"sources": [
44
{
55
"generator": {
66
"name": "artman",
7-
"version": "0.23.1",
8-
"dockerImage": "googleapis/artman@sha256:9d5cae1454da64ac3a87028f8ef486b04889e351c83bb95e83b8fab3959faed0"
7+
"version": "0.26.0",
8+
"dockerImage": "googleapis/artman@sha256:6db0735b0d3beec5b887153a2a7c7411fc7bb53f73f6f389a822096bd14a3a15"
99
}
1010
},
1111
{
1212
"git": {
1313
"name": "googleapis",
1414
"remote": "https://github.com/googleapis/googleapis.git",
15-
"sha": "5487c78983f6bd5bbafa69166593826a90778a2f",
16-
"internalRef": "251716150"
15+
"sha": "384aa843867c4d17756d14a01f047b6368494d32",
16+
"internalRef": "253675319"
1717
}
1818
},
1919
{

containeranalysis/synth.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,43 @@
3333
include_protos=True,
3434
)
3535

36-
excludes = ["nox.py", "setup.py", "google/cloud/containeranalysis_v1/proto"]
36+
excludes = ["nox.py", "setup.py", "google/cloud/containeranalysis_v1/proto", "README.rst", "docs/index.rst"]
3737

3838
s.move(library, excludes=excludes)
3939
# .proto files end up in the wrong place by default
4040
s.move(library / "google/cloud/containeranalysis_v1/proto", "google/cloud/devtools/containeranalysis_v1/proto")
4141

42+
43+
# Insert helper method to get grafeas client
44+
s.replace("google/**/container_analysis_client.py",
45+
r"""_GAPIC_LIBRARY_VERSION = pkg_resources\.get_distribution\(
46+
'google-cloud-containeranalysis',
47+
\)\.version""",
48+
r"""from grafeas import grafeas_v1
49+
from grafeas.grafeas_v1.gapic.transports import grafeas_grpc_transport
50+
51+
_GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution(
52+
"google-cloud-containeranalysis"
53+
).version
54+
""")
55+
56+
s.replace("google/**/container_analysis_client.py",
57+
r''' \# Service calls
58+
def set_iam_policy\(''',
59+
r''' def get_grafeas_client(self):
60+
"""Returns an equivalent grafeas client.
61+
62+
Returns:
63+
A :class:`~grafeas.grafeas_v1.GrafeasClient` instance.
64+
"""
65+
grafeas_transport = grafeas_grpc_transport.GrafeasGrpcTransport(
66+
self.SERVICE_ADDRESS,
67+
self.transport._OAUTH_SCOPES)
68+
69+
return grafeas_v1.GrafeasClient(grafeas_transport)
70+
71+
# Service calls
72+
def set_iam_policy(''')
4273
# ----------------------------------------------------------------------------
4374
# Add templated files
4475
# ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)