Esempio n. 1
0
 def _do_generate_from_source(self, config):
     # type: (Config) -> Dict[str, Any]
     app_py = os.path.join(config.project_dir, 'app.py')
     assert self._osutils.file_exists(app_py)
     app_source = self._osutils.get_file_contents(app_py, binary=False)
     app_policy = policy.policy_from_source_code(app_source)
     app_policy['Statement'].append(CLOUDWATCH_LOGS)
     return app_policy
Esempio n. 2
0
 def _get_policy_from_source_code(self, config):
     if config['autogen_policy']:
         app_py = os.path.join(config['project_dir'], 'app.py')
         assert os.path.isfile(app_py)
         with open(app_py) as f:
             app_policy = policy.policy_from_source_code(f.read())
             app_policy['Statement'].append(CLOUDWATCH_LOGS)
             return app_policy
     else:
         app_policy = self._load_last_policy(config)
         return app_policy
Esempio n. 3
0
 def _get_policy_from_source_code(self, config):
     if config['autogen_policy']:
         app_py = os.path.join(config['project_dir'], 'app.py')
         assert os.path.isfile(app_py)
         with open(app_py) as f:
             app_policy = policy.policy_from_source_code(f.read())
             app_policy['Statement'].append(CLOUDWATCH_LOGS)
             return app_policy
     else:
         app_policy = self._load_last_policy(config)
         return app_policy
Esempio n. 4
0
def gen_policy(ctx, filename):
    from chalice import policy
    if filename is None:
        filename = os.path.join(ctx.obj['project_dir'], 'app.py')
    if not os.path.isfile(filename):
        click.echo("App file does not exist: %s" % filename)
        raise click.Abort()
    with open(filename) as f:
        contents = f.read()
        generated = policy.policy_from_source_code(contents)
        click.echo(json.dumps(generated, indent=2))
Esempio n. 5
0
def gen_policy(ctx, filename):
    # type: (click.Context, str) -> None
    if filename is None:
        filename = os.path.join(ctx.obj['project_dir'], 'app.py')
    if not os.path.isfile(filename):
        click.echo("App file does not exist: %s" % filename, err=True)
        raise click.Abort()
    with open(filename) as f:
        contents = f.read()
        generated = policy.policy_from_source_code(contents)
        click.echo(serialize_to_json(generated))
Esempio n. 6
0
def gen_policy(ctx, filename):
    # type: (click.Context, str) -> None
    from chalice import policy
    if filename is None:
        filename = os.path.join(ctx.obj['project_dir'], 'app.py')
    if not os.path.isfile(filename):
        click.echo("App file does not exist: %s" % filename, err=True)
        raise click.Abort()
    with open(filename) as f:
        contents = f.read()
        generated = policy.policy_from_source_code(contents)
        click.echo(serialize_to_json(generated))
Esempio n. 7
0
def gen_policy(ctx, filename):
    from chalice import policy
    if filename is None:
        project_dir = os.getcwd()
        filename = os.path.join(project_dir, 'app.py')
    if not os.path.isfile(filename):
        click.echo("App file does not exist: %s" % filename)
        raise click.Abort()
    with open(filename) as f:
        contents = f.read()
        generated = policy.policy_from_source_code(contents)
        click.echo(json.dumps(generated, indent=2))
Esempio n. 8
0
 def _get_policy_from_source_code(self, config):
     # type: (Config) -> Dict[str, Any]
     if config.autogen_policy:
         app_py = os.path.join(config.project_dir, 'app.py')
         assert os.path.isfile(app_py)
         with open(app_py) as f:
             app_policy = policy.policy_from_source_code(f.read())
             app_policy['Statement'].append(CLOUDWATCH_LOGS)
             return app_policy
     else:
         app_policy = self._load_last_policy(config)
         return app_policy
Esempio n. 9
0
 def _get_policy_from_source_code(self, config):
     # type: (Config) -> Dict[str, Any]
     if config.autogen_policy:
         app_py = os.path.join(config.project_dir, 'app.py')
         assert os.path.isfile(app_py)
         with open(app_py) as f:
             app_policy = policy.policy_from_source_code(f.read())
             app_policy['Statement'].append(CLOUDWATCH_LOGS)
             return app_policy
     else:
         app_policy = self._load_last_policy(config)
         return app_policy