コード例 #1
0
def _check_for_uri_param(param, value):
    if isinstance(value, list) and len(value) == 1:
        value = value[0]
    try:
        return get_paramfile(value)
    except ResourceLoadingError as e:
        raise ParamError(param.cli_name, six.text_type(e))
コード例 #2
0
 def test_text_file(self):
     contents = 'This is a test'
     filename = self.files.create_file('foo', contents)
     prefixed_filename = 'file://' + filename
     data = get_paramfile(prefixed_filename)
     self.assertEqual(data, contents)
     self.assertIsInstance(data, six.string_types)
コード例 #3
0
ファイル: test_paramfile.py プロジェクト: RadicalLove/aws-cli
 def test_binary_file(self):
     contents = "This is a test"
     filename = self.files.create_file("foo", contents)
     prefixed_filename = "fileb://" + filename
     data = get_paramfile(prefixed_filename)
     self.assertEqual(data, b"This is a test")
     self.assertIsInstance(data, six.binary_type)
コード例 #4
0
ファイル: argprocess.py プロジェクト: kotnik/aws-cli
def _check_for_uri_param(param, value):
    if isinstance(value, list) and len(value) == 1:
        value = value[0]
    try:
        return get_paramfile(value)
    except ResourceLoadingError as e:
        raise ParamError(param, str(e))
コード例 #5
0
ファイル: test_paramfile.py プロジェクト: RadicalLove/aws-cli
 def test_text_file(self):
     contents = "This is a test"
     filename = self.files.create_file("foo", contents)
     prefixed_filename = "file://" + filename
     data = get_paramfile(prefixed_filename)
     self.assertEqual(data, contents)
     self.assertIsInstance(data, six.string_types)
コード例 #6
0
 def test_binary_file(self):
     contents = 'This is a test'
     filename = self.files.create_file('foo', contents)
     prefixed_filename = 'fileb://' + filename
     data = get_paramfile(prefixed_filename)
     self.assertEqual(data, b'This is a test')
     self.assertIsInstance(data, six.binary_type)
コード例 #7
0
ファイル: clidriver.py プロジェクト: Web5design/aws-cli
 def _handle_param_file(self, value):
     session = self.operation_object.service.session
     if isinstance(value, list) and len(value) == 1:
         temp = value[0]
     else:
         temp = value
     temp = get_paramfile(session, temp)
     if temp:
         value = temp
     return value
コード例 #8
0
ファイル: arguments.py プロジェクト: nvdnkpr/aws-cli-python
 def _handle_param_file(self, value):
     session = self.operation_object.service.session
     # If the arg is suppose to be a list type, just
     # get the first element in the list, as it may
     # refer to a file:// (or http/https) type.
     potential_param_value = value
     if isinstance(value, list) and len(value) == 1:
         potential_param_value = value[0]
     try:
         actual_value = get_paramfile(session, potential_param_value)
     except ResourceLoadingError as e:
         raise BadArgumentError("Bad value for argument '%s': %s" % (self.cli_name, e))
     if actual_value is not None:
         value = actual_value
     return value
コード例 #9
0
ファイル: clidriver.py プロジェクト: tuksik/aws-cli
 def _handle_param_file(self, value):
     session = self.operation_object.service.session
     # If the arg is suppose to be a list type, just
     # get the first element in the list, as it may
     # refer to a file:// (or http/https) type.
     potential_param_value = value
     if isinstance(value, list) and len(value) == 1:
         potential_param_value = value[0]
     try:
         actual_value = get_paramfile(session, potential_param_value)
     except ResourceLoadingError as e:
         raise BadArgumentError("Bad value for argument '%s': %s" %
                                (self.cli_name, e))
     if actual_value is not None:
         value = actual_value
     return value
コード例 #10
0
    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\nJSON received: %s" % (e, retrieved_json))
            # Add the members from the input JSON to the call parameters.
            self._update_call_parameters(call_parameters, input_data)
コード例 #11
0
    def _get_arg_value(self, parsed_args):
        arg_value = getattr(parsed_args, self.py_name, None)
        if arg_value is None:
            return

        cli_input_args = [
            k for k, v in vars(parsed_args).items()
            if v is not None and k.startswith('cli_input')
        ]
        if len(cli_input_args) != 1:
            raise ParamSyntaxError(
                'Only one --cli-input- parameter may be specified.')

        # If the value starts with file:// or fileb://, return the contents
        # from the file.
        paramfile_data = get_paramfile(arg_value, LOCAL_PREFIX_MAP)
        if paramfile_data is not None:
            return paramfile_data

        return arg_value
