123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134open!StdLabelsletsprintf=Printf.sprintftypevendor={region_name:string;host:string;port:int;}typet=|Ap_northeast_1(* Asia Pacific (Tokyo) *)|Ap_northeast_2(* Asia Pacific (Seoul) *)|Ap_northeast_3(* Asia Pacific (Osaka-Local) *)|Ap_southeast_1(* Asia Pacific (Singapore) *)|Ap_southeast_2(* Asia Pacific (Sydney) *)|Ap_south_1(* Asia Pacific (Mumbai) *)|Eu_central_1(* EU (Frankfurt) *)|Cn_northwest_1(* China (Ningxia) *)|Cn_north_1(* China (Beijing) *)|Eu_west_1(* EU (Ireland) *)|Eu_west_2(* EU (London) *)|Eu_west_3(* EU (Paris) *)|Sa_east_1(* South America (São Paulo) *)|Us_east_1(* US East (N. Virginia) *)|Us_east_2(* US East (Ohio) *)|Us_west_1(* US West (N. California) *)|Us_west_2(* US West (Oregon) *)|Ca_central_1(* Canada - central *)|Otherofstring(* Other unknown *)|Vendorofvendor(* S3-compatible vendor/service *)letto_string=function|Ap_northeast_1->"ap-northeast-1"|Ap_northeast_2->"ap-northeast-2"|Ap_northeast_3->"ap-northeast-3"|Ap_southeast_1->"ap-southeast-1"|Ap_southeast_2->"ap-southeast-2"|Ap_south_1->"ap-south-1"|Eu_central_1->"eu-central-1"|Cn_northwest_1->"cn-northwest-1"|Cn_north_1->"cn-north-1"|Eu_west_1->"eu-west-1"|Eu_west_2->"eu-west-2"|Eu_west_3->"eu-west-3"|Sa_east_1->"sa-east-1"|Us_east_1->"us-east-1"|Us_east_2->"us-east-2"|Us_west_1->"us-west-1"|Us_west_2->"us-west-2"|Ca_central_1->"ca-central-1"|Others->s|Vendorv->v.region_nameletof_string=function|"ap-northeast-1"->Ap_northeast_1|"ap-northeast-2"->Ap_northeast_2|"ap-northeast-3"->Ap_northeast_3|"ap-southeast-1"->Ap_southeast_1|"ap-southeast-2"->Ap_southeast_2|"ap-south-1"->Ap_south_1|"eu-central-1"->Eu_central_1|"cn-northwest-1"->Cn_northwest_1|"cn-north-1"->Cn_north_1|"eu-west-1"->Eu_west_1|"eu-west-2"->Eu_west_2|"eu-west-3"->Eu_west_3|"sa-east-1"->Sa_east_1|"us-east-1"->Us_east_1|"us-east-2"->Us_east_2|"us-west-1"->Us_west_1|"us-west-2"->Us_west_2|"ca-central-1"->Ca_central_1|s->failwith("Unknown region: "^s)letvendor~region_name~host~port=Vendor{region_name;host;port}letminio~host~port=vendor~region_name:(to_stringUs_east_1)~host~porttypeendpoint={inet:[`V4|`V6];scheme:[`Http|`Https];host:string;port:int;region:t;}letof_hosthost=matchString.split_on_char~sep:'.'host|>List.revwith|"com"::"amazonaws"::"s3"::_->Us_east_1|"com"::"amazonaws"::host::_whenString.lengthhost>3&&host.[0]='s'&&host.[1]='3'&&host.[2]='-'->String.sub~pos:3~len:(String.lengthhost-3)host|>of_string|"com"::"amazonaws"::host::_->host|>of_string|_->failwith"Cannot parse region from host"letto_host~dualstackregion=matchregionwith|Vendorv->v.host|_->letdualstack=matchdualstackwith|true->".dualstack"|false->""into_stringregion|>sprintf"s3%s.%s.amazonaws.com"dualstackletto_portregion=matchregionwith|Vendorv->Somev.port|_->Noneletendpoint~inet~schemeregion=letport=matchto_portregionwith|Somep->p|None->matchschemewith|`Http->80|`Https->443inletdualstack=matchinetwith|`V4->false|`V6->truein{inet;scheme;host=to_host~dualstackregion;port;region}