{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wall -Werror #-}

-- |
-- Module      : Amazonka.Route53.Internal
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka.com>
-- Stability   : experimental
-- Portability : non-portable (GHC extensions)
module Amazonka.Route53.Internal
  ( Region (..),
    ResourceId (..),
    _ResourceId,

    -- * Website Endpoints
    getHostedZoneId,
  )
where

import Amazonka.Core
import Amazonka.Core.Lens.Internal (coerced)
import Amazonka.Data
import Amazonka.Prelude
import qualified Data.Text as Text

-- | A Route53 identifier for resources such as hosted zones and delegation sets.
--
-- Since Route53 outputs prefixed resource identifiers such as
-- @/hostedzone/ABC123@, but expects unprefixed identifiers as inputs, such as
-- @ABC123@, the 'FromXML' instance will strip this prefix take care to ensure
-- the correct input format is observed and @decodeXML . encodeXML == id@ holds.
newtype ResourceId = ResourceId {ResourceId -> Text
fromResourceId :: Text}
  deriving
    ( ResourceId -> ResourceId -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResourceId -> ResourceId -> Bool
$c/= :: ResourceId -> ResourceId -> Bool
== :: ResourceId -> ResourceId -> Bool
$c== :: ResourceId -> ResourceId -> Bool
Eq,
      Eq ResourceId
ResourceId -> ResourceId -> Bool
ResourceId -> ResourceId -> Ordering
ResourceId -> ResourceId -> ResourceId
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ResourceId -> ResourceId -> ResourceId
$cmin :: ResourceId -> ResourceId -> ResourceId
max :: ResourceId -> ResourceId -> ResourceId
$cmax :: ResourceId -> ResourceId -> ResourceId
>= :: ResourceId -> ResourceId -> Bool
$c>= :: ResourceId -> ResourceId -> Bool
> :: ResourceId -> ResourceId -> Bool
$c> :: ResourceId -> ResourceId -> Bool
<= :: ResourceId -> ResourceId -> Bool
$c<= :: ResourceId -> ResourceId -> Bool
< :: ResourceId -> ResourceId -> Bool
$c< :: ResourceId -> ResourceId -> Bool
compare :: ResourceId -> ResourceId -> Ordering
$ccompare :: ResourceId -> ResourceId -> Ordering
Ord,
      ReadPrec [ResourceId]
ReadPrec ResourceId
Int -> ReadS ResourceId
ReadS [ResourceId]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResourceId]
$creadListPrec :: ReadPrec [ResourceId]
readPrec :: ReadPrec ResourceId
$creadPrec :: ReadPrec ResourceId
readList :: ReadS [ResourceId]
$creadList :: ReadS [ResourceId]
readsPrec :: Int -> ReadS ResourceId
$creadsPrec :: Int -> ReadS ResourceId
Read,
      Int -> ResourceId -> ShowS
[ResourceId] -> ShowS
ResourceId -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResourceId] -> ShowS
$cshowList :: [ResourceId] -> ShowS
show :: ResourceId -> String
$cshow :: ResourceId -> String
showsPrec :: Int -> ResourceId -> ShowS
$cshowsPrec :: Int -> ResourceId -> ShowS
Show,
      forall x. Rep ResourceId x -> ResourceId
forall x. ResourceId -> Rep ResourceId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResourceId x -> ResourceId
$cfrom :: forall x. ResourceId -> Rep ResourceId x
Generic,
      String -> ResourceId
forall a. (String -> a) -> IsString a
fromString :: String -> ResourceId
$cfromString :: String -> ResourceId
IsString,
      Text -> Either String ResourceId
forall a. (Text -> Either String a) -> FromText a
fromText :: Text -> Either String ResourceId
$cfromText :: Text -> Either String ResourceId
FromText,
      ResourceId -> Text
forall a. (a -> Text) -> ToText a
toText :: ResourceId -> Text
$ctoText :: ResourceId -> Text
ToText,
      ResourceId -> ByteString
forall a. (a -> ByteString) -> ToByteString a
toBS :: ResourceId -> ByteString
$ctoBS :: ResourceId -> ByteString
ToByteString,
      ResourceId -> XML
forall a. (a -> XML) -> ToXML a
toXML :: ResourceId -> XML
$ctoXML :: ResourceId -> XML
ToXML,
      ResourceId -> QueryString
forall a. (a -> QueryString) -> ToQuery a
toQuery :: ResourceId -> QueryString
$ctoQuery :: ResourceId -> QueryString
ToQuery,
      ResourceId -> ByteStringBuilder
forall a. (a -> ByteStringBuilder) -> ToLog a
build :: ResourceId -> ByteStringBuilder
$cbuild :: ResourceId -> ByteStringBuilder
ToLog
    )