コード例 #12
0
    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, LOCAL_PREFIX_MAP)
            # 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\nJSON received: %s" %
                    (e, retrieved_json))
            # Add the members from the input JSON to the call parameters.
            self._update_call_parameters(call_parameters, input_data)
コード例 #13
0
ファイル: test_paramfile.py プロジェクト: RadicalLove/aws-cli
 def test_non_string_type_returns_none(self):
     self.assertIsNone(get_paramfile(100))
コード例 #14
0
 def get_paramfile(self, path):
     return get_paramfile(path, REMOTE_PREFIX_MAP.copy())
コード例 #15
0
 def get_paramfile(self, path):
     return get_paramfile(path, LOCAL_PREFIX_MAP.copy())
コード例 #16
0
 def test_no_match_uris_returns_none(self):
     self.assertIsNone(get_paramfile('foobar://somewhere.bar'))
コード例 #17
0
 def test_non_string_type_returns_none(self):
     self.assertIsNone(get_paramfile(100))
コード例 #18
0
ファイル: test_paramfile.py プロジェクト: HelderSi/aws-cli
 def test_resource_from_http(self):
     self.response.text = 'http contents'
     loaded = get_paramfile('http://foo.bar.baz')
     self.assertEqual(loaded, 'http contents')
     self.requests_mock.get.assert_called_with('http://foo.bar.baz')
コード例 #19
0
ファイル: test_paramfile.py プロジェクト: RadicalLove/aws-cli
 def test_connection_error_raises_error(self):
     self.requests_mock.get.side_effect = Exception("Connection error.")
     with self.assertRaisesRegexp(ResourceLoadingError, "foo\.bar\.baz"):
         get_paramfile("https://foo.bar.baz")
コード例 #20
0
 def test_resource_from_https(self):
     self.response.text = 'http contents'
     loaded = get_paramfile('https://foo.bar.baz')
     self.assertEqual(loaded, 'http contents')
     self.requests_mock.get.assert_called_with('https://foo.bar.baz')
コード例 #21
0
ファイル: test_paramfile.py プロジェクト: RadicalLove/aws-cli
 def test_resource_from_https(self):
     self.response.text = "http contents"
     loaded = get_paramfile("https://foo.bar.baz")
     self.assertEqual(loaded, "http contents")
     self.requests_mock.get.assert_called_with("https://foo.bar.baz")
コード例 #22
0
ファイル: test_paramfile.py プロジェクト: RadicalLove/aws-cli
 def test_non_200_raises_error(self):
     self.response.status_code = 500
     with self.assertRaisesRegexp(ResourceLoadingError, "foo\.bar\.baz"):
         get_paramfile("https://foo.bar.baz")
コード例 #23
0
 def test_file_does_not_exist_raises_error(self):
     with self.assertRaises(ResourceLoadingError):
         get_paramfile('file://file/does/not/existsasdf.txt')
コード例 #24
0
 def test_non_200_raises_error(self):
     self.response.status_code = 500
     with self.assertRaisesRegexp(ResourceLoadingError, 'foo\.bar\.baz'):
         get_paramfile('https://foo.bar.baz')
コード例 #25
0
ファイル: test_paramfile.py プロジェクト: RadicalLove/aws-cli
 def test_file_does_not_exist_raises_error(self):
     with self.assertRaises(ResourceLoadingError):
         get_paramfile("file://file/does/not/existsasdf.txt")
コード例 #26
0
ファイル: test_paramfile.py プロジェクト: RadicalLove/aws-cli
 def test_cannot_load_text_file(self):
     contents = b"\xbfX\xac\xbe"
     filename = self.files.create_file("foo", contents, mode="wb")
     prefixed_filename = "file://" + filename
     with self.assertRaises(ResourceLoadingError):
         get_paramfile(prefixed_filename)
コード例 #27
0
 def test_connection_error_raises_error(self):
     self.requests_mock.get.side_effect = Exception("Connection error.")
     with self.assertRaisesRegexp(ResourceLoadingError, 'foo\.bar\.baz'):
         get_paramfile('https://foo.bar.baz')
コード例 #28
0
ファイル: test_paramfile.py プロジェクト: RadicalLove/aws-cli
 def test_no_match_uris_returns_none(self):
     self.assertIsNone(get_paramfile("foobar://somewhere.bar"))
コード例 #29
0
 def test_cannot_load_text_file(self):
     contents = b'\xbfX\xac\xbe'
     filename = self.files.create_file('foo', contents, mode='wb')
     prefixed_filename = 'file://' + filename
     with self.assertRaises(ResourceLoadingError):
         get_paramfile(prefixed_filename)