Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/awscli/customizations/rds.py
1566 views
1
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
"""
14
This customization splits the modify-option-group into two separate commands:
15
16
* ``add-option-group``
17
* ``remove-option-group``
18
19
In both commands the ``--options-to-remove`` and ``--options-to-add`` args will
20
be renamed to just ``--options``.
21
22
All the remaining args will be available in both commands (which proxy
23
modify-option-group).
24
25
"""
26
27
from awscli.clidriver import ServiceOperation
28
from awscli.clidriver import CLIOperationCaller
29
from awscli.customizations import utils
30
from awscli.customizations.commands import BasicCommand
31
from awscli.customizations.utils import uni_print
32
from awscli.utils import create_nested_client
33
34
35
def register_rds_modify_split(cli):
36
cli.register('building-command-table.rds', _building_command_table)
37
cli.register('building-argument-table.rds.add-option-to-option-group',
38
_rename_add_option)
39
cli.register('building-argument-table.rds.remove-option-from-option-group',
40
_rename_remove_option)
41
42
43
def register_add_generate_db_auth_token(cli):
44
cli.register('building-command-table.rds', _add_generate_db_auth_token)
45
46
47
def _add_generate_db_auth_token(command_table, session, **kwargs):
48
command = GenerateDBAuthTokenCommand(session)
49
command_table['generate-db-auth-token'] = command
50
51
52
def _rename_add_option(argument_table, **kwargs):
53
utils.rename_argument(argument_table, 'options-to-include',
54
new_name='options')
55
del argument_table['options-to-remove']
56
57
58
def _rename_remove_option(argument_table, **kwargs):
59
utils.rename_argument(argument_table, 'options-to-remove',
60
new_name='options')
61
del argument_table['options-to-include']
62
63
64
def _building_command_table(command_table, session, **kwargs):
65
# Hooked up to building-command-table.rds
66
# We don't need the modify-option-group operation.
67
del command_table['modify-option-group']
68
# We're going to replace modify-option-group with two commands:
69
# add-option-group and remove-option-group
70
rds_model = session.get_service_model('rds')
71
modify_operation_model = rds_model.operation_model('ModifyOptionGroup')
72
command_table['add-option-to-option-group'] = ServiceOperation(
73
parent_name='rds', name='add-option-to-option-group',
74
operation_caller=CLIOperationCaller(session),
75
session=session,
76
operation_model=modify_operation_model)
77
command_table['remove-option-from-option-group'] = ServiceOperation(
78
parent_name='rds', name='remove-option-from-option-group',
79
session=session,
80
operation_model=modify_operation_model,
81
operation_caller=CLIOperationCaller(session))
82
83
84
class GenerateDBAuthTokenCommand(BasicCommand):
85
NAME = 'generate-db-auth-token'
86
DESCRIPTION = (
87
'Generates an auth token used to connect to a db with IAM credentials.'
88
)
89
ARG_TABLE = [
90
{'name': 'hostname', 'required': True,
91
'help_text': 'The hostname of the database to connect to.'},
92
{'name': 'port', 'cli_type_name': 'integer', 'required': True,
93
'help_text': 'The port number the database is listening on.'},
94
{'name': 'username', 'required': True,
95
'help_text': 'The username to log in as.'}
96
]
97
98
def _run_main(self, parsed_args, parsed_globals):
99
rds = create_nested_client(
100
self._session,
101
'rds',
102
region_name=parsed_globals.region,
103
endpoint_url=parsed_globals.endpoint_url,
104
verify=parsed_globals.verify_ssl
105
)
106
token = rds.generate_db_auth_token(
107
DBHostname=parsed_args.hostname,
108
Port=parsed_args.port,
109
DBUsername=parsed_args.username
110
)
111
uni_print(token)
112
uni_print('\n')
113
return 0
114
115