1 ################################################################################
2 # Copyright (c) 2020 AT&T Intellectual Property. #
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 #
8 # http://www.apache.org/licenses/LICENSE-2.0 #
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 ################################################################################
18 from flask import make_response
19 from flask_restx 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
24 log = logging.getLogger(__name__)
25 ns = api.namespace('charts', description='Managing helm charts')
29 class ChartsList(Resource):
31 @api.response(200, 'Get helm chart list OK')
32 @api.response(500, 'Get helm chart list failed', error_message_model)
35 Returns the list of xApp helm charts that have been onboarded.
38 return get_charts_list()
41 @ns.route('/xapp/<string:xapp_chart_name>')
42 class VersionList(Resource):
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):
48 Returns the helm chart for the specified xApp.
50 return get_charts_list(xapp_chart_name=xapp_chart_name)
53 @ns.route('/xapp/<string:xapp_chart_name>/ver/<string:version>')
54 class ChartsFetcher(Resource):
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):
61 Returns the helm chart for the specified xApp and version.
64 content, status = download_chart_package(xapp_chart_name=xapp_chart_name, version=version)
67 return content, status
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\"")
76 @ns.route('/xapp/<string:xapp_chart_name>/ver/<string:version>/values.yaml')
77 class ValuesYamlFetcher(Resource):
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):
84 Returns the helm values.yaml file of the specified xApp and version.
87 content, status = download_values_yaml(xapp_chart_name=xapp_chart_name, version=version)
90 return content, status
92 response = make_response(content)
93 response.headers.set("Content-Type", "text/x-yaml")
94 response.headers.set("Content-Disposition", "attachment; filename=\"values.yaml\"")