Example #1
0
 bool ValidatorImpl::has_invalid_update_fields( const Resource& value, const Bytes& type )
 {
     if ( type == SUBSCRIPTION )
     {
         if ( value.count( "endpoint" ) )
         {
             const auto endpoint = String::to_string( value.lower_bound( "endpoint" )->second );
             
             if ( not Uri::is_valid( endpoint ) )
             {
                 return true;
             }
             
             const Uri uri( endpoint );
             
             if ( uri.get_scheme( ) not_eq "http" )
             {
                 return true;
             }
         }
     }
     else if ( type == QUEUE )
     {
         return has_invalid_create_fields( value, type );
     }
     
     return false;
 }
Example #2
0
 bool ValidatorImpl::has_invalid_key( const Resource& value )
 {
     if ( value.count( "key" ) )
     {
         const auto key = String::to_string( value.lower_bound( "key" )->second );
         
         static const regex regular_expression( key_pattern );
         return not regex_match( key, regular_expression );
     }
     
     return false;
 }
Example #3
0
 bool ValidatorImpl::has_invalid_create_fields( const Resource& value, const Bytes& type )
 {
     if ( type == SUBSCRIPTION )
     {
         if ( value.count( "endpoint" ) not_eq 1 )
         {
             return true;
         }
         
         const auto endpoint = String::to_string( value.lower_bound( "endpoint" )->second );
         
         if ( not Uri::is_valid( endpoint ) )
         {
             return true;
         }
         
         const Uri uri( endpoint );
         
         if ( uri.get_scheme( ) not_eq "http" )
         {
             return true;
         }
         
         if ( value.count( "state" ) )
         {
             const auto state = String::lowercase( String::to_string( value.lower_bound( "state" )->second ) );
             
             if ( state not_eq "reachable" or state not_eq "unreachable" )
             {
                 return true;
             }
         }
     }
     else if ( type == QUEUE )
     {
         try
         {
             if ( value.count( "message-limit" ) )
             {
                 stoul( String::to_string( value.lower_bound( "message-limit" )->second ) );
             }
             
             if ( value.count( "message-size-limit" ) )
             {
                 stoul( String::to_string( value.lower_bound( "message-size-limit" )->second ) );
             }
             
             if ( value.count( "subscription-limit" ) )
             {
                 stoul( String::to_string( value.lower_bound( "subscription-limit" )->second ) );
             }
             
             if ( value.count( "max-delivery-attempts" ) )
             {
                 stoul( String::to_string( value.lower_bound( "max-delivery-attempts" )->second ) );
             }
             
             if ( value.count( "redelivery-interval" ) )
             {
                 stoul( String::to_string( value.lower_bound( "redelivery-interval" )->second ) );
             }
             
             if ( value.count( "pattern" ) and "pub-sub" not_eq String::lowercase( String::to_string( value.lower_bound( "pattern" )->second ) ) )
             {
                 return true;
             }
         }
         catch ( const invalid_argument& )
         {
             return true;
         }
         catch ( const out_of_range& )
         {
             return true;
         }
     }
     
     return false;
 }
Example #4
0
 bool ValidatorImpl::has_reserved_update_fields( const Resource& value )
 {
     return value.count( "key" ) or has_reserved_create_fields( value );
 }