{-# INLINE _ResourceId #-}
_ResourceId :: Iso' ResourceId Text
_ResourceId :: Iso' ResourceId Text
_ResourceId = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
coerced

instance Hashable ResourceId

instance NFData ResourceId

-- | Handles prefixed Route53 resource identifiers.
instance FromXML ResourceId where
  parseXML :: [Node] -> Either String ResourceId
parseXML = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text -> ResourceId
ResourceId forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Text -> Text
Text.takeWhileEnd (forall a. Eq a => a -> a -> Bool
/= Char
'/')) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. FromXML a => [Node] -> Either String a
parseXML

-- | Get the hosted zone identifier for an S3 website endpoint.
--
-- When you configure your bucket as a website, the website is available using
-- a region-specific website endpoint. This hosted zone identifier is used
-- adding an alias record to the website to your hosted zone.
--
-- /See:/ <https://docs.aws.amazon.com/general/latest/gr/s3.html#s3_website_region_endpoints Amazon Simple Storage Service Website Endpoints>.
getHostedZoneId :: Region -> Maybe ResourceId
getHostedZoneId :: Region -> Maybe ResourceId
getHostedZoneId = \case
  Region
Ohio -> forall a. a -> Maybe a
Just ResourceId
"Z2O1EMRO9K5GLX"
  Region
NorthVirginia -> forall a. a -> Maybe a
Just ResourceId
"Z3AQBSTGFYJSTF"
  Region
NorthCalifornia -> forall a. a -> Maybe a
Just ResourceId
"Z2F56UZL2M1ACD"
  Region
Oregon -> forall a. a -> Maybe a
Just ResourceId
"Z3BJ6K6RIION7M"
  Region
CapeTown -> forall a. a -> Maybe a
Just ResourceId
"Z11KHD8FBVPUYU"
  Region
HongKong -> forall a. a -> Maybe a
Just ResourceId
"ZNB98KWMFR0R6"
  Region
Hyderabad -> forall a. a -> Maybe a
Just ResourceId
"Z02976202B4EZMXIPMXF7"
  Region
Jakarta -> forall a. a -> Maybe a
Just ResourceId
"Z01846753K324LI26A3VV"
  Region
Melbourne -> forall a. a -> Maybe a
Just ResourceId
"Z0312387243XT5FE14WFO"
  Region
Mumbai -> forall a. a -> Maybe a
Just ResourceId
"Z11RGJOFQNVJUP"
  Region
Osaka -> forall a. a -> Maybe a
Just ResourceId
"Z2YQB5RD63NC85"
  Region
Seoul -> forall a. a -> Maybe a
Just ResourceId
"Z3W03O7B5YMIYP"
  Region
Singapore -> forall a. a -> Maybe a
Just ResourceId
"Z3O0J2DXBE1FTB"
  Region
Sydney -> forall a. a -> Maybe a
Just ResourceId
"Z1WCIGYICN2BYD"
  Region
Tokyo -> forall a. a -> Maybe a
Just ResourceId
"Z2M4EHUR26P7ZW"
  Region
Montreal -> forall a. a -> Maybe a
Just ResourceId
"Z1QDHH18159H29"
  Region
Ningxia -> forall a. a -> Maybe a
Just ResourceId
"Z282HJ1KT0DH03"
  Region
Frankfurt -> forall a. a -> Maybe a
Just ResourceId
"Z21DNDUVLTQW6Q"
  Region
Ireland -> forall a. a -> Maybe a
Just ResourceId
"Z1BKCTXD74EZPE"
  Region
London -> forall a. a -> Maybe a
Just ResourceId
"Z3GKZC51ZF0DB4"
  Region
Milan -> forall a. a -> Maybe a
Just ResourceId
"Z30OZKI7KPW7MI"
  Region
Paris -> forall a. a -> Maybe a
Just ResourceId
"Z3R1K369G5AVDG"
  Region
Stockholm -> forall a. a -> Maybe a
Just ResourceId
"Z3BAZG2TWCNX0D"
  Region
Spain -> forall a. a -> Maybe a
Just ResourceId
"Z0081959F7139GRJC19J"
  Region
Zurich -> forall a. a -> Maybe a
Just ResourceId
"Z030506016YDQGETNASS"
  Region
Bahrain -> forall a. a -> Maybe a
Just ResourceId
"Z1MPMWCPA7YB62"
  Region
UAE -> forall a. a -> Maybe a
Just ResourceId
"Z06143092I8HRXZRUZROF"
  Region
SaoPaulo -> forall a. a -> Maybe a
Just ResourceId
"Z7KQH4QJS55SO"
  Region
GovCloudEast -> forall a. a -> Maybe a
Just ResourceId
"Z2NIFVYYW2VKV1"
  Region
GovCloudWest -> forall a. a -> Maybe a
Just ResourceId
"Z31GFT0UA1I2HV"
  Region' Text
_ -> forall a. Maybe a
Nothing