示例#1
0
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonRoute53Config config = new AmazonRoute53Config();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonRoute53Client client = new AmazonRoute53Client(creds, config);

            ListQueryLoggingConfigsResponse resp = new ListQueryLoggingConfigsResponse();

            do
            {
                ListQueryLoggingConfigsRequest req = new ListQueryLoggingConfigsRequest
                {
                    NextToken = resp.NextToken
                    ,
                    MaxResults = maxItems.ToString()
                };

                resp = client.ListQueryLoggingConfigs(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.QueryLoggingConfigs)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
示例#2
0
        // public string DnsRecordName { get; set; }

        // public string DnsRecordType { get; set; }

        // public string DnsRecordValue { get; set; }

        /// <summary>
        /// Returns all records up to 100 at a time, starting with the
        /// one with the optional name and/or type, sorted in lexical
        /// order by name (with labels reversed) then by type.
        /// </summary>
        public async Task <ListResourceRecordSetsResponse> GetRecords(
            string startingDnsName, string startingDnsType = null)
        {
#pragma warning disable 618 // "'StoredProfileCredentials' is obsolete..."
            var crd = StoredProfileCredentials.GetProfile(AwsProfileName);
#pragma warning restore 618
            var cfg = new AmazonRoute53Config
            {
                RegionEndpoint = RegionEndpoint.USEast1,
            };

            var reg = RegionEndpoint.GetBySystemName(AwsRegion);
            using (var r53 = new Amazon.Route53.AmazonRoute53Client(crd, cfg))
            {
                var rrRequ = new Amazon.Route53.Model.ListResourceRecordSetsRequest
                {
                    HostedZoneId    = HostedZoneId,
                    StartRecordName = startingDnsName,
                    StartRecordType = startingDnsType,
                };

                var rrResp = await r53.ListResourceRecordSetsAsync(rrRequ);

                return(rrResp);
            }
        }
示例#3
0
        public override IAmazonRoute53 CreateRoute53Client()
        {
            var config = new AmazonRoute53Config()
            {
                RegionEndpoint = AWSRegion
            };

            return(new AmazonRoute53Client(Credentials, config));
        }
示例#4
0
        public AmazonRoute53Client GetAmazonRoute53Client()
        {
            AmazonRoute53Config config = new AmazonRoute53Config()
            {
                RegionEndpoint = RegionEndpoint.GetBySystemName(Settings.AWSRegion) // TODO: inject
            };

            AmazonRoute53Client route53Client = new AmazonRoute53Client(Settings.AWSAccessKeyId, Settings.AWSAccessKeySecret, config);

            return(route53Client);
        }
示例#5
0
        protected IAmazonRoute53 CreateClient(AWSCredentials credentials, RegionEndpoint region)
        {
            var config = new AmazonRoute53Config {
                RegionEndpoint = region
            };

            Amazon.PowerShell.Utils.Common.PopulateConfig(this, config);
            this.CustomizeClientConfig(config);
            var client = new AmazonRoute53Client(credentials, config);

            client.BeforeRequestEvent += RequestEventHandler;
            client.AfterResponseEvent += ResponseEventHandler;
            return(client);
        }
示例#6
0
        private async static Task <string> GetHostedZoneIdByName(string hostedZoneName)
        {
            AmazonRoute53Config config = new AmazonRoute53Config()
            {
                RegionEndpoint = RegionEndpoint.GetBySystemName(Settings.AWSRegion) // TODO: inject
            };

            using (AmazonRoute53Client route53Client = new AmazonRoute53Client(Settings.AWSAccessKeyId, Settings.AWSAccessKeySecret, config))
            {
                ListHostedZonesByNameResponse zones = await route53Client.ListHostedZonesByNameAsync(new ListHostedZonesByNameRequest()
                {
                    DNSName = hostedZoneName
                });

                HostedZone matchingZone = zones?.HostedZones.FirstOrDefault(zone => zone.Name == hostedZoneName);
                return(matchingZone?.Id);
            }
        }
示例#7
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);
        }
示例#8
0
        private async static Task <bool> UpdateIpAddressForSubdomain(string hostedZoneId, string fqdn, string newIpAddress)
        {
            AmazonRoute53Config config = new AmazonRoute53Config()
            {
                RegionEndpoint = RegionEndpoint.GetBySystemName(Settings.AWSRegion) // TODO: inject
            };

            using (AmazonRoute53Client route53Client = new AmazonRoute53Client(Settings.AWSAccessKeyId, Settings.AWSAccessKeySecret, config))
            {
                ListResourceRecordSetsResponse records = await route53Client.ListResourceRecordSetsAsync(new ListResourceRecordSetsRequest(hostedZoneId));

                ResourceRecordSet matchingRecordSet = records?.ResourceRecordSets.FirstOrDefault(prop => prop.Name == fqdn && prop.Type == RRType.A);

                if (matchingRecordSet != null && matchingRecordSet.ResourceRecords.FirstOrDefault() != null)
                {
                    if (matchingRecordSet.ResourceRecords.FirstOrDefault().Value != newIpAddress)
                    {
                        matchingRecordSet.ResourceRecords.FirstOrDefault().Value = newIpAddress;
                        ChangeBatch change = new ChangeBatch();
                        change.Changes.Add(new Change(ChangeAction.UPSERT, matchingRecordSet));

                        ChangeResourceRecordSetsResponse changeRequest = await route53Client.ChangeResourceRecordSetsAsync(new ChangeResourceRecordSetsRequest(hostedZoneId, change));

                        Log.Information("[Runtime = {StartTime}] Change request submitted to change subdomain {Subdomain} IP address to {IPAddress}.", startTime, fqdn, newIpAddress);

                        return(changeRequest.HttpStatusCode == System.Net.HttpStatusCode.OK);
                    }
                    else
                    {
                        Log.Information("[Runtime = {StartTime}] Subdomain {Subdomain} found, but the IP address was already {IPAddress}.", startTime, fqdn, newIpAddress);
                    }
                }
                else
                {
                    // New subdomain
                    Log.Information("[Runtime = {StartTime}] Subdomain {Subdomain} record not found.", startTime, fqdn);
                }

                return(false);
            }
        }