コード例 #1
0
 def __init__(self,
              profile_name,
              region_name,
              lambda_fn,
              config_file,
              debug=False):
     self.lambda_fn = lambda_fn
     self.lambda_client = None
     if lambda_fn:
         self.lambda_client = LambdaClient(profile_name=profile_name,
                                           region_name=region_name,
                                           func_name=lambda_fn,
                                           debug=debug)
     if config_file:
         config = json.load(config_file)
         self.crud = CRUD(**config)
     self.debug = debug
コード例 #2
0
ファイル: cli.py プロジェクト: cloudnative/cruddy
 def __init__(self, profile_name, region_name,
              lambda_fn, config_file, debug=False):
     self.lambda_fn = lambda_fn
     self.lambda_client = None
     if lambda_fn:
         self.lambda_client = LambdaClient(
             profile_name=profile_name, region_name=region_name,
             func_name=lambda_fn, debug=debug)
     if config_file:
         config = json.load(config_file)
         self.crud = CRUD(**config)
     self.debug = debug
コード例 #3
0
class CLIHandler(object):
    def __init__(self,
                 profile_name,
                 region_name,
                 lambda_fn,
                 config_file,
                 debug=False):
        self.lambda_fn = lambda_fn
        self.lambda_client = None
        if lambda_fn:
            self.lambda_client = LambdaClient(profile_name=profile_name,
                                              region_name=region_name,
                                              func_name=lambda_fn,
                                              debug=debug)
        if config_file:
            config = json.load(config_file)
            self.crud = CRUD(**config)
        self.debug = debug

    def _handle_response(self, response):
        if response.status == 'success':
            click.echo(json.dumps(response.data, indent=4))
        else:
            click.echo(click.style(response.status, fg='red'))
            click.echo(click.style(response.error_type, fg='red'))
            click.echo(click.style(response.error_message, fg='red'))

    def _invoke_lambda(self, payload, raw):
        response = self.lambda_client.invoke(payload)
        if raw:
            return response
        self._handle_response(response)

    def _invoke_cruddy(self, payload, raw):
        response = self.crud.handler(**payload)
        if raw:
            return response
        self._handle_response(response)

    def invoke(self, payload, raw=False):
        if self.lambda_fn:
            return self._invoke_lambda(payload, raw)
        elif self.crud:
            return self._invoke_cruddy(payload, raw)
        else:
            msg = 'You must specify either --lambda-fn or --config'
            click.echo(click.style(msg, fg='red'))
コード例 #4
0
ファイル: cli.py プロジェクト: cloudnative/cruddy
class CLIHandler(object):

    def __init__(self, profile_name, region_name,
                 lambda_fn, config_file, debug=False):
        self.lambda_fn = lambda_fn
        self.lambda_client = None
        if lambda_fn:
            self.lambda_client = LambdaClient(
                profile_name=profile_name, region_name=region_name,
                func_name=lambda_fn, debug=debug)
        if config_file:
            config = json.load(config_file)
            self.crud = CRUD(**config)
        self.debug = debug

    def _handle_response(self, response):
        if response.status == 'success':
            click.echo(json.dumps(response.data, indent=4))
        else:
            click.echo(click.style(response.status, fg='red'))
            click.echo(click.style(response.error_type, fg='red'))
            click.echo(click.style(response.error_message, fg='red'))

    def _invoke_lambda(self, payload, raw):
        response = self.lambda_client.invoke(payload)
        if raw:
            return response
        self._handle_response(response)

    def _invoke_cruddy(self, payload, raw):
        response = self.crud.handler(**payload)
        if raw:
            return response
        self._handle_response(response)

    def invoke(self, payload, raw=False):
        if self.lambda_fn:
            return self._invoke_lambda(payload, raw)
        elif self.crud:
            return self._invoke_cruddy(payload, raw)
        else:
            msg = 'You must specify either --lambda-fn or --config'
            click.echo(click.style(msg, fg='red'))