FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
aws-cli/awscli/customizations/cliinputjson.py at develop · firstval/aws-cli · GitHub
firstval
/
aws-cli
Public
forked from
aws/aws-cli
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
aws-cli
/
awscli
/
customizations
/
cliinputjson.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
83 lines (70 loc) · 3.59 KB
Breadcrumbs
aws-cli
/
awscli
/
customizations
/
cliinputjson.py
Copy path
File metadata and controls
83 lines (70 loc) · 3.59 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import
json
from
awscli
.
paramfile
import
get_paramfile
from
awscli
.
argprocess
import
ParamError
from
awscli
.
customizations
.
arguments
import
OverrideRequiredArgsArgument
def
register_cli_input_json
(
cli
):
cli
.
register
(
'building-argument-table'
,
add_cli_input_json
)
def
add_cli_input_json
(
session
,
argument_table
,
**
kwargs
):
# This argument cannot support operations with streaming output which
# is designated by the argument name `outfile`.
if
'outfile'
not
in
argument_table
:
cli_input_json_argument
=
CliInputJSONArgument
(
session
)
cli_input_json_argument
.
add_to_arg_table
(
argument_table
)
class
CliInputJSONArgument
(
OverrideRequiredArgsArgument
):
"""This argument inputs a JSON string as the entire input for a command.
Ideally, the value to this argument should be a filled out JSON file
generated by ``--generate-cli-skeleton``. The items in the JSON string
will not clobber other arguments entered into the command line.
"""
ARG_DATA
=
{
'name'
:
'cli-input-json'
,
'help_text'
:
'Performs service operation based on the JSON string '
'provided. The JSON string follows the format provided '
'by ``--generate-cli-skeleton``. If other arguments are '
'provided on the command line, the CLI values will override '
'the JSON-provided values.'
}
def
__init__
(
self
,
session
):
super
(
CliInputJSONArgument
,
self
).
__init__
(
session
)
def
_register_argument_action
(
self
):
self
.
_session
.
register
(
'calling-command.*'
,
self
.
add_to_call_parameters
)
super
(
CliInputJSONArgument
,
self
).
_register_argument_action
()
def
add_to_call_parameters
(
self
,
call_parameters
,
parsed_args
,
parsed_globals
,
**
kwargs
):
# Check if ``--cli-input-json`` was specified in the command line.
input_json
=
getattr
(
parsed_args
,
'cli_input_json'
,
None
)
if
input_json
is
not
None
:
# Retrieve the JSON from the file if needed.
retrieved_json
=
get_paramfile
(
input_json
)
# Nothing was retrieved from the file. So assume the argument
# is already a JSON string.
if
retrieved_json
is
None
:
retrieved_json
=
input_json
try
:
# Try to load the JSON string into a python dictionary
input_data
=
json
.
loads
(
retrieved_json
)
except
ValueError
as
e
:
raise
ParamError
(
self
.
name
,
"Invalid JSON: %s
\n
JSON received: %s"
%
(
e
,
retrieved_json
))
# Add the members from the input JSON to the call parameters.
self
.
_update_call_parameters
(
call_parameters
,
input_data
)
def
_update_call_parameters
(
self
,
call_parameters
,
input_data
):
for
input_key
in
input_data
.
keys
():
# Only add the values to ``call_parameters`` if not already
# present.
if
input_key
not
in
call_parameters
:
call_parameters
[
input_key
]
=
input_data
[
input_key
]
Back
|
FazBrowse Home
|
New Git URL