CSIT Data driver
[csit.git] / resources / tools / storage / __main__.py
1 #!/usr/bin/env python3
2
3 # Copyright (c) 2021 Cisco and/or its affiliates.
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
16 """S3 Storage Backend."""
17
18 from json import dumps
19
20 from argparse import ArgumentParser, RawDescriptionHelpFormatter
21
22 from .storage import Storage
23
24
25 def main():
26     """
27     Main entry function when called from CLI.
28     """
29     parser = ArgumentParser(
30         description=u"S3 Storage Backend Operation.",
31         formatter_class=RawDescriptionHelpFormatter
32     )
33     parser.add_argument(
34         u"-e", u"--expression", required=False, type=str,
35         default=u"select * from s3object s",
36         help=u"S3 compatible SQL query."
37     )
38
39     args = parser.parse_args()
40
41     json_iterator = Storage(
42         endpoint_url=u"http://storage.service.consul:9000",
43         bucket=u"docs",
44         profile_name=u"nomad-s3"
45     ).s3_file_processing(
46         prefix=u"", expression=args.expression
47     )
48     for item in json_iterator:
49         print(dumps(item, indent=4, sort_keys=False))
50
51
52 if __name__ == u"__main__":
53     main()