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): 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')
def validate_params(self): ParameterUtil.cast_parameter_to_int(self.params, self.get_schema()) validate(self.params, self.get_schema()) DBUtil.validate_article_existence(self.dynamodb, self.params['article_id'], status='public')
def test_validate_article_existence_ng_not_exists_user_id(self): with self.assertRaises(NotAuthorizedError): DBUtil.validate_article_existence( self.dynamodb, self.article_info_table_items[0]['article_id'], user_id='hogefugapiyo', )
def test_validate_article_existence_ng_not_validate_article_existence_id(self): with self.assertRaises(RecordNotFoundError): DBUtil.validate_article_existence( self.dynamodb, 'hogefugapiyo', user_id=self.article_info_table_items[0]['user_id'], )
def test_validate_article_existence_ng_not_exists_version2(self): with self.assertRaises(RecordNotFoundError): DBUtil.validate_article_existence( self.dynamodb, self.article_info_table_items[0]['article_id'], user_id=self.article_info_table_items[0]['user_id'], version=2)
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'])
def exec_main_proc(self): params = self.event.get('pathParameters') article_info_table = self.dynamodb.Table( os.environ['ARTICLE_INFO_TABLE_NAME']) article_content_table = self.dynamodb.Table( os.environ['ARTICLE_CONTENT_TABLE_NAME']) article_info = article_info_table.get_item( Key={ 'article_id': params['article_id'] }).get('Item') article_content = article_content_table.get_item( Key={ 'article_id': params['article_id'] }).get('Item') DBUtil.validate_article_existence( self.dynamodb, params['article_id'], user_id=self.event['requestContext']['authorizer']['claims'] ['cognito:username'], status='draft') if article_content is not None: article_info.update(article_content) return { 'statusCode': 200, 'body': json.dumps(article_info, cls=DecimalEncoder) }
def test_validate_article_existence_ng_not_exists_is_purchased(self): with self.assertRaises(RecordNotFoundError): DBUtil.validate_article_existence( self.dynamodb, self.article_info_table_items[0]['article_id'], user_id=self.article_info_table_items[0]['user_id'], is_purchased=True)
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')
def validate_params(self): 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')
def validate_params(self): validate(self.params, self.get_schema()) DBUtil.validate_article_existence( self.dynamodb, self.params['article_id'], status='public', )
def validate_params(self): # single validate(self.params, self.get_schema()) # relation DBUtil.validate_article_existence(self.dynamodb, self.params['article_id'], status='public', is_purchased=True)
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'])
def validate_params(self): 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='draft')
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 )
def validate_params(self): # 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()) DBUtil.validate_article_existence( self.dynamodb, self.params['article_id'], user_id=self.event['requestContext']['authorizer']['claims'] ['cognito:username'], status='public')
def exec_main_proc(self): DBUtil.validate_article_existence( self.dynamodb, self.params['article_id'], user_id=self.event['requestContext']['authorizer']['claims'] ['cognito:username'], status='draft') self.__update_article_content() self.__update_article_info() return {'statusCode': 200}
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')
def validate_params(self): if self.event.get('pathParameters') is None: raise ValidationError('pathParameters is required') validate(self.event.get('pathParameters'), self.get_schema()) DBUtil.validate_article_existence( self.dynamodb, self.params['article_id'], user_id=self.event['requestContext']['authorizer']['claims'] ['cognito:username'], status='public')
def validate_params(self): # 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 test_validate_article_existence_ok_exists_user_and_version2(self): result = DBUtil.validate_article_existence( self.dynamodb, self.article_info_table_items[1]['article_id'], user_id=self.article_info_table_items[1]['user_id'], version=2) self.assertTrue(result)
def test_validate_article_existence_ok_exists_user_and_status(self): result = DBUtil.validate_article_existence( self.dynamodb, self.article_info_table_items[0]['article_id'], user_id=self.article_info_table_items[0]['user_id'], status=self.article_info_table_items[0]['status']) self.assertTrue(result)
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') DBUtil.validate_parent_comment_existence(self.dynamodb, self.params['parent_id']) DBUtil.validate_user_existence(self.dynamodb, self.params['replyed_user_id']) DBUtil.validate_user_existence_in_thread( self.dynamodb, self.params['replyed_user_id'], self.params['parent_id'])
def validate_params(self): 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='draft') DBUtil.validate_topic(self.dynamodb, self.params['topic'])
def validate_params(self): 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'])
def validate_params(self): 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')