@@ -57,6 +57,8 @@ public AdminPaths(WireMockServerSettings settings)
5757 public string OpenApi => $ "{ _prefix } /openapi";
5858
5959 public RegexMatcher MappingsGuidPathMatcher => new ( $ "^{ _prefixEscaped } \\ /mappings\\ /([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})$") ;
60+ public RegexMatcher MappingsGuidEnablePathMatcher => new ( $ "^{ _prefixEscaped } \\ /mappings\\ /([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})\\ /enable$") ;
61+ public RegexMatcher MappingsGuidDisablePathMatcher => new ( $ "^{ _prefixEscaped } \\ /mappings\\ /([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})\\ /disable$") ;
6062 public RegexMatcher MappingsCodeGuidPathMatcher => new ( $ "^{ _prefixEscaped } \\ /mappings\\ /code\\ /([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})$") ;
6163 public RegexMatcher RequestsGuidPathMatcher => new ( $ "^{ _prefixEscaped } \\ /requests\\ /([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})$") ;
6264 public RegexMatcher ScenariosNameMatcher => new ( $ "^{ _prefixEscaped } \\ /scenarios\\ /.+$") ;
@@ -100,6 +102,12 @@ private void InitAdmin()
100102 Given ( Request . Create ( ) . WithPath ( _adminPaths . MappingsGuidPathMatcher ) . UsingPut ( ) . WithHeader ( HttpKnownHeaderNames . ContentType , AdminRequestContentTypeJson ) ) . AtPriority ( WireMockConstants . AdminPriority ) . RespondWith ( new DynamicResponseProvider ( MappingPut ) ) ;
101103 Given ( Request . Create ( ) . WithPath ( _adminPaths . MappingsGuidPathMatcher ) . UsingDelete ( ) ) . AtPriority ( WireMockConstants . AdminPriority ) . RespondWith ( new DynamicResponseProvider ( MappingDelete ) ) ;
102104
105+ // __admin/mappings/{guid}/enable
106+ Given ( Request . Create ( ) . WithPath ( _adminPaths . MappingsGuidEnablePathMatcher ) . UsingPut ( ) ) . AtPriority ( WireMockConstants . AdminPriority ) . RespondWith ( new DynamicResponseProvider ( MappingEnable ) ) ;
107+
108+ // __admin/mappings/{guid}/disable
109+ Given ( Request . Create ( ) . WithPath ( _adminPaths . MappingsGuidDisablePathMatcher ) . UsingPut ( ) ) . AtPriority ( WireMockConstants . AdminPriority ) . RespondWith ( new DynamicResponseProvider ( MappingDisable ) ) ;
110+
103111 // __admin/mappings/code/{guid}
104112 Given ( Request . Create ( ) . WithPath ( _adminPaths . MappingsCodeGuidPathMatcher ) . UsingGet ( ) ) . AtPriority ( WireMockConstants . AdminPriority ) . RespondWith ( new DynamicResponseProvider ( MappingCodeGet ) ) ;
105113
@@ -426,6 +434,47 @@ private static bool TryParseGuidFromRequestMessage(IRequestMessage requestMessag
426434 var lastPart = requestMessage . Path . Split ( '/' ) . LastOrDefault ( ) ;
427435 return Guid . TryParse ( lastPart , out guid ) ;
428436 }
437+
438+ private static bool TryParseGuidFromSecondToLastSegment ( IRequestMessage requestMessage , out Guid guid )
439+ {
440+ var parts = requestMessage . Path . Split ( '/' ) ;
441+ if ( parts . Length >= 2 && Guid . TryParse ( parts [ parts . Length - 2 ] , out guid ) )
442+ return true ;
443+ guid = Guid . Empty ;
444+ return false ;
445+ }
446+
447+ private IResponseMessage MappingEnable ( HttpContext _ , IRequestMessage requestMessage )
448+ {
449+ if ( TryParseGuidFromSecondToLastSegment ( requestMessage , out var guid ) )
450+ {
451+ var mapping = Mappings . FirstOrDefault ( m => ! m . IsAdminInterface && m . Guid == guid ) ;
452+ if ( mapping != null )
453+ {
454+ mapping . IsEnabled = true ;
455+ return ResponseMessageBuilder . Create ( HttpStatusCode . OK , "Mapping enabled" , guid ) ;
456+ }
457+ }
458+
459+ _settings . Logger . Warn ( "HttpStatusCode set to 404 : Mapping not found" ) ;
460+ return ResponseMessageBuilder . Create ( HttpStatusCode . NotFound , "Mapping not found" ) ;
461+ }
462+
463+ private IResponseMessage MappingDisable ( HttpContext _ , IRequestMessage requestMessage )
464+ {
465+ if ( TryParseGuidFromSecondToLastSegment ( requestMessage , out var guid ) )
466+ {
467+ var mapping = Mappings . FirstOrDefault ( m => ! m . IsAdminInterface && m . Guid == guid ) ;
468+ if ( mapping != null )
469+ {
470+ mapping . IsEnabled = false ;
471+ return ResponseMessageBuilder . Create ( HttpStatusCode . OK , "Mapping disabled" , guid ) ;
472+ }
473+ }
474+
475+ _settings . Logger . Warn ( "HttpStatusCode set to 404 : Mapping not found" ) ;
476+ return ResponseMessageBuilder . Create ( HttpStatusCode . NotFound , "Mapping not found" ) ;
477+ }
429478 #endregion Mapping/{guid}
430479
431480 #region Mappings
0 commit comments