|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | +# you may not use this file except in compliance with the License. |
| 3 | +# You may obtain a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +# See the License for the specific language governing permissions and |
| 11 | +# limitations under the License. |
| 12 | + |
| 13 | +import pecan |
| 14 | +from wsme import types as wtypes |
| 15 | + |
| 16 | +from oslo_log import log |
| 17 | + |
| 18 | +from magnum.api.controllers import base |
| 19 | +from magnum.api.controllers.v1 import types |
| 20 | +from magnum.api import expose |
| 21 | +from magnum.api import utils as api_utils |
| 22 | +from magnum.common import policy |
| 23 | + |
| 24 | + |
| 25 | +LOG = log.getLogger(__name__) |
| 26 | + |
| 27 | + |
| 28 | +class ClusterID(wtypes.Base): |
| 29 | + """API representation of a cluster ID |
| 30 | +
|
| 31 | + This class enforces type checking and value constraints, and converts |
| 32 | + between the internal object model and the API representation of a cluster |
| 33 | + ID. |
| 34 | + """ |
| 35 | + |
| 36 | + uuid = types.uuid |
| 37 | + """Unique UUID for this cluster""" |
| 38 | + |
| 39 | + def __init__(self, uuid): |
| 40 | + self.uuid = uuid |
| 41 | + |
| 42 | + |
| 43 | +class CredentialsController(base.Controller): |
| 44 | + """REST controller for cluster actions.""" |
| 45 | + def __init__(self): |
| 46 | + super(CredentialsController, self).__init__() |
| 47 | + |
| 48 | + @base.Controller.api_version("1.12") |
| 49 | + @expose.expose(ClusterID, types.uuid_or_name, status_code=202) |
| 50 | + def patch(self, cluster_ident): |
| 51 | + """Rotate the credential in use by a cluster. |
| 52 | +
|
| 53 | + :param cluster_ident: UUID of a cluster or logical name of the cluster. |
| 54 | + """ |
| 55 | + |
| 56 | + context = pecan.request.context |
| 57 | + policy.enforce(context, 'credential:rotate', |
| 58 | + action='credential:rotate') |
| 59 | + |
| 60 | + cluster = api_utils.get_resource('Cluster', cluster_ident) |
| 61 | + # NOTE(northcottmt): Perform rotation synchronously as there aren't any |
| 62 | + # slow apply/upgrade operations to do |
| 63 | + pecan.request.rpcapi.credential_rotate(cluster) |
| 64 | + |
| 65 | + return ClusterID(cluster.uuid) |
0 commit comments