Last active
October 5, 2023 12:02
-
-
Save cboudereau/423cc1fc61e0a267b62cd065786a3e00 to your computer and use it in GitHub Desktop.
mirror_proxy.fsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Mode = Passthrough | Mirroring | Filtering | Proxy | |
let main mode proxyRemoteUrl mirrorRemoteUrl mirrorRemoteApiKey hotels = | |
match mode, proxyRemoteUrl, mirrorRemoteUrl, mirrorRemoteApiKey with | |
| Proxy, _, Some mirrorUrl, Some mirrorApiKey -> sprintf "proxy, %s, %s" mirrorUrl mirrorApiKey | |
| _, None, _, _ -> sprintf "error : missing parameters to support any mode" | |
| Passthrough, Some url, _, _ -> sprintf "passthrough with %s" url | |
| Filtering, Some remoteUrl, Some mirrorUrl, Some mirrorApiKey -> | |
match hotels () with | |
| [] -> sprintf "warning no hotels to filter, fallbacking to passthough with remote_url %s" remoteUrl | |
| hotels -> sprintf "filtering mode with %s, %s, %s and hotels %A" remoteUrl mirrorUrl mirrorApiKey hotels | |
| Mirroring, Some remoteUrl, Some mirrorUrl, Some mirrorApiKey -> sprintf "Mirroring %s, %s, %s" remoteUrl mirrorUrl mirrorApiKey | |
| mode, Some remoteUrl, _, _ -> sprintf "warning fallback to passthrough from mode %A with url %s" mode remoteUrl | |
let proxyRemoteUrl = Some "http://remote_url" | |
let mirrorRemoteUrl = Some "http://mirror_url" | |
let mirrorRemoteApiKey = Some "mirror api key" | |
let noHotels () = [] | |
let hotels h () = h | |
[ | |
//Errors | |
"error : missing parameters to support any mode" = main Passthrough None None None noHotels | |
"error : missing parameters to support any mode" = main Filtering None None None noHotels | |
"error : missing parameters to support any mode" = main Mirroring None None None noHotels | |
"error : missing parameters to support any mode" = main Proxy None None None noHotels | |
"error : missing parameters to support any mode" = main Proxy None mirrorRemoteUrl None noHotels | |
"error : missing parameters to support any mode" = main Proxy None None mirrorRemoteApiKey noHotels | |
//Fallback | |
"warning no hotels to filter, fallbacking to passthough with remote_url http://remote_url" = main Filtering proxyRemoteUrl mirrorRemoteUrl mirrorRemoteApiKey noHotels | |
"warning fallback to passthrough from mode Filtering with url http://remote_url" = main Filtering proxyRemoteUrl None None noHotels | |
"warning fallback to passthrough from mode Mirroring with url http://remote_url" = main Mirroring proxyRemoteUrl None None noHotels | |
"warning fallback to passthrough from mode Proxy with url http://remote_url" = main Proxy proxyRemoteUrl None None noHotels | |
//Happy Paths | |
"passthrough with http://remote_url" = main Passthrough proxyRemoteUrl None None noHotels | |
"Mirroring http://remote_url, http://mirror_url, mirror api key" = main Mirroring proxyRemoteUrl mirrorRemoteUrl mirrorRemoteApiKey noHotels | |
"""filtering mode with http://remote_url, http://mirror_url, mirror api key and hotels ["H1234"]""" = main Filtering proxyRemoteUrl mirrorRemoteUrl mirrorRemoteApiKey (hotels ["H1234"]) | |
"proxy, http://mirror_url, mirror api key" = main Proxy None mirrorRemoteUrl mirrorRemoteApiKey noHotels | |
] |> List.forall id | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment