public DynDns53ConsoleClient(IConfigHandler configHandler, IAmazonRoute53 route53Client, IHeartbeatService heartbeatService, ILog logger)
 {
     this.configHandler    = configHandler;
     this.route53Client    = route53Client;
     this.heartbeatService = heartbeatService;
     this.logger           = logger;
 }
示例#2
0
        /// <summary>
        /// Constructs an instance with a preconfigured S3 client. This can be used for testing
        /// the outside of the Lambda environment.
        /// </summary>
        /// <param name="s3"></param>
        public Function(IAmazonEC2 ec2, IAmazonRoute53 r53, IAmazonS3 s3)
        {
            _ec2 = ec2;
            _r53 = r53;
            _s3  = s3;

            Setup();
        }
示例#3
0
 public DnsUpdaterTestPad(IConfigHandler configHandler, 
     IIpChecker ipchecker,
     IAmazonRoute53 amazonClient)
 {
     _configHandler = configHandler;
     _ipChecker = ipchecker;
     _amazonClient = amazonClient;
 }
示例#4
0
 public R53Trigger(ILogger <R53Trigger> logger, IAmazonRoute53 r53, IAmazonS3 s3,
                   EC2Evaluator ec2Eval)
 {
     _logger  = logger;
     _r53     = r53;
     _s3      = s3;
     _ec2Eval = ec2Eval;
 }
示例#5
0
        public static ListHostedZonesResponse GetHostedZones(IAmazonRoute53 r53Client)
        {
            var request = new ListHostedZonesRequest {
                MaxItems = "100"
            };
            var response = r53Client.ListHostedZones(request);

            return(response);
        }
示例#6
0
 public Route53(LookupClientProvider dnsClient, ILogService log, Route53Options options, string identifier)
     : base(dnsClient, log, options, identifier)
 {
     _route53Client = !string.IsNullOrWhiteSpace(options.IAMRole)
         ? new AmazonRoute53Client(new InstanceProfileAWSCredentials(options.IAMRole))
         : !string.IsNullOrWhiteSpace(options.AccessKeyId) && !string.IsNullOrWhiteSpace(options.SecretAccessKey)
             ? new AmazonRoute53Client(options.AccessKeyId, options.SecretAccessKey)
             : new AmazonRoute53Client();
 }
示例#7
0
        public Route53(LookupClientProvider dnsClient, ILogService log, Route53Options options, string identifier)
            : base(dnsClient, log, options, identifier)
        {
            var region = RegionEndpoint.USEast1;

            _route53Client = !string.IsNullOrWhiteSpace(options.IAMRole)
                ? new AmazonRoute53Client(new InstanceProfileAWSCredentials(options.IAMRole), region)
                : !string.IsNullOrWhiteSpace(options.AccessKeyId) && !string.IsNullOrWhiteSpace(options.SecretAccessKey.Value)
                    ? new AmazonRoute53Client(options.AccessKeyId, options.SecretAccessKey.Value, region)
                    : new AmazonRoute53Client(region);
        }
示例#8
0
        public static ListResourceRecordSetsResponse GetResourceRecordSets(IAmazonRoute53 r53Client)
        {
            var request = new ListResourceRecordSetsRequest
            {
                HostedZoneId    = Zoneid,
                StartRecordName = Fqdn,
                StartRecordType = "A",
                MaxItems        = "100"
            };
            var response = r53Client.ListResourceRecordSets(request);

            return(response);
        }
示例#9
0
        private static void CreateHostedZone(IAmazonRoute53 r53Client, string domainName)
        {
            var zoneRequest = new CreateHostedZoneRequest
            {
                Name            = domainName,
                CallerReference = "testingss"
            };

            var zoneResponse = r53Client.CreateHostedZone(zoneRequest);
            var recordSet    = new ResourceRecordSet
            {
                Name            = domainName,
                TTL             = 60,
                Type            = RRType.A,
                ResourceRecords = new List <ResourceRecord> {
                    new ResourceRecord {
                        Value = IpAddress
                    }
                }
            };

            var change1 = new Change
            {
                ResourceRecordSet = recordSet,
                Action            = ChangeAction.CREATE
            };

            var changeBatch = new ChangeBatch
            {
                Changes = new List <Change> {
                    change1
                }
            };

            var recordsetRequest = new ChangeResourceRecordSetsRequest
            {
                HostedZoneId = zoneResponse.HostedZone.Id,
                ChangeBatch  = changeBatch
            };

            var recordsetResponse = r53Client.ChangeResourceRecordSets(recordsetRequest);
            var changeRequest     = new GetChangeRequest
            {
                Id = recordsetResponse.ChangeInfo.Id
            };

            Console.WriteLine(changeRequest);
        }
