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 / 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 = []
    session.register_component('data_loader', _LOADER)
    return driver
github aws / aws-cli / tests / unit / View on Github external
def test_aws_configure_in_error_message_no_credentials(self):
        driver = create_clidriver()
        def raise_exception(*args, **kwargs):
            raise NoCredentialsError()
            lambda command_table, **kwargs: \
                command_table.__setitem__('ec2', raise_exception))
        with mock.patch('sys.stderr') as f:
            driver.main('ec2 describe-instances'.split())
            'Unable to locate credentials. '
            'You can configure credentials by running "aws configure".')
github aws / aws-cli / tests / unit / 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()
            'building-top-level-params', self.inject_new_param)
            lambda parsed_args, **kwargs: args_seen.append(parsed_args))
github aws / aws-cli / tests / functional / View on Github external
def test_none(self):
        self.environ['AWS_CONFIG_FILE'] = self.files.create_file(
            '[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 / View on Github external
def test_no_errors_when_missing_completion_data(self):
        index_generator = generator.IndexGenerator(
        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.
        # 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')
github awslabs / aws-shell / tests / integration / 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 / 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))[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:
  ["aws", "configure"])
github venth / aws-adfs / aws_adfs / View on Github external
def decorate():
    old_stderr = sys.stderr
    redirected_error = sys.stderr = StringIO()
        driver = clidriver.create_clidriver()
        return_code = driver.main()
        sys.stderr = old_stderr

    error_text = redirected_error.getvalue()

    if _was_token_expired(return_code, error_text):
    elif error_text is not None:
github awslabs / aws-shell / awsshell / 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)):
    with open(output_filename, 'w') as f: