...
1# Copyright 2022 Google LLC
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"""dclsampleconverter converts samples from DCL format into KCC format."""
16
17from absl import app
18from absl import flags
19from absl import logging
20from collections.abc import Sequence
21
22import resource
23import strings
24
25FLAGS = flags.FLAGS
26
27flags.DEFINE_string('service', '', 'The name of the service, snake cased')
28flags.DEFINE_string('resource', '', 'The name of the resource, snake cased')
29flags.DEFINE_string('dcl_path', '', 'The local path of the DCL GoB repo.')
30flags.DEFINE_string('kcc_path', '', 'The local path of the KCC GoB repo.')
31
32
33def main(argv: Sequence[str]) -> None:
34 logging.info(
35 f'Converting samples for service {FLAGS.service} resource {FLAGS.resource}.'
36 )
37 kcc_kind = strings.snake_to_title(
38 f'{FLAGS.service}_{FLAGS.resource}'
39 ) # e.g. compute_service_attachment -> ComputeServiceAttachment
40 r = resource.Resource(
41 service=FLAGS.service,
42 name=FLAGS.resource,
43 kcc_kind=kcc_kind,
44 dcl_dir=f'{FLAGS.dcl_path}/services/google/{FLAGS.service}',
45 kcc_testdata_dir=f'{FLAGS.kcc_path}/pkg/test/resourcefixture/testdata/basic/{FLAGS.service}/v1beta1/{kcc_kind.lower()}',
46 kcc_samples_dir=f'{FLAGS.kcc_path}/config/samples/resources/{kcc_kind.lower()}',
47 samples=[],
48 )
49 r.load_samples()
50 r.convert_samples()
51 r.write_samples()
52
53
54if __name__ == '__main__':
55 app.run(main)
View as plain text