{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.Organizations.DisablePolicyType
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Disables an organizational policy type in a root. A policy of a certain
-- type can be attached to entities in a root only if that type is enabled
-- in the root. After you perform this operation, you no longer can attach
-- policies of the specified type to that root or to any organizational
-- unit (OU) or account in that root. You can undo this by using the
-- EnablePolicyType operation.
--
-- This is an asynchronous request that AWS performs in the background. If
-- you disable a policy type for a root, it still appears enabled for the
-- organization if
-- <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_org_support-all-features.html all features>
-- are enabled for the organization. AWS recommends that you first use
-- ListRoots to see the status of policy types for a specified root, and
-- then use this operation.
--
-- This operation can be called only from the organization\'s management
-- account.
--
-- To view the status of available policy types in the organization, use
-- DescribeOrganization.
module Amazonka.Organizations.DisablePolicyType
  ( -- * Creating a Request
    DisablePolicyType (..),
    newDisablePolicyType,

    -- * Request Lenses
    disablePolicyType_rootId,
    disablePolicyType_policyType,

    -- * Destructuring the Response
    DisablePolicyTypeResponse (..),
    newDisablePolicyTypeResponse,

    -- * Response Lenses
    disablePolicyTypeResponse_root,
    disablePolicyTypeResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Organizations.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newDisablePolicyType' smart constructor.
data DisablePolicyType = DisablePolicyType'
  { -- | The unique identifier (ID) of the root in which you want to disable a
    -- policy type. You can get the ID from the ListRoots operation.
    --
    -- The <http://wikipedia.org/wiki/regex regex pattern> for a root ID string
    -- requires \"r-\" followed by from 4 to 32 lowercase letters or digits.
    DisablePolicyType -> Text
rootId :: Prelude.Text,
    -- | The policy type that you want to disable in this root. You can specify
    -- one of the following values:
    --
    -- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_ai-opt-out.html AISERVICES_OPT_OUT_POLICY>
    --
    -- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_backup.html BACKUP_POLICY>
    --
    -- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scp.html SERVICE_CONTROL_POLICY>
    --
    -- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html TAG_POLICY>
    DisablePolicyType -> PolicyType
policyType :: PolicyType
  }
  deriving (DisablePolicyType -> DisablePolicyType -> Bool
(DisablePolicyType -> DisablePolicyType -> Bool)
-> (DisablePolicyType -> DisablePolicyType -> Bool)
-> Eq DisablePolicyType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DisablePolicyType -> DisablePolicyType -> Bool
$c/= :: DisablePolicyType -> DisablePolicyType -> Bool
== :: DisablePolicyType -> DisablePolicyType -> Bool
$c== :: DisablePolicyType -> DisablePolicyType -> Bool
Prelude.Eq, ReadPrec [DisablePolicyType]
ReadPrec DisablePolicyType
Int -> ReadS DisablePolicyType
ReadS [DisablePolicyType]
(Int -> ReadS DisablePolicyType)
-> ReadS [DisablePolicyType]
-> ReadPrec DisablePolicyType
-> ReadPrec [DisablePolicyType]
-> Read DisablePolicyType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DisablePolicyType]
$creadListPrec :: ReadPrec [DisablePolicyType]
readPrec :: ReadPrec DisablePolicyType
$creadPrec :: ReadPrec DisablePolicyType
readList :: ReadS [DisablePolicyType]
$creadList :: ReadS [DisablePolicyType]
readsPrec :: Int -> ReadS DisablePolicyType
$creadsPrec :: Int -> ReadS DisablePolicyType
Prelude.Read, Int -> DisablePolicyType -> ShowS
[DisablePolicyType] -> ShowS
DisablePolicyType -> String
(Int -> DisablePolicyType -> ShowS)
-> (DisablePolicyType -> String)
-> ([DisablePolicyType] -> ShowS)
-> Show DisablePolicyType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DisablePolicyType] -> ShowS
$cshowList :: [DisablePolicyType] -> ShowS
show :: DisablePolicyType -> String
$cshow :: DisablePolicyType -> String
showsPrec :: Int -> DisablePolicyType -> ShowS
$cshowsPrec :: Int -> DisablePolicyType -> ShowS
Prelude.Show, (forall x. DisablePolicyType -> Rep DisablePolicyType x)
-> (forall x. Rep DisablePolicyType x -> DisablePolicyType)
-> Generic DisablePolicyType
forall x. Rep DisablePolicyType x -> DisablePolicyType
forall x. DisablePolicyType -> Rep DisablePolicyType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DisablePolicyType x -> DisablePolicyType
$cfrom :: forall x. DisablePolicyType -> Rep DisablePolicyType x
Prelude.Generic)

-- |
-- Create a value of 'DisablePolicyType' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'rootId', 'disablePolicyType_rootId' - The unique identifier (ID) of the root in which you want to disable a
-- policy type. You can get the ID from the ListRoots operation.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> for a root ID string
-- requires \"r-\" followed by from 4 to 32 lowercase letters or digits.
--
-- 'policyType', 'disablePolicyType_policyType' - The policy type that you want to disable in this root. You can specify
-- one of the following values:
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_ai-opt-out.html AISERVICES_OPT_OUT_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_backup.html BACKUP_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scp.html SERVICE_CONTROL_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html TAG_POLICY>
newDisablePolicyType ::
  -- | 'rootId'
  Prelude.Text ->
  -- | 'policyType'
  PolicyType ->
  DisablePolicyType
newDisablePolicyType :: Text -> PolicyType -> DisablePolicyType
newDisablePolicyType Text
pRootId_ PolicyType
pPolicyType_ =
  DisablePolicyType' :: Text -> PolicyType -> DisablePolicyType
DisablePolicyType'
    { $sel:rootId:DisablePolicyType' :: Text
rootId = Text
pRootId_,
      $sel:policyType:DisablePolicyType' :: PolicyType
policyType = PolicyType
pPolicyType_
    }

-- | The unique identifier (ID) of the root in which you want to disable a
-- policy type. You can get the ID from the ListRoots operation.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> for a root ID string
-- requires \"r-\" followed by from 4 to 32 lowercase letters or digits.
disablePolicyType_rootId :: Lens.Lens' DisablePolicyType Prelude.Text
disablePolicyType_rootId :: (Text -> f Text) -> DisablePolicyType -> f DisablePolicyType
disablePolicyType_rootId = (DisablePolicyType -> Text)
-> (DisablePolicyType -> Text -> DisablePolicyType)
-> Lens DisablePolicyType DisablePolicyType Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DisablePolicyType' {Text
rootId :: Text
$sel:rootId:DisablePolicyType' :: DisablePolicyType -> Text
rootId} -> Text
rootId) (\s :: DisablePolicyType
s@DisablePolicyType' {} Text
a -> DisablePolicyType
s {$sel:rootId:DisablePolicyType' :: Text
rootId = Text
a} :: DisablePolicyType)

-- | The policy type that you want to disable in this root. You can specify
-- one of the following values:
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_ai-opt-out.html AISERVICES_OPT_OUT_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_backup.html BACKUP_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scp.html SERVICE_CONTROL_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html TAG_POLICY>
disablePolicyType_policyType :: Lens.Lens' DisablePolicyType PolicyType
disablePolicyType_policyType :: (PolicyType -> f PolicyType)
-> DisablePolicyType -> f DisablePolicyType
disablePolicyType_policyType = (DisablePolicyType -> PolicyType)
-> (DisablePolicyType -> PolicyType -> DisablePolicyType)
-> Lens DisablePolicyType DisablePolicyType PolicyType PolicyType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DisablePolicyType' {PolicyType
policyType :: PolicyType
$sel:policyType:DisablePolicyType' :: DisablePolicyType -> PolicyType
policyType} -> PolicyType
policyType) (\s :: DisablePolicyType
s@DisablePolicyType' {} PolicyType
a -> DisablePolicyType
s {$sel:policyType:DisablePolicyType' :: PolicyType
policyType = PolicyType
a} :: DisablePolicyType)

instance Core.AWSRequest DisablePolicyType where
  type
    AWSResponse DisablePolicyType =
      DisablePolicyTypeResponse
  request :: DisablePolicyType -> Request DisablePolicyType
request = Service -> DisablePolicyType -> Request DisablePolicyType
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DisablePolicyType
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DisablePolicyType)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DisablePolicyType))
-> Logger
-> Service
-> Proxy DisablePolicyType
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DisablePolicyType)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Root -> Int -> DisablePolicyTypeResponse
DisablePolicyTypeResponse'
            (Maybe Root -> Int -> DisablePolicyTypeResponse)
-> Either String (Maybe Root)
-> Either String (Int -> DisablePolicyTypeResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Root)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Root")
            Either String (Int -> DisablePolicyTypeResponse)
-> Either String Int -> Either String DisablePolicyTypeResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable DisablePolicyType

instance Prelude.NFData DisablePolicyType

instance Core.ToHeaders DisablePolicyType where
  toHeaders :: DisablePolicyType -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DisablePolicyType -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"AWSOrganizationsV20161128.DisablePolicyType" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON DisablePolicyType where
  toJSON :: DisablePolicyType -> Value
toJSON DisablePolicyType' {Text
PolicyType
policyType :: PolicyType
rootId :: Text
$sel:policyType:DisablePolicyType' :: DisablePolicyType -> PolicyType
$sel:rootId:DisablePolicyType' :: DisablePolicyType -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"RootId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
rootId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"PolicyType" Text -> PolicyType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= PolicyType
policyType)
          ]
      )

instance Core.ToPath DisablePolicyType where
  toPath :: DisablePolicyType -> ByteString
toPath = ByteString -> DisablePolicyType -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery DisablePolicyType where
  toQuery :: DisablePolicyType -> QueryString
toQuery = QueryString -> DisablePolicyType -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newDisablePolicyTypeResponse' smart constructor.
data DisablePolicyTypeResponse = DisablePolicyTypeResponse'
  { -- | A structure that shows the root with the updated list of enabled policy
    -- types.
    DisablePolicyTypeResponse -> Maybe Root
root :: Prelude.Maybe Root,
    -- | The response's http status code.
    DisablePolicyTypeResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DisablePolicyTypeResponse -> DisablePolicyTypeResponse -> Bool
(DisablePolicyTypeResponse -> DisablePolicyTypeResponse -> Bool)
-> (DisablePolicyTypeResponse -> DisablePolicyTypeResponse -> Bool)
-> Eq DisablePolicyTypeResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DisablePolicyTypeResponse -> DisablePolicyTypeResponse -> Bool
$c/= :: DisablePolicyTypeResponse -> DisablePolicyTypeResponse -> Bool
== :: DisablePolicyTypeResponse -> DisablePolicyTypeResponse -> Bool
$c== :: DisablePolicyTypeResponse -> DisablePolicyTypeResponse -> Bool
Prelude.Eq, ReadPrec [DisablePolicyTypeResponse]
ReadPrec DisablePolicyTypeResponse
Int -> ReadS DisablePolicyTypeResponse
ReadS [DisablePolicyTypeResponse]
(Int -> ReadS DisablePolicyTypeResponse)
-> ReadS [DisablePolicyTypeResponse]
-> ReadPrec DisablePolicyTypeResponse
-> ReadPrec [DisablePolicyTypeResponse]
-> Read DisablePolicyTypeResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DisablePolicyTypeResponse]
$creadListPrec :: ReadPrec [DisablePolicyTypeResponse]
readPrec :: ReadPrec DisablePolicyTypeResponse
$creadPrec :: ReadPrec DisablePolicyTypeResponse
readList :: ReadS [DisablePolicyTypeResponse]
$creadList :: ReadS [DisablePolicyTypeResponse]
readsPrec :: Int -> ReadS DisablePolicyTypeResponse
$creadsPrec :: Int -> ReadS DisablePolicyTypeResponse
Prelude.Read, Int -> DisablePolicyTypeResponse -> ShowS
[DisablePolicyTypeResponse] -> ShowS
DisablePolicyTypeResponse -> String
(Int -> DisablePolicyTypeResponse -> ShowS)
-> (DisablePolicyTypeResponse -> String)
-> ([DisablePolicyTypeResponse] -> ShowS)
-> Show DisablePolicyTypeResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DisablePolicyTypeResponse] -> ShowS
$cshowList :: [DisablePolicyTypeResponse] -> ShowS
show :: DisablePolicyTypeResponse -> String
$cshow :: DisablePolicyTypeResponse -> String
showsPrec :: Int -> DisablePolicyTypeResponse -> ShowS
$cshowsPrec :: Int -> DisablePolicyTypeResponse -> ShowS
Prelude.Show, (forall x.
 DisablePolicyTypeResponse -> Rep DisablePolicyTypeResponse x)
-> (forall x.
    Rep DisablePolicyTypeResponse x -> DisablePolicyTypeResponse)
-> Generic DisablePolicyTypeResponse
forall x.
Rep DisablePolicyTypeResponse x -> DisablePolicyTypeResponse
forall x.
DisablePolicyTypeResponse -> Rep DisablePolicyTypeResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DisablePolicyTypeResponse x -> DisablePolicyTypeResponse
$cfrom :: forall x.
DisablePolicyTypeResponse -> Rep DisablePolicyTypeResponse x
Prelude.Generic)

-- |
-- Create a value of 'DisablePolicyTypeResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'root', 'disablePolicyTypeResponse_root' - A structure that shows the root with the updated list of enabled policy
-- types.
--
-- 'httpStatus', 'disablePolicyTypeResponse_httpStatus' - The response's http status code.
newDisablePolicyTypeResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DisablePolicyTypeResponse
newDisablePolicyTypeResponse :: Int -> DisablePolicyTypeResponse
newDisablePolicyTypeResponse Int
pHttpStatus_ =
  DisablePolicyTypeResponse' :: Maybe Root -> Int -> DisablePolicyTypeResponse
DisablePolicyTypeResponse'
    { $sel:root:DisablePolicyTypeResponse' :: Maybe Root
root = Maybe Root
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DisablePolicyTypeResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A structure that shows the root with the updated list of enabled policy
-- types.
disablePolicyTypeResponse_root :: Lens.Lens' DisablePolicyTypeResponse (Prelude.Maybe Root)
disablePolicyTypeResponse_root :: (Maybe Root -> f (Maybe Root))
-> DisablePolicyTypeResponse -> f DisablePolicyTypeResponse
disablePolicyTypeResponse_root = (DisablePolicyTypeResponse -> Maybe Root)
-> (DisablePolicyTypeResponse
    -> Maybe Root -> DisablePolicyTypeResponse)
-> Lens
     DisablePolicyTypeResponse
     DisablePolicyTypeResponse
     (Maybe Root)
     (Maybe Root)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DisablePolicyTypeResponse' {Maybe Root
root :: Maybe Root
$sel:root:DisablePolicyTypeResponse' :: DisablePolicyTypeResponse -> Maybe Root
root} -> Maybe Root
root) (\s :: DisablePolicyTypeResponse
s@DisablePolicyTypeResponse' {} Maybe Root
a -> DisablePolicyTypeResponse
s {$sel:root:DisablePolicyTypeResponse' :: Maybe Root
root = Maybe Root
a} :: DisablePolicyTypeResponse)

-- | The response's http status code.
disablePolicyTypeResponse_httpStatus :: Lens.Lens' DisablePolicyTypeResponse Prelude.Int
disablePolicyTypeResponse_httpStatus :: (Int -> f Int)
-> DisablePolicyTypeResponse -> f DisablePolicyTypeResponse
disablePolicyTypeResponse_httpStatus = (DisablePolicyTypeResponse -> Int)
-> (DisablePolicyTypeResponse -> Int -> DisablePolicyTypeResponse)
-> Lens DisablePolicyTypeResponse DisablePolicyTypeResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DisablePolicyTypeResponse' {Int
httpStatus :: Int
$sel:httpStatus:DisablePolicyTypeResponse' :: DisablePolicyTypeResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: DisablePolicyTypeResponse
s@DisablePolicyTypeResponse' {} Int
a -> DisablePolicyTypeResponse
s {$sel:httpStatus:DisablePolicyTypeResponse' :: Int
httpStatus = Int
a} :: DisablePolicyTypeResponse)

instance Prelude.NFData DisablePolicyTypeResponse