How to use the awscli.clidriver.create_clidriver function in awscli

To help you get started, we’ve selected a few awscli examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gkrizek / bash-lambda-layer / bin / awscli / testutils.py View on Github external
def create_clidriver():
    driver = awscli.clidriver.create_clidriver()
    session = driver.session
    data_path = session.get_config_variable('data_path').split(os.pathsep)
    if not data_path:
        data_path = []
    _LOADER.search_paths.extend(data_path)
    session.register_component('data_loader', _LOADER)
    return driver
github aws / aws-cli / tests / unit / test_clidriver.py View on Github external
def test_aws_configure_in_error_message_no_credentials(self):
        driver = create_clidriver()
        def raise_exception(*args, **kwargs):
            raise NoCredentialsError()
        driver.session.register(
            'building-command-table',
            lambda command_table, **kwargs: \
                command_table.__setitem__('ec2', raise_exception))
        with mock.patch('sys.stderr') as f:
            driver.main('ec2 describe-instances'.split())
        self.assertEqual(
            f.write.call_args_list[0][0][0],
            'Unable to locate credentials. '
            'You can configure credentials by running "aws configure".')
github aws / aws-cli / tests / unit / test_clidriver.py View on Github external
def test_event_emission_for_top_level_params(self):
        driver = create_clidriver()
        # --unknown-foo is an known arg, so we expect a 255 rc.
        rc = driver.main('ec2 describe-instances --unknown-arg foo'.split())
        self.assertEqual(rc, 255)
        self.assertIn('Unknown options: --unknown-arg', self.stderr.getvalue())

        # The argument table is memoized in the CLIDriver object. So
        # when we call main() above, it will get created and cached
        # and the argument table won't get created again (and therefore
        # the building-top-level-params event will not get generated again).
        # So, for this test we need to create a new driver object.
        driver = create_clidriver()
        driver.session.register(
            'building-top-level-params', self.inject_new_param)
        driver.session.register(
            'top-level-args-parsed',
            lambda parsed_args, **kwargs: args_seen.append(parsed_args))
github aws / aws-cli / tests / functional / test_timeformat.py View on Github external
def test_none(self):
        self.environ['AWS_CONFIG_FILE'] = self.files.create_file(
            'none',
            '[default]\ncli_timestamp_format = none\n')
        self.driver = create_clidriver()
        expected_time = 0

        stdout, _, _ = self.run_cmd(self.command)
        json_response = json.loads(stdout)
        start_time = json_response["builds"][0]["startTime"]
        self.assertEqual(expected_time, start_time)
github aws / aws-cli / tests / functional / autocomplete / test_server_index.py View on Github external
def test_no_errors_when_missing_completion_data(self):
        index_generator = generator.IndexGenerator(
            [ModelIndexer(self.db_connection),
             APICallIndexer(self.db_connection)],
        )
        driver = clidriver.create_clidriver()
        # We're going to remove the CLI data path from the loader.
        # This will result in the loader not being able to find any
        # completion data, which allows us to verify the behavior when
        # there's no completion data.
        driver.session.register('building-command-table.main',
                                _ddb_only_command_table)
        driver.session.register('building-command-table.dynamodb',
                                self._disable_cli_loaders)
        index_generator.generate_index(driver)
        # We shouldn't get any data now because we couldn't load
        # completion data.
        lookup = model.DBCompletionLookup(self.db_connection)
        result = lookup.get_server_completion_data(
            ['aws', 'dynamodb'], 'delete-table', 'table-name')
        self.assertIsNone(result)
github awslabs / aws-shell / tests / integration / test_makeindex.py View on Github external
def cloudformation_command():
    driver = awscli.clidriver.create_clidriver()
    cmd = driver.create_help_command()
    cfn = cmd.command_table['cloudformation']
    return cfn
github edraizen / molmimic / molmimic / util / iostore.py View on Github external
#         os.environ["AWS_SECRET_ACCESS_KEY"] = instanceMetadata["SecretAccessKey"]
#         os.environ["AWS_SESSION_TOKEN"] = instanceMetadata["Token"]
#
#         if not os.path.isfile("~/.aws/credentials"):
#             if not os.path.isdir("~/.aws"):
#                 os.makedirs("~/.aws")
#             with open("~/.aws/credentials", "w") as f:
#                 print("""[default]
# aws_access_key_id = {AccessKeyId}
# aws_secret_access_key = {SecretAccessKey}
# """.format(**instanceMetadata))

        subprocess.call([sys.executable, "-m", "pip", "install", "awscli", "--upgrade", "--user"])

        import awscli.clidriver
        driver = awscli.clidriver.create_clidriver()

        cmd = ["s3", "sync", "s3://{}/{}".format(self.bucket_name, prefix), local_dir]
        if postfix is not None:
            cmd += ["--exclude=\"*\"", "--include=\"*{}\"".format(postfix)]


        rc = driver.main(args=cmd)

        # del os.environ["AWS_ACCESS_KEY_ID"]
        # del os.environ["AWS_SECRET_ACCESS_KEY"]
        # del os.environ["AWS_SESSION_TOKEN"]
        del awscli.clidriver

        if rc != 0:
            subprocess.call(["aws", "configure"])
github venth / aws-adfs / aws_adfs / aws_refreshable.py View on Github external
def decorate():
    old_stderr = sys.stderr
    redirected_error = sys.stderr = StringIO()
    try:
        driver = clidriver.create_clidriver()
        return_code = driver.main()
    finally:
        sys.stderr = old_stderr

    error_text = redirected_error.getvalue()

    if _was_token_expired(return_code, error_text):
        _re_authenticate(driver)
        clidriver.main()
    elif error_text is not None:
        old_stderr.write(error_text)
github awslabs / aws-shell / awsshell / makeindex.py View on Github external
def write_index(output_filename=None):
    driver = awscli.clidriver.create_clidriver()
    help_command = driver.create_help_command()
    index = {'aws': new_index()}
    current = index['aws']
    index_command(current, help_command)

    result = json.dumps(index)
    if not os.path.isdir(os.path.dirname(output_filename)):
        os.makedirs(os.path.dirname(output_filename))
    with open(output_filename, 'w') as f:
        f.write(result)