|
3 | 3 | # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
|
4 | 4 |
|
5 | 5 | import click
|
| 6 | +import oci # noqa: F401 |
| 7 | +import six # noqa: F401 |
| 8 | +import sys # noqa: F401 |
6 | 9 | from services.key_management.src.oci_cli_kms_management.generated import kmsmanagement_cli
|
7 | 10 | from oci_cli import cli_util
|
8 | 11 | from oci_cli import json_skeleton_utils
|
@@ -134,3 +137,162 @@ def restore_from_file(ctx, **kwargs):
|
134 | 137 | ctx.invoke(kmsmanagement_cli.restore_key_from_file, **kwargs)
|
135 | 138 | except Exception:
|
136 | 139 | click.echo("Can't open the file")
|
| 140 | + |
| 141 | + |
| 142 | +@cli_util.copy_params_from_generated_command(kmsmanagement_cli.create_key_version, params_to_exclude=['']) |
| 143 | +@kmsmanagement_cli.key_version_group.command(name=cli_util.override('kms_management.create_key_version.command_name', 'create'), help=u"""Generates a new [KeyVersion] resource that provides new cryptographic material for a master encryption key. The key must be in an `ENABLED` state to be rotated. |
| 144 | +
|
| 145 | +As a management operation, this call is subject to a Key Management limit that applies to the total number of requests across all management write operations. Key Management might throttle this call to reject an otherwise valid request when the total rate of management write operations exceeds 10 requests per second for a given tenancy. |
| 146 | +
|
| 147 | +The top level --endpoint parameter must be supplied for this operation. \n[Command Reference](createKeyVersion)""") |
| 148 | +@click.pass_context |
| 149 | +@json_skeleton_utils.json_skeleton_generation_handler(input_params_to_complex_types={}, output_type={'module': 'key_management', 'class': 'KeyVersion'}) |
| 150 | +@cli_util.wrap_exceptions |
| 151 | +def create_key_version_extended(ctx, from_json, wait_for_state, max_wait_seconds, wait_interval_seconds, key_id): |
| 152 | + |
| 153 | + if isinstance(key_id, six.string_types) and len(key_id.strip()) == 0: |
| 154 | + raise click.UsageError('Parameter --key-id cannot be whitespace or empty string') |
| 155 | + |
| 156 | + kwargs = {} |
| 157 | + kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(ctx.obj['request_id']) |
| 158 | + client = cli_util.build_client('key_management', 'kms_management', ctx) |
| 159 | + result = client.create_key_version( |
| 160 | + key_id=key_id, |
| 161 | + **kwargs |
| 162 | + ) |
| 163 | + if wait_for_state: |
| 164 | + |
| 165 | + if hasattr(client, 'get_key_version') and callable(getattr(client, 'get_key_version')): |
| 166 | + try: |
| 167 | + wait_period_kwargs = {} |
| 168 | + if max_wait_seconds is not None: |
| 169 | + wait_period_kwargs['max_wait_seconds'] = max_wait_seconds |
| 170 | + if wait_interval_seconds is not None: |
| 171 | + wait_period_kwargs['max_interval_seconds'] = wait_interval_seconds |
| 172 | + |
| 173 | + click.echo('Action completed. Waiting until the resource has entered state: {}'.format(wait_for_state), file=sys.stderr) |
| 174 | + result = oci.wait_until(client, client.get_key_version(key_id, result.data.id), 'lifecycle_state', wait_for_state, **wait_period_kwargs) |
| 175 | + except oci.exceptions.MaximumWaitTimeExceeded as e: |
| 176 | + # If we fail, we should show an error, but we should still provide the information to the customer |
| 177 | + click.echo('Failed to wait until the resource entered the specified state. Outputting last known resource state', file=sys.stderr) |
| 178 | + cli_util.render_response(result, ctx) |
| 179 | + sys.exit(2) |
| 180 | + except Exception: |
| 181 | + click.echo('Encountered error while waiting for resource to enter the specified state. Outputting last known resource state', file=sys.stderr) |
| 182 | + cli_util.render_response(result, ctx) |
| 183 | + raise |
| 184 | + else: |
| 185 | + click.echo('Unable to wait for the resource to enter the specified state', file=sys.stderr) |
| 186 | + cli_util.render_response(result, ctx) |
| 187 | + |
| 188 | + |
| 189 | +@cli_util.copy_params_from_generated_command(kmsmanagement_cli.schedule_key_version_deletion, params_to_exclude=['']) |
| 190 | +@kmsmanagement_cli.key_version_group.command(name=cli_util.override('kms_management.schedule_key_version_deletion.command_name', 'schedule-key-version-deletion'), help=u"""Schedules the deletion of the specified key version. This sets the lifecycle state of the key version to `PENDING_DELETION` and then deletes it after the specified retention period ends. |
| 191 | +
|
| 192 | +As a provisioning operation, this call is subject to a Key Management limit that applies to the total number of requests across all provisioning write operations. Key Management might throttle this call to reject an otherwise valid request when the total rate of provisioning write operations exceeds 10 requests per second for a given tenancy. |
| 193 | +
|
| 194 | +The top level --endpoint parameter must be supplied for this operation. \n[Command Reference](scheduleKeyVersionDeletion)""") |
| 195 | +@click.pass_context |
| 196 | +@json_skeleton_utils.json_skeleton_generation_handler(input_params_to_complex_types={}, output_type={'module': 'key_management', 'class': 'KeyVersion'}) |
| 197 | +@cli_util.wrap_exceptions |
| 198 | +def schedule_key_version_deletion_extended(ctx, from_json, wait_for_state, max_wait_seconds, wait_interval_seconds, key_id, key_version_id, time_of_deletion, if_match): |
| 199 | + |
| 200 | + if isinstance(key_id, six.string_types) and len(key_id.strip()) == 0: |
| 201 | + raise click.UsageError('Parameter --key-id cannot be whitespace or empty string') |
| 202 | + |
| 203 | + if isinstance(key_version_id, six.string_types) and len(key_version_id.strip()) == 0: |
| 204 | + raise click.UsageError('Parameter --key-version-id cannot be whitespace or empty string') |
| 205 | + |
| 206 | + kwargs = {} |
| 207 | + if if_match is not None: |
| 208 | + kwargs['if_match'] = if_match |
| 209 | + kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(ctx.obj['request_id']) |
| 210 | + |
| 211 | + _details = {} |
| 212 | + |
| 213 | + if time_of_deletion is not None: |
| 214 | + _details['timeOfDeletion'] = time_of_deletion |
| 215 | + |
| 216 | + client = cli_util.build_client('key_management', 'kms_management', ctx) |
| 217 | + result = client.schedule_key_version_deletion( |
| 218 | + key_id=key_id, |
| 219 | + key_version_id=key_version_id, |
| 220 | + schedule_key_version_deletion_details=_details, |
| 221 | + **kwargs |
| 222 | + ) |
| 223 | + if wait_for_state: |
| 224 | + |
| 225 | + if hasattr(client, 'get_key_version') and callable(getattr(client, 'get_key_version')): |
| 226 | + try: |
| 227 | + wait_period_kwargs = {} |
| 228 | + if max_wait_seconds is not None: |
| 229 | + wait_period_kwargs['max_wait_seconds'] = max_wait_seconds |
| 230 | + if wait_interval_seconds is not None: |
| 231 | + wait_period_kwargs['max_interval_seconds'] = wait_interval_seconds |
| 232 | + |
| 233 | + click.echo('Action completed. Waiting until the resource has entered state: {}'.format(wait_for_state), file=sys.stderr) |
| 234 | + result = oci.wait_until(client, client.get_key_version(key_id, result.data.id), 'lifecycle_state', wait_for_state, **wait_period_kwargs) |
| 235 | + except oci.exceptions.MaximumWaitTimeExceeded as e: |
| 236 | + # If we fail, we should show an error, but we should still provide the information to the customer |
| 237 | + click.echo('Failed to wait until the resource entered the specified state. Outputting last known resource state', file=sys.stderr) |
| 238 | + cli_util.render_response(result, ctx) |
| 239 | + sys.exit(2) |
| 240 | + except Exception: |
| 241 | + click.echo('Encountered error while waiting for resource to enter the specified state. Outputting last known resource state', file=sys.stderr) |
| 242 | + cli_util.render_response(result, ctx) |
| 243 | + raise |
| 244 | + else: |
| 245 | + click.echo('Unable to wait for the resource to enter the specified state', file=sys.stderr) |
| 246 | + cli_util.render_response(result, ctx) |
| 247 | + |
| 248 | + |
| 249 | +@cli_util.copy_params_from_generated_command(kmsmanagement_cli.cancel_key_version_deletion, params_to_exclude=['']) |
| 250 | +@kmsmanagement_cli.key_version_group.command(name=cli_util.override('kms_management.cancel_key_version_deletion.command_name', 'cancel-key-version-deletion'), help=u"""Cancels the scheduled deletion of the specified key version. Canceling a scheduled deletion restores the key version to its lifecycle state from before its scheduled deletion. |
| 251 | +
|
| 252 | +As a provisioning operation, this call is subject to a Key Management limit that applies to the total number of requests across all provisioning write operations. Key Management might throttle this call to reject an otherwise valid request when the total rate of provisioning write operations exceeds 10 requests per second for a given tenancy. |
| 253 | +
|
| 254 | +The top level --endpoint parameter must be supplied for this operation. \n[Command Reference](cancelKeyVersionDeletion)""") |
| 255 | +@click.pass_context |
| 256 | +@json_skeleton_utils.json_skeleton_generation_handler(input_params_to_complex_types={}, output_type={'module': 'key_management', 'class': 'KeyVersion'}) |
| 257 | +@cli_util.wrap_exceptions |
| 258 | +def cancel_key_version_deletion_extended(ctx, from_json, wait_for_state, max_wait_seconds, wait_interval_seconds, key_id, key_version_id, if_match): |
| 259 | + |
| 260 | + if isinstance(key_id, six.string_types) and len(key_id.strip()) == 0: |
| 261 | + raise click.UsageError('Parameter --key-id cannot be whitespace or empty string') |
| 262 | + |
| 263 | + if isinstance(key_version_id, six.string_types) and len(key_version_id.strip()) == 0: |
| 264 | + raise click.UsageError('Parameter --key-version-id cannot be whitespace or empty string') |
| 265 | + |
| 266 | + kwargs = {} |
| 267 | + if if_match is not None: |
| 268 | + kwargs['if_match'] = if_match |
| 269 | + kwargs['opc_request_id'] = cli_util.use_or_generate_request_id(ctx.obj['request_id']) |
| 270 | + client = cli_util.build_client('key_management', 'kms_management', ctx) |
| 271 | + result = client.cancel_key_version_deletion( |
| 272 | + key_id=key_id, |
| 273 | + key_version_id=key_version_id, |
| 274 | + **kwargs |
| 275 | + ) |
| 276 | + if wait_for_state: |
| 277 | + |
| 278 | + if hasattr(client, 'get_key_version') and callable(getattr(client, 'get_key_version')): |
| 279 | + try: |
| 280 | + wait_period_kwargs = {} |
| 281 | + if max_wait_seconds is not None: |
| 282 | + wait_period_kwargs['max_wait_seconds'] = max_wait_seconds |
| 283 | + if wait_interval_seconds is not None: |
| 284 | + wait_period_kwargs['max_interval_seconds'] = wait_interval_seconds |
| 285 | + |
| 286 | + click.echo('Action completed. Waiting until the resource has entered state: {}'.format(wait_for_state), file=sys.stderr) |
| 287 | + result = oci.wait_until(client, client.get_key_version(key_id, result.data.id), 'lifecycle_state', wait_for_state, **wait_period_kwargs) |
| 288 | + except oci.exceptions.MaximumWaitTimeExceeded as e: |
| 289 | + # If we fail, we should show an error, but we should still provide the information to the customer |
| 290 | + click.echo('Failed to wait until the resource entered the specified state. Outputting last known resource state', file=sys.stderr) |
| 291 | + cli_util.render_response(result, ctx) |
| 292 | + sys.exit(2) |
| 293 | + except Exception: |
| 294 | + click.echo('Encountered error while waiting for resource to enter the specified state. Outputting last known resource state', file=sys.stderr) |
| 295 | + cli_util.render_response(result, ctx) |
| 296 | + raise |
| 297 | + else: |
| 298 | + click.echo('Unable to wait for the resource to enter the specified state', file=sys.stderr) |
0 commit comments