示例#10
0
        public Route53(
            LookupClientProvider dnsClient,
            DomainParseService domainParser,
            ILogService log,
            ISettingsService settings,
            Route53Options options)
            : base(dnsClient, log, settings)
        {
            var region = RegionEndpoint.USEast1;

            _route53Client = !string.IsNullOrWhiteSpace(options.IAMRole)
                ? new AmazonRoute53Client(new InstanceProfileAWSCredentials(options.IAMRole), region)
                : !string.IsNullOrWhiteSpace(options.AccessKeyId) && !string.IsNullOrWhiteSpace(options.SecretAccessKey.Value)
                    ? new AmazonRoute53Client(options.AccessKeyId, options.SecretAccessKey.Value, region)
                    : new AmazonRoute53Client(region);
            _domainParser = domainParser;
        }
示例#11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="route53Client"></param>
        /// <param name="hostedZoneId"></param>
        /// <returns></returns>
        internal static IEnumerable<ResourceRecordSet> ListResourceRecordSets(IAmazonRoute53 route53Client, string hostedZoneId)
        {
            var allResourceRecords = new List<ResourceRecordSet>();
            var response = route53Client.ListResourceRecordSets(new ListResourceRecordSetsRequest { HostedZoneId = hostedZoneId }); // , MaxItems = "1"

            while (true)
            {
                allResourceRecords.AddRange(response.ResourceRecordSets);

                if (response.IsTruncated == false)
                {
                    return allResourceRecords;
                }

                // make a request for the next chunk of data
                response = route53Client.ListResourceRecordSets(new ListResourceRecordSetsRequest { HostedZoneId = hostedZoneId, StartRecordName = response.NextRecordName });
            }
        }
示例#12
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="route53Client"></param>
        /// <returns></returns>
        internal static IEnumerable<HostedZone> ListHostedZones(IAmazonRoute53 route53Client)
        {
            var allHostedZones = new List<HostedZone>();
            var response = route53Client.ListHostedZones();

            while (true)
            {
                allHostedZones.AddRange(response.HostedZones);

                if (response.NextMarker == null)
                {
                    return allHostedZones;
                }

                // make a request for the next chunk of data
                response = route53Client.ListHostedZones(new ListHostedZonesRequest { Marker = response.NextMarker });
            }
        }
示例#13
0
        public Route53(
            LookupClientProvider dnsClient,
            ILogService log,
            ProxyService proxy,
            ISettingsService settings,
            Route53Options options) : base(dnsClient, log, settings)
        {
            var region = RegionEndpoint.USEast1;
            var config = new AmazonRoute53Config()
            {
                RegionEndpoint = region
            };

            config.SetWebProxy(proxy.GetWebProxy());
            _route53Client = !string.IsNullOrWhiteSpace(options.IAMRole)
                ? new AmazonRoute53Client(new InstanceProfileAWSCredentials(options.IAMRole), config)
                : !string.IsNullOrWhiteSpace(options.AccessKeyId) && !string.IsNullOrWhiteSpace(options.SecretAccessKey.Value)
                    ? new AmazonRoute53Client(options.AccessKeyId, options.SecretAccessKey.Value, config)
                    : new AmazonRoute53Client(config);
        }
示例#14
0
 private Amazon.Route53.Model.GetHostedZoneResponse CallAWSServiceOperation(IAmazonRoute53 client, Amazon.Route53.Model.GetHostedZoneRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Route 53", "GetHostedZone");
     try
     {
         #if DESKTOP
         return(client.GetHostedZone(request));
         #elif CORECLR
         return(client.GetHostedZoneAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }
示例#15
0
        private static void CreateRecordSet(IAmazonRoute53 r53Client)
        {
            var objRecord = new ResourceRecord {
                Value = "Your IP Address"
            };

            var objRecordSet = new ResourceRecordSet
            {
                Name = Fqdn,
                Type = "A",
                TTL  = 300
            };

            objRecordSet.ResourceRecords.Add(objRecord);

            var objChange = new Change
            {
                Action            = ChangeAction.UPSERT,
                ResourceRecordSet = objRecordSet
            };

            var objChangeList = new List <Change> {
                objChange
            };

            var objChangeBatch = new ChangeBatch {
                Changes = objChangeList
            };

            var objRequest = new ChangeResourceRecordSetsRequest
            {
                HostedZoneId = Zoneid,
                ChangeBatch  = objChangeBatch
            };

            r53Client.ChangeResourceRecordSets(objRequest);
        }
示例#16
0
 internal Route53PaginatorFactory(IAmazonRoute53 client)
 {
     this.client = client;
 }
示例#17
0
 public DnsService(IAmazonRoute53 route53Client)
 {
     _route53Client = route53Client;
 }
示例#18
0
 internal ListHealthChecksPaginator(IAmazonRoute53 client, ListHealthChecksRequest request)
 {
     this._client  = client;
     this._request = request;
 }
 public AwsDnsChallengePersistenceStrategy(AwsOptions awsOptions, ILogger <AwsDnsChallengePersistenceStrategy> logger) : base(logger)
 {
     _awsOptions    = awsOptions;
     _route53Client = new AmazonRoute53Client(awsOptions.Credentials, awsOptions.Region);
     _logger        = logger;
 }
 // This dependency-injected instance is populated from config
 public Route53Updater(IAmazonRoute53 amazonRoute53)
 {
     this.route53Client = amazonRoute53;
 }
 internal ListResourceRecordSetsPaginator(IAmazonRoute53 client, ListResourceRecordSetsRequest request)
 {
     this._client  = client;
     this._request = request;
 }
示例#22
0
 // TODO: Move this injection to where it's actually needed
 public Updater(IAmazonRoute53 amazonRoute53)
 {
     _route53Updater = new Route53Updater(amazonRoute53);
 }
 internal ListQueryLoggingConfigsPaginator(IAmazonRoute53 client, ListQueryLoggingConfigsRequest request)
 {
     this._client  = client;
     this._request = request;
 }
示例#24
0
 public RouteHandler(IAmazonRoute53 route53Client)
 {
     _route53Client = route53Client;
 }
示例#25
0
 public UpdateDnsFunction()
 {
     _amazonEc2Client     = new AmazonEC2Client();
     _amazonRoute53Client = new AmazonRoute53Client();
 }
示例#26
0
 public UpdateDnsFunction(IAmazonEC2 ec2Client, IAmazonRoute53 route53Client)
 {
     _amazonEc2Client     = ec2Client;
     _amazonRoute53Client = route53Client;
 }
示例#27
0
 public DnsUpdater(IAmazonRoute53 amazonClient)
 {
     this.amazonClient = amazonClient;
 }
        public async Task <Response> Delete()
        {
            var props = Request.ResourceProperties;
            IAmazonCertificateManager acmClient = await acmFactory.Create(props.CreationRoleArn);

            IAmazonRoute53 route53Client = await route53Factory.Create(props.ValidationRoleArn);

            var describeResponse = await acmClient.DescribeCertificateAsync(new DescribeCertificateRequest
            {
                CertificateArn = Request.PhysicalResourceId,
            });

            Console.WriteLine($"Got describe certificate response: {JsonSerializer.Serialize(describeResponse)}");

            var names   = new HashSet <string>();
            var changes = new List <Change>();

            foreach (var option in describeResponse.Certificate.DomainValidationOptions)
            {
                var query = from name in names where name == option.ResourceRecord.Name select name;

                if (query.Count() != 0)
                {
                    continue;
                }

                names.Add(option.ResourceRecord.Name);
                changes.Add(new Change
                {
                    Action            = ChangeAction.DELETE,
                    ResourceRecordSet = new ResourceRecordSet
                    {
                        Name            = option.ResourceRecord.Name,
                        Type            = new RRType(option.ResourceRecord.Type.Value),
                        SetIdentifier   = Request.PhysicalResourceId,
                        Weight          = 1,
                        TTL             = 60,
                        ResourceRecords = new List <ResourceRecord> {
                            new ResourceRecord {
                                Value = option.ResourceRecord.Value
                            }
                        }
                    }
                });
            }

            if (changes.Count() != 0)
            {
                try
                {
                    var roleArn = Request.ResourceProperties.ValidationRoleArn;
                    var changeRecordsResponse = await route53Client.ChangeResourceRecordSetsAsync(new ChangeResourceRecordSetsRequest
                    {
                        HostedZoneId = Request.ResourceProperties.HostedZoneId,
                        ChangeBatch  = new ChangeBatch
                        {
                            Changes = changes
                        }
                    });

                    Console.WriteLine($"Got delete record response: {JsonSerializer.Serialize(changeRecordsResponse)}");
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Error deleting old resource records: {e.Message} {e.StackTrace}");
                }
            }

            var deleteResponse = await acmClient.DeleteCertificateAsync(new DeleteCertificateRequest
            {
                CertificateArn = Request.PhysicalResourceId,
            });

            Console.WriteLine($"Received delete certificate response: {JsonSerializer.Serialize(deleteResponse)}");

            return(new Response
            {
                PhysicalResourceId = Request.PhysicalResourceId
            });
        }
示例#29
0
 public DnsService(IAmazonRoute53 route53Client)
 {
     _route53Client = route53Client;
 }
 internal ListHostedZonesPaginator(IAmazonRoute53 client, ListHostedZonesRequest request)
 {
     this._client  = client;
     this._request = request;
 }
        public async Task <Response?> Create()
        {
            var props = Request.ResourceProperties;

            IAmazonCertificateManager acmClient = await acmFactory.Create(props.CreationRoleArn);

            IAmazonRoute53 route53Client = await route53Factory.Create(props.ValidationRoleArn);

            var request = new RequestCertificateRequest
            {
                DomainName       = props.DomainName,
                ValidationMethod = props.ValidationMethod
            };

            if (props.CertificateAuthorityArn != null)
            {
                request.CertificateAuthorityArn = props.CertificateAuthorityArn;
            }
            if (props.DomainValidationOptions != null)
            {
                request.DomainValidationOptions = props.DomainValidationOptions;
            }
            if (props.Options != null)
            {
                request.Options = props.Options;
            }
            if (props.SubjectAlternativeNames != null)
            {
                request.SubjectAlternativeNames = props.SubjectAlternativeNames;
            }

            var requestCertificateResponse = await acmClient.RequestCertificateAsync(request);

            Console.WriteLine($"Got Request Certificate Response: {JsonSerializer.Serialize(requestCertificateResponse)}");

            PhysicalResourceId = requestCertificateResponse.CertificateArn;
            var describeCertificateRequest = new DescribeCertificateRequest {
                CertificateArn = PhysicalResourceId
            };
            var tasks = new List <Task>();

            Thread.Sleep(500);
            bool foundValidationOptions = false;
            List <DomainValidation> validationOptions = new List <DomainValidation>();

            // For some reason, the domain validation options aren't immediately populated.
            while (!foundValidationOptions)
            {
                var describeCertificateResponse = await acmClient.DescribeCertificateAsync(describeCertificateRequest);

                Console.WriteLine($"Got Describe Certificate Response: {JsonSerializer.Serialize(describeCertificateResponse)}");

                validationOptions      = describeCertificateResponse.Certificate.DomainValidationOptions;
                foundValidationOptions = true;

                if (validationOptions.Count() == 0)
                {
                    foundValidationOptions = false;
                }

                foreach (var option in validationOptions)
                {
                    if (option.ResourceRecord?.Name == null)
                    {
                        foundValidationOptions = false;
                    }
                }

                Thread.Sleep(1000);
            }

            if (props.Tags != null)
            {
                tasks.Add(Task.Run(async delegate
                {
                    var addTagsResponse = await acmClient.AddTagsToCertificateAsync(new AddTagsToCertificateRequest
                    {
                        Tags           = props.Tags,
                        CertificateArn = PhysicalResourceId,
                    });

                    Console.WriteLine($"Got Add Tags Response: {JsonSerializer.Serialize(addTagsResponse)}");
                }));
            }

            // add DNS validation records if applicable
            var names   = new HashSet <string>();
            var changes = new List <Change>();

            if (props.ValidationMethod == ValidationMethod.DNS)
            {
                foreach (var option in validationOptions)
                {
                    var query = from name in names where name == option.ResourceRecord.Name select name;

                    if (query.Count() != 0)
                    {
                        continue;
                    }

                    names.Add(option.ResourceRecord.Name);
                    changes.Add(new Change
                    {
                        Action            = ChangeAction.UPSERT,
                        ResourceRecordSet = new ResourceRecordSet
                        {
                            Name            = option.ResourceRecord.Name,
                            Type            = new RRType(option.ResourceRecord.Type.Value),
                            SetIdentifier   = PhysicalResourceId,
                            Weight          = 1,
                            TTL             = 60,
                            ResourceRecords = new List <ResourceRecord> {
                                new ResourceRecord {
                                    Value = option.ResourceRecord.Value
                                }
                            }
                        }
                    });
                }

                tasks.Add(
                    Task.Run(async delegate
                {
                    var changeRecordsResponse = await route53Client.ChangeResourceRecordSetsAsync(new ChangeResourceRecordSetsRequest
                    {
                        HostedZoneId = props.HostedZoneId,
                        ChangeBatch  = new ChangeBatch
                        {
                            Changes = changes
                        }
                    });

                    Console.WriteLine($"Got Change Record Sets Response: {JsonSerializer.Serialize(changeRecordsResponse)}");
                })
                    );
            }

            Task.WaitAll(tasks.ToArray());

            Request.PhysicalResourceId = PhysicalResourceId;
            Request.RequestType        = RequestType.Wait;

            return(await Wait());
        }
 // TODO: Move this injection to where it's actually needed
 public DynDnsController(IAmazonRoute53 amazonRoute53)
 {
     _updater = new Updater(amazonRoute53);
 }