Completed
Pull Request — master (#2334)
by Edward
06:02
created

st2api.controllers.exp.ResourceController   A

Complexity

Total Complexity 32

Size/Duplication

Total Lines 199
Duplicated Lines 0 %
Metric Value
wmc 32
dl 0
loc 199
rs 9.6
1
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  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
from pecan import (abort, expose, request, rest)
17
from six.moves import http_client
18
19
# from st2api.controllers import resource
20
from st2common import log as logging
21
22
LOG = logging.getLogger(__name__)
23
24
25
class ActionAliasController(rest.RestController):
26
27
    @expose()
28
    def post(self, action_alias):
29
        self._redirect(request)
30
31
    @expose()
32
    def put(self, action_alias_ref_or_id, action_alias):
33
        self._redirect(request)
34
35
    @expose()
36
    def delete(self, action_alias_ref_or_id):
37
        self._redirect(request)
38
39
    def _redirect(self, request_instance):
40
        redirect_url = request.path_url.replace('/exp/', '/v1/')
41
        LOG.debug('Redirecting to: %s', redirect_url)
42
        # In theory, we could redirect using pecan's redirect method but there is
43
        # a bug that doesn't display the name of the moved location in the body.
44
        # redirect_path = request.path.replace('/exp/', '/v1')
45
        # redirect(location=redirect_path, internal=False, request=request,
46
        #          code=http_client.MOVED_PERMANENTLY)
47
        msg = 'The resource has been permanently moved to %s.' % redirect_url
48
        abort(status_code=http_client.MOVED_PERMANENTLY,
49
              headers={'Location': redirect_url},
50
              detail=msg,
51
              comment=msg)
52