1# -*- coding: utf-8 -*- # 2# Copyright 2017 Google LLC. All Rights Reserved. 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"""Restore a version.""" 16 17from __future__ import absolute_import 18from __future__ import division 19from __future__ import unicode_literals 20 21from googlecloudsdk.api_lib.cloudkms import base as cloudkms_base 22from googlecloudsdk.calliope import base 23from googlecloudsdk.command_lib.kms import flags 24 25 26class Restore(base.UpdateCommand): 27 """Restore a version scheduled for destruction. 28 29 Restores the given version that was scheduled to be destroyed. 30 31 This moves the version from Scheduled for destruction to Disabled. 32 Only versions which are Scheduled for destruction can be Restored. 33 34 ## EXAMPLES 35 36 The following command restores version 9 of key `frodo` within 37 keyring `fellowship` and location `us-east1` which was previously scheduled 38 for destruction: 39 40 $ {command} 9 --location=us-east1 --keyring=fellowship --key=frodo 41 """ 42 43 @staticmethod 44 def Args(parser): 45 flags.AddKeyVersionResourceArgument(parser, 'to restore') 46 47 def Run(self, args): 48 # pylint: disable=line-too-long 49 client = cloudkms_base.GetClientInstance() 50 messages = cloudkms_base.GetMessagesModule() 51 52 version_ref = flags.ParseCryptoKeyVersionName(args) 53 req = messages.CloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsRestoreRequest( 54 name=version_ref.RelativeName()) 55 56 ckv = client.projects_locations_keyRings_cryptoKeys_cryptoKeyVersions 57 return ckv.Restore(req) 58