def validate_params(self):
        UserUtil.verified_phone_and_email(self.event)

        # カストディ規制時のウォレット移行が済んでいなければ利用不可
        user_id = self.event['requestContext']['authorizer']['claims'][
            'cognito:username']
        UserUtil.validate_private_eth_address(self.dynamodb, user_id)
Ejemplo n.º 2
0
    def validate_params(self):
        # 認証・ウォレット情報が登録済であること
        UserUtil.verified_phone_and_email(self.event)
        UserUtil.validate_private_eth_address(
            self.dynamodb, self.event['requestContext']['authorizer']['claims']
            ['cognito:username'])
        # single
        validate(self.params, self.get_schema())
        # 署名が正しいこと
        if self.params.get('init_approve_signed_transaction') is not None:
            PrivateChainUtil.validate_raw_transaction_signature(
                self.params['init_approve_signed_transaction'],
                self.event['requestContext']['authorizer']['claims']
                ['custom:private_eth_address'])
        PrivateChainUtil.validate_raw_transaction_signature(
            self.params['approve_signed_transaction'],
            self.event['requestContext']['authorizer']['claims']
            ['custom:private_eth_address'])
        PrivateChainUtil.validate_raw_transaction_signature(
            self.params['relay_signed_transaction'],
            self.event['requestContext']['authorizer']['claims']
            ['custom:private_eth_address'])

        # pinコードを検証
        self.__validate_pin_code(self.params['access_token'],
                                 self.params['pin_code'])
    def validate_params(self):
        # 認証・ウォレット情報が登録済であること
        UserUtil.verified_phone_and_email(self.event)
        UserUtil.validate_private_eth_address(
            self.dynamodb, self.event['requestContext']['authorizer']['claims']
            ['cognito:username'])

        # single
        validate(self.params, self.get_schema())
        # 署名が正しいこと
        PrivateChainUtil.validate_raw_transaction_signature(
            self.params['purchase_signed_transaction'],
            self.event['requestContext']['authorizer']['claims']
            ['custom:private_eth_address'])
        PrivateChainUtil.validate_raw_transaction_signature(
            self.params['burn_signed_transaction'],
            self.event['requestContext']['authorizer']['claims']
            ['custom:private_eth_address'])

        # relation
        DBUtil.validate_article_existence(self.dynamodb,
                                          self.params['article_id'],
                                          status='public',
                                          is_purchased=True)
        DBUtil.validate_not_purchased(
            self.dynamodb, self.params['article_id'],
            self.event['requestContext']['authorizer']['claims']
            ['cognito:username'])
Ejemplo n.º 4
0
    def validate_params(self):
        UserUtil.verified_phone_and_email(self.event)

        # check price type is integer or decimal
        ParameterUtil.validate_price_params(self.params.get('price'))
        if self.params.get('price') is not None:
            self.params['price'] = int(self.params['price'])

        validate(self.params, self.get_schema())

        if self.params.get('eye_catch_url'):
            TextSanitizer.validate_img_url(self.params.get('eye_catch_url'))

        if self.params.get('tags'):
            ParameterUtil.validate_array_unique(self.params['tags'],
                                                'tags',
                                                case_insensitive=True)
            TagUtil.validate_format(self.params['tags'])

        DBUtil.validate_article_existence(
            self.dynamodb,
            self.params['article_id'],
            user_id=self.event['requestContext']['authorizer']['claims']
            ['cognito:username'],
            status='public',
            version=2)

        DBUtil.validate_topic(self.dynamodb, self.params['topic'])

        DBUtil.validate_exists_title_and_body(self.dynamodb,
                                              self.params['article_id'])
    def validate_params(self):
        UserUtil.verified_phone_and_email(self.event)
        # single
        # check price type is integer or decimal
        try:
            self.params['price'] = int(self.params['price'])
        except ValueError:
            raise ValidationError('Price must be integer')

        # check price value is not decimal
        price = self.params['price'] / 10**18
        if price.is_integer() is False:
            raise ValidationError('Decimal value is not allowed')
        validate(self.params, self.get_schema())

        # relation
        DBUtil.validate_article_existence(self.dynamodb,
                                          self.params['article_id'],
                                          status='public')
        DBUtil.validate_latest_price(self.dynamodb, self.params['article_id'],
                                     self.params['price'])
        DBUtil.validate_not_purchased(
            self.dynamodb, self.params['article_id'],
            self.event['requestContext']['authorizer']['claims']
            ['cognito:username'])
 def validate_params(self):
     UserUtil.verified_phone_and_email(self.event)
     validate(self.params, self.get_schema())
     comment = DBUtil.get_validated_comment(self.dynamodb,
                                            self.params['comment_id'])
     DBUtil.validate_article_existence(self.dynamodb,
                                       comment['article_id'],
                                       status='public')
Ejemplo n.º 7
0
    def validate_params(self):
        UserUtil.verified_phone_and_email(self.event)
        if self.event.get('body') is None:
            raise ValidationError('Request parameter is required')

        params = json.loads(self.event.get('body'))

        validate(params, self.get_schema(), format_checker=FormatChecker())
    def validate_params(self):
        UserUtil.verified_phone_and_email(self.event)
        if not self.event.get('body'):
            raise ValidationError('Request parameter is required')

        validate(self.params, self.get_schema())
        DBUtil.validate_article_existence(self.dynamodb,
                                          self.params['article_id'],
                                          status='public')
Ejemplo n.º 9
0
    def main(self):
        logger = logging.getLogger()
        logger.setLevel(logging.INFO)

        try:
            # user validation
            UserUtil.verified_phone_and_email(self.event)

            # params validation
            self.validate_params()

            # exec main process
            return self.exec_main_proc()
        except ValidationError as err:
            logger.fatal(err)
            logger.info(self.event)

            return {
                'statusCode':
                400,
                'body':
                json.dumps({'message': "Invalid parameter: {0}".format(err)})
            }
        except NotVerifiedUserError as err:
            logger.fatal(err)
            logger.info(self.event)

            return {
                'statusCode': 400,
                'body': json.dumps({'message': "Bad Request: {0}".format(err)})
            }
        except NotAuthorizedError as err:
            logger.fatal(err)
            logger.info(self.event)

            return {
                'statusCode': 403,
                'body': json.dumps({'message': str(err)})
            }
        except RecordNotFoundError as err:
            logger.fatal(err)
            logger.info(self.event)

            return {
                'statusCode': 404,
                'body': json.dumps({'message': str(err)})
            }

        except Exception as err:
            logger.fatal(err)
            logger.info(self.event)
            traceback.print_exc()

            return {
                'statusCode': 500,
                'body': json.dumps({'message': 'Internal server error'})
            }
Ejemplo n.º 10
0
 def validate_params(self):
     ParameterUtil.cast_parameter_to_int(self.params, self.get_schema())
     UserUtil.verified_phone_and_email(self.event)
     validate(self.params, self.get_schema())
     DBUtil.validate_article_existence(
         self.dynamodb,
         self.event['pathParameters']['article_id'],
         user_id=self.event['requestContext']['authorizer']['claims']
         ['cognito:username'])
Ejemplo n.º 11
0
 def validate_params(self):
     UserUtil.verified_phone_and_email(self.event)
     validate(self.params, self.get_schema())
     # 該当 article_id が自分のものかつ、v2であることを確認
     DBUtil.validate_article_existence(
         self.dynamodb,
         self.params['article_id'],
         user_id=self.event['requestContext']['authorizer']['claims']['cognito:username'],
         version=2
     )
Ejemplo n.º 12
0
    def validate_params(self):
        UserUtil.verified_phone_and_email(self.event)
        validate(self.params, self.get_schema())

        DBUtil.validate_article_existence(
            self.dynamodb,
            self.params['article_id'],
            user_id=self.event['requestContext']['authorizer']['claims']
            ['cognito:username'],
            status='public')
Ejemplo n.º 13
0
 def validate_params(self):
     UserUtil.verified_phone_and_email(self.event)
     # single
     if self.event.get('pathParameters') is None:
         raise ValidationError('pathParameters is required')
     validate(self.event.get('pathParameters'), self.get_schema())
     # relation
     DBUtil.validate_article_existence(
         self.dynamodb,
         self.event['pathParameters']['article_id'],
         status='public')
Ejemplo n.º 14
0
 def test_verified_phone_and_email_ng_not_exist_email(self):
     event = {
         'requestContext': {
             'authorizer': {
                 'claims': {
                     'phone_number_verified': 'true'
                 }
             }
         }
     }
     with self.assertRaises(NotVerifiedUserError):
         UserUtil.verified_phone_and_email(event)
    def validate_params(self):
        UserUtil.verified_phone_and_email(self.event)
        if not self.event.get('pathParameters'):
            raise ValidationError('pathParameters is required')

        if not self.event.get('body') or not json.loads(
                self.event.get('body')):
            raise ValidationError('Request parameter is required')

        validate(self.params,
                 self.get_schema(),
                 format_checker=FormatChecker())
Ejemplo n.º 16
0
    def validate_params(self):
        UserUtil.verified_phone_and_email(self.event)
        if not self.event.get('body'):
            raise ValidationError('Request parameter is required')

        validate(self.params, self.get_schema())
        DBUtil.validate_write_blacklisted(
            self.dynamodb, self.event['requestContext']['authorizer']['claims']
            ['cognito:username'])
        DBUtil.validate_article_existence(self.dynamodb,
                                          self.params['article_id'],
                                          status='public')
Ejemplo n.º 17
0
 def test_verified_phone_and_email_ng_all_params_false(self):
     event = {
         'requestContext': {
             'authorizer': {
                 'claims': {
                     'phone_number_verified': 'false',
                     'email_verified': 'false'
                 }
             }
         }
     }
     with self.assertRaises(NotVerifiedUserError):
         UserUtil.verified_phone_and_email(event)
    def validate_params(self):
        UserUtil.verified_phone_and_email(self.event)

        # send_value について数値でのチェックを行うため、int に変換
        try:
            self.params['send_value'] = int(self.params['send_value'])
        except ValueError:
            raise ValidationError('send_value must be numeric')

        # pinコードを検証
        self.__validate_pin_code(self.params['access_token'],
                                 self.params['pin_code'])

        validate(self.params, self.get_schema())
    def validate_params(self):
        UserUtil.verified_phone_and_email(self.event)
        # single
        # params
        validate(self.params, self.get_schema())
        self.validate_image_data(self.params['article_image'])
        # headers
        validate(self.event.get('headers'), self.get_headers_schema())

        # relation
        DBUtil.validate_article_existence(
            self.dynamodb,
            self.event['pathParameters']['article_id'],
            user_id=self.event['requestContext']['authorizer']['claims']
            ['cognito:username'])
    def validate_params(self):
        UserUtil.verified_phone_and_email(self.event)
        if self.event['requestContext']['authorizer']['claims'].get(
                'custom:private_eth_address') is None:
            raise ValidationError('not exists private_eth_address')

        # single
        if self.event.get('pathParameters') is None:
            raise ValidationError('pathParameters is required')
        validate(self.event.get('pathParameters'), self.get_schema())
        # relation
        DBUtil.validate_article_existence(
            self.dynamodb,
            self.event['pathParameters']['article_id'],
            status='public')
    def validate_params(self):
        UserUtil.verified_phone_and_email(self.event)

        validate(self.params,
                 self.get_schema(),
                 format_checker=FormatChecker())

        self.__validate_reporting_myself()

        # 著作権侵害の場合はオリジナル記事のURLを必須とする
        if self.params['reason'] == 'copyright_violation':
            if not self.params['origin_url']:
                raise ValidationError('origin url is required')

        DBUtil.validate_user_existence(self.dynamodb,
                                       self.event['pathParameters']['user_id'])
    def validate_params(self):
        UserUtil.verified_phone_and_email(self.event)

        # single
        if self.event.get('pathParameters') is None:
            raise ValidationError('pathParameters is required')
        validate(self.params, self.get_schema(), format_checker=FormatChecker())

        # 著作権侵害の場合はオリジナル記事のURLを必須とする
        if self.params['reason'] == 'copyright_violation':
            if not self.params['origin_url']:
                raise ValidationError('origin url is required')

        # relation
        DBUtil.validate_article_existence(
            self.dynamodb,
            self.event['pathParameters']['article_id'],
            status='public'
        )
Ejemplo n.º 23
0
    def validate_params(self):
        UserUtil.verified_phone_and_email(self.event)
        if not self.event.get('pathParameters'):
            raise ValidationError('pathParameters is required')

        if not self.event.get('body') or not json.loads(
                self.event.get('body')):
            raise ValidationError('Request parameter is required')

        validate(self.params,
                 self.get_schema(),
                 format_checker=FormatChecker())

        DBUtil.validate_article_existence(
            self.dynamodb,
            self.params['article_id'],
            user_id=self.event['requestContext']['authorizer']['claims']
            ['cognito:username'],
            status='public',
            version=1)
Ejemplo n.º 24
0
 def test_verified_phone_and_email_ng_not_exist_all_params(self):
     event = {
         'requestContext': {
             'authorizer': {
                 'claims': {
                 }
             }
         }
     }
     result = UserUtil.verified_phone_and_email(event)
     self.assertTrue(result)
Ejemplo n.º 25
0
    def validate_params(self):
        UserUtil.verified_phone_and_email(self.event)
        if self.event.get('pathParameters') is None:
            raise ValidationError('pathParameters is required')

        validate(self.params, self.get_schema())

        if self.params.get('tags'):
            ParameterUtil.validate_array_unique(self.params['tags'],
                                                'tags',
                                                case_insensitive=True)
            TagUtil.validate_format(self.params['tags'])

        DBUtil.validate_article_existence(
            self.dynamodb,
            self.params['article_id'],
            user_id=self.event['requestContext']['authorizer']['claims']
            ['cognito:username'],
            status='public')

        DBUtil.validate_topic(self.dynamodb, self.params['topic'])
Ejemplo n.º 26
0
 def test_verified_phone_and_email_ok(self):
     event = {
         'requestContext': {
             'authorizer': {
                 'claims': {
                     'phone_number_verified': 'true',
                     'email_verified': 'true'
                 }
             }
         }
     }
     result = UserUtil.verified_phone_and_email(event)
     self.assertTrue(result)
Ejemplo n.º 27
0
 def test_verified_phone_and_email_ok_not_exist_requestContext(self):
     event = {
     }
     result = UserUtil.verified_phone_and_email(event)
     self.assertTrue(result)
Ejemplo n.º 28
0
 def validate_params(self):
     UserUtil.verified_phone_and_email(self.event)
     validate(self.params,
              self.get_schema(),
              format_checker=FormatChecker())
Ejemplo n.º 29
0
 def validate_params(self):
     UserUtil.verified_phone_and_email(self.event)
     validate(self.params, self.get_schema())
Ejemplo n.º 30
0
 def validate_params(self):
     UserUtil.verified_phone_and_email(self.event)