Removing committers
[ric-plt/appmgr.git] / xapp_orchestrater / dev / xapp_onboarder / xapp_onboarder / api / endpoints / charts_ep.py
1 ################################################################################
2 #   Copyright (c) 2020 AT&T Intellectual Property.                             #
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 ################################################################################
16
17 import logging
18 from flask import make_response
19 from flask_restplus import Resource
20 from xapp_onboarder.api.api_reference import api
21 from xapp_onboarder.api.charts import get_charts_list, download_chart_package, download_values_yaml
22 from xapp_onboarder.api.models.response_models import error_message_model
23
24 log = logging.getLogger(__name__)
25 ns = api.namespace('charts', description='Managing helm charts')
26
27
28 @ns.route('')
29 class ChartsList(Resource):
30
31     @api.response(200, 'Get helm chart list OK')
32     @api.response(500, 'Get helm chart list failed', error_message_model)
33     def get(self):
34         """
35         Returns the list of xApp helm charts that have been onboarded.
36         """
37
38         return get_charts_list()
39
40
41 @ns.route('/xapp/<string:xapp_chart_name>')
42 class VersionList(Resource):
43
44     @api.response(200, 'Get helm chart OK')
45     @api.response(500, 'Get helm chart failed', error_message_model)
46     def get(self, xapp_chart_name):
47         """
48         Returns the helm chart for the specified xApp.
49         """
50         return get_charts_list(xapp_chart_name=xapp_chart_name)
51
52
53 @ns.route('/xapp/<string:xapp_chart_name>/ver/<string:version>')
54 class ChartsFetcher(Resource):
55
56     @api.response(200, 'Get helm chart package OK')
57     @api.response(500, 'Get helm chart package failed', error_message_model)
58     @api.produces(['application/gzip'])
59     def get(self, xapp_chart_name, version):
60         """
61         Returns the helm chart for the specified xApp and version.
62         """
63
64         content, status = download_chart_package(xapp_chart_name=xapp_chart_name, version=version)
65
66         if status != 200:
67             return content, status
68
69         response = make_response(content)
70         response.headers.set("Content-Type", "application/gzip")
71         response.headers.set("Content-Disposition",
72                              "attachment; filename=\"" + xapp_chart_name + "-" + version + ".tgz\"")
73         return response
74
75
76 @ns.route('/xapp/<string:xapp_chart_name>/ver/<string:version>/values.yaml')
77 class ValuesYamlFetcher(Resource):
78
79     @api.response(200, 'Get helm chart values.yaml OK')
80     @api.response(500, 'Get helm chart values.yaml failed', error_message_model)
81     @api.produces(['text/x-yaml'])
82     def get(self, xapp_chart_name, version):
83         """
84         Returns the helm values.yaml file of the specified xApp and version.
85         """
86
87         content, status = download_values_yaml(xapp_chart_name=xapp_chart_name, version=version)
88
89         if status != 200:
90             return content, status
91
92         response = make_response(content)
93         response.headers.set("Content-Type", "text/x-yaml")
94         response.headers.set("Content-Disposition", "attachment; filename=\"values.yaml\"")
95
96         return response