From 2e95c66694eeee77a8cc968cfcdfc2fb428b2e15 Mon Sep 17 00:00:00 2001 From: Vehbi Sinan Tunalioglu Date: Mon, 13 May 2024 08:39:37 +0800 Subject: [PATCH] feat: list domains managed on AWS Route53 --- package.yaml | 1 + src/Clompse/Programs/ListDomains.hs | 8 ++++++-- src/Clompse/Providers/Aws.hs | 3 ++- src/Clompse/Providers/Aws/ApiAws.hs | 21 +++++++++++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/package.yaml b/package.yaml index 9fccf93..c07d0b1 100644 --- a/package.yaml +++ b/package.yaml @@ -24,6 +24,7 @@ library: - amazonka-core - amazonka-ec2 - amazonka-lightsail + - amazonka-route53 - amazonka-s3 - async-pool - autodocodec diff --git a/src/Clompse/Programs/ListDomains.hs b/src/Clompse/Programs/ListDomains.hs index 55fc99b..cc6c09f 100644 --- a/src/Clompse/Programs/ListDomains.hs +++ b/src/Clompse/Programs/ListDomains.hs @@ -7,6 +7,7 @@ module Clompse.Programs.ListDomains where import qualified Autodocodec as ADC import Clompse.Config (CloudConnection (..), CloudProfile (..), Config (..)) +import qualified Clompse.Providers.Aws as Providers.Aws import qualified Clompse.Providers.Do as Providers.Do import qualified Clompse.Types as Types import qualified Control.Concurrent.Async.Pool as Async @@ -62,8 +63,11 @@ listDomainsForCloudConnection :: MonadIO m => CloudConnection -> m [Types.Domain] -listDomainsForCloudConnection (CloudConnectionAws _conn) = do - pure [] +listDomainsForCloudConnection (CloudConnectionAws conn) = do + eRecords <- runExceptT (Providers.Aws.listDomainsRoute53 conn) + case eRecords of + Left e -> _log (" ERROR (AWS Route53 Domains): " <> Z.Text.tshow e) >> pure [] + Right records -> pure records listDomainsForCloudConnection (CloudConnectionDo conn) = do eRecords <- runExceptT (Providers.Do.listDomains conn) case eRecords of diff --git a/src/Clompse/Providers/Aws.hs b/src/Clompse/Providers/Aws.hs index 91f3508..f1bef83 100644 --- a/src/Clompse/Providers/Aws.hs +++ b/src/Clompse/Providers/Aws.hs @@ -5,11 +5,12 @@ module Clompse.Providers.Aws ( AwsConnection (..), listBucketsLightsail, listBucketsS3, + listDomainsRoute53, listServersEc2, listServersLightsail, ) where -import Clompse.Providers.Aws.ApiAws (listBucketsS3, listServersEc2) +import Clompse.Providers.Aws.ApiAws (listBucketsS3, listDomainsRoute53, listServersEc2) import Clompse.Providers.Aws.ApiLightsail (listBucketsLightsail, listServersLightsail) import Clompse.Providers.Aws.Connection (AwsConnection (..)) import Clompse.Providers.Aws.Error (AwsError (..)) diff --git a/src/Clompse/Providers/Aws/ApiAws.hs b/src/Clompse/Providers/Aws/ApiAws.hs index 7c885ff..eaec4e7 100644 --- a/src/Clompse/Providers/Aws/ApiAws.hs +++ b/src/Clompse/Providers/Aws/ApiAws.hs @@ -13,6 +13,8 @@ import qualified Amazonka.EC2 as Aws.Ec2 import qualified Amazonka.EC2.Lens as Aws.Ec2.Lens import qualified Amazonka.EC2.Types as Aws.Ec2.Types import qualified Amazonka.EC2.Types as Aws.Ec2.Types.InstanceTypeInfo +import qualified Amazonka.Route53 as Aws.Route53 +import qualified Amazonka.Route53.Lens as Aws.Route53.Lens import qualified Amazonka.S3 as Aws.S3 import qualified Amazonka.S3.Lens as Aws.S3.Lens import Clompse.Providers.Aws.Connection (AwsConnection, _envFromConnection) @@ -56,6 +58,25 @@ listBucketsS3 = awsListAllS3Buckets +listDomainsRoute53 + :: MonadIO m + => MonadError AwsError m + => AwsConnection + -> m [Types.Domain] +listDomainsRoute53 cfg = do + env <- _envFromConnection cfg + let prog = Aws.send env Aws.Route53.newListHostedZones + resIs <- liftIO . fmap (L.view Aws.Route53.Lens.listHostedZonesResponse_hostedZones) . Aws.runResourceT $ prog + pure $ fmap mkTuple resIs + where + mkTuple b = + let name = b L.^. Aws.Route53.Lens.hostedZone_name + in Types.Domain + { Types._domainName = name + , Types._domainProvider = Types.ProviderAws + } + + -- * Data Definitions