Exemplo n.º 1
0
 def test_can_get_auth_from_config(self, mock_get_config, mock_connect):
     mock_get_config.return_value = {
         'Metrics': [],
         'Auth': {
             'aws_access_key_id': 'foo',
             'aws_secret_access_key': 'bar',
         }
     }
     leadbutt.leadbutt('dummy_config_file', 'dummy_cli_options')
     self.assertTrue(mock_connect.called)
     args, kwargs = mock_connect.call_args
     self.assertEqual(kwargs['aws_access_key_id'], 'foo')
     self.assertEqual(kwargs['aws_secret_access_key'], 'bar')
Exemplo n.º 2
0
def main():
    template_file, namespace, region, filters, cli_tokens = interpret_options()

    # get the template first so this can fail before making a network request
    jinja_template = get_jinja_template(template_file)

    # this is the ugly hack part: we'll require the caller to pass in a specific CLI 'option'
    # to achieve the desired effect of getting the specified beanstalk environment resources
    # TODO: refactor plumbum into a class style, so an argument for the environment name can replace this
    if 'environment_name' not in filters:
        raise CliArgsException(
            'in {}, you must pass at least one environment_name=something filter'.format(
                os.path.basename(__file__)
            )
        )

    # check the namespace, this script only works for 'beanstall'
    if namespace != 'beanstalk':
        raise CliArgsException(
            "The only valid namespace for {} is 'beanstalk'".format(os.path.basename(__file__))
        )

    resources = list_beanstalk(region, filters)

    base_tokens = {
        'filters': filters,
        'region': region,  # Use for Auth config section if needed
        'resources': resources,
        'environment_name': filters['environment_name'],
    }

    tempfile = NamedTemporaryFile()
    tempfile.write(jinja_template.render(get_template_tokens(base_tokens=base_tokens, cli_tokens=cli_tokens)))
    tempfile.flush()
    # TODO: not hardcoding the Perdiod and Count requies a refactor of leabutt.py into a class with a config object.
    leadbutt(tempfile.name, {'Period': 1, 'Count': 5}, verbose=False)
    tempfile.close()