Skip to content

Commit

Permalink
Merge pull request #52 from vst/44-list-domains-managed-on-aws-route53
Browse files Browse the repository at this point in the history
feat: list domains managed on AWS Route53
  • Loading branch information
vst authored May 13, 2024
2 parents 08c6bb5 + 2e95c66 commit d4c8a9e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ library:
- amazonka-core
- amazonka-ec2
- amazonka-lightsail
- amazonka-route53
- amazonka-s3
- async-pool
- autodocodec
Expand Down
8 changes: 6 additions & 2 deletions src/Clompse/Programs/ListDomains.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/Clompse/Providers/Aws.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..))
Expand Down
21 changes: 21 additions & 0 deletions src/Clompse/Providers/Aws/ApiAws.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit d4c8a9e

Please sign in to comment.