From bf399b724dd9d8b6e55d1684c7b80f3803fc5916 Mon Sep 17 00:00:00 2001 From: Vehbi Sinan Tunalioglu Date: Tue, 14 May 2024 08:06:10 +0800 Subject: [PATCH] feat: list domains managed on AWS Lightsail --- src/Clompse/Programs/ListDomains.hs | 9 +++++++-- src/Clompse/Providers/Aws.hs | 3 ++- src/Clompse/Providers/Aws/ApiLightsail.hs | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/Clompse/Programs/ListDomains.hs b/src/Clompse/Programs/ListDomains.hs index cc6c09f..3b0b5ce 100644 --- a/src/Clompse/Programs/ListDomains.hs +++ b/src/Clompse/Programs/ListDomains.hs @@ -64,10 +64,15 @@ listDomainsForCloudConnection => CloudConnection -> m [Types.Domain] listDomainsForCloudConnection (CloudConnectionAws conn) = do - eRecords <- runExceptT (Providers.Aws.listDomainsRoute53 conn) - case eRecords of + eRecordsRoute53 <- runExceptT (Providers.Aws.listDomainsRoute53 conn) + recordsRoute53 <- case eRecordsRoute53 of Left e -> _log (" ERROR (AWS Route53 Domains): " <> Z.Text.tshow e) >> pure [] Right records -> pure records + eRecordsRouteLightsail <- runExceptT (Providers.Aws.listDomainsLightsail conn) + recordsLightsail <- case eRecordsRouteLightsail of + Left e -> _log (" ERROR (AWS Lightsail Domains): " <> Z.Text.tshow e) >> pure [] + Right records -> pure records + pure (recordsRoute53 <> recordsLightsail) 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 f1bef83..4dbca7f 100644 --- a/src/Clompse/Providers/Aws.hs +++ b/src/Clompse/Providers/Aws.hs @@ -5,13 +5,14 @@ module Clompse.Providers.Aws ( AwsConnection (..), listBucketsLightsail, listBucketsS3, + listDomainsLightsail, listDomainsRoute53, listServersEc2, listServersLightsail, ) where import Clompse.Providers.Aws.ApiAws (listBucketsS3, listDomainsRoute53, listServersEc2) -import Clompse.Providers.Aws.ApiLightsail (listBucketsLightsail, listServersLightsail) +import Clompse.Providers.Aws.ApiLightsail (listBucketsLightsail, listDomainsLightsail, listServersLightsail) import Clompse.Providers.Aws.Connection (AwsConnection (..)) import Clompse.Providers.Aws.Error (AwsError (..)) diff --git a/src/Clompse/Providers/Aws/ApiLightsail.hs b/src/Clompse/Providers/Aws/ApiLightsail.hs index 977696e..aefe891 100644 --- a/src/Clompse/Providers/Aws/ApiLightsail.hs +++ b/src/Clompse/Providers/Aws/ApiLightsail.hs @@ -50,6 +50,25 @@ listBucketsLightsail = awsListAllLightsailBuckets +listDomainsLightsail + :: MonadIO m + => MonadError AwsError m + => AwsConnection + -> m [Types.Domain] +listDomainsLightsail cfg = do + env <- _envFromConnection cfg + let prog = Aws.send env Aws.Lightsail.newGetDomains + resIs <- liftIO . fmap (fromMaybe [] . L.view Aws.Lightsail.Lens.getDomainsResponse_domains) . Aws.runResourceT $ prog + pure $ fmap mkTuple resIs + where + mkTuple b = + let name = b L.^. Aws.Lightsail.Lens.domain_name + in Types.Domain + { Types._domainName = fromMaybe "" name + , Types._domainProvider = Types.ProviderAws + } + + -- * Data Definitions