Наследование: AmazonWebServiceClient, AmazonRoute53
Пример #1
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);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            IConfigHandler _configHandler = new AppConfigHandler();
            var config = _configHandler.GetConfig();
            IIpChecker _ipChecker = new AwsIpChecker();
            IAmazonRoute53 _amazonClient = new AmazonRoute53Client(config.Route53AccessKey, config.Route53SecretKey, RegionEndpoint.EUWest1);
            var dnsUpdater = new DnsUpdater(_configHandler, _ipChecker, _amazonClient);

            HostFactory.Run(x =>
            {
                x.Service<IScheduledTaskService>(s =>
                {
                    s.ConstructUsing(name => new DnsUpdateService(new SchedulerRegistry(new ScheduledTaskWorker(dnsUpdater))));
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });

                x.RunAsLocalSystem();

                x.SetDisplayName("DynDns53 Service");
                x.SetServiceName("DynDns53");
                x.SetDescription("Updates AWS Route53 records with the current external IP of the system");

                x.StartAutomatically();

                x.EnableServiceRecovery(s =>
                {
                    s.RestartService(1);
                    s.RestartService(2);
                    s.RestartService(5);
                });
            });
        }
Пример #3
0
        public async Task EditR53Record(Amazon.Route53.Model.ResourceRecordSet rrSet,
                                        bool delete = false)
        {
#pragma warning disable 618 // "'StoredProfileCredentials' is obsolete..."
            //var creds = new BasicAWSCredentials(AwsAccessKey, AwsSecretKey);
            var creds = new StoredProfileAWSCredentials("acmesharp-tests");
#pragma warning restore 618
            var reg = RegionEndpoint.GetBySystemName(AwsRegion);
            using (var r53 = new Amazon.Route53.AmazonRoute53Client(creds, reg))
            {
                var rrRequ = new Amazon.Route53.Model.ChangeResourceRecordSetsRequest
                {
                    HostedZoneId = HostedZoneId,
                    ChangeBatch  = new Amazon.Route53.Model.ChangeBatch
                    {
                        Changes = new List <Amazon.Route53.Model.Change>
                        {
                            new Amazon.Route53.Model.Change
                            {
                                Action = delete
                                    ? Amazon.Route53.ChangeAction.DELETE
                                    : Amazon.Route53.ChangeAction.UPSERT,
                                ResourceRecordSet = rrSet
                            }
                        }
                    }
                };

                var rrResp = await r53.ChangeResourceRecordSetsAsync(rrRequ);
            }
        }
Пример #4
0
    public static void Route53CreateAdd(string[] args)
    {
      #region Route53CreateAdd
      string domainName = "www.example.org";

      IAmazonRoute53 route53Client = new AmazonRoute53Client();

      CreateHostedZoneRequest zoneRequest = new CreateHostedZoneRequest
      {
        Name = domainName,
        CallerReference = "my_change_request"
      };

      CreateHostedZoneResponse zoneResponse = route53Client.CreateHostedZone(zoneRequest);

      ResourceRecordSet recordSet = new ResourceRecordSet
      {
        Name = domainName,
        TTL = 60,
        Type = RRType.A,
        ResourceRecords = new List<ResourceRecord> { new ResourceRecord { Value = "192.0.2.235" } }
      };

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

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

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

      ChangeResourceRecordSetsResponse recordsetResponse = route53Client.ChangeResourceRecordSets(recordsetRequest);

      GetChangeRequest changeRequest = new GetChangeRequest
      {
        Id = recordsetResponse.ChangeInfo.Id
      };

      while (route53Client.GetChange(changeRequest).ChangeInfo.Status == ChangeStatus.PENDING)
      {
        Console.WriteLine("Change is pending.");
        Thread.Sleep(TimeSpan.FromSeconds(15));
      }
      #endregion

      Console.WriteLine("Change is complete.");
      Console.ReadKey();
    }
Пример #5
0
        public async Task<long> AsyncMethod()
        {
            IConfigHandler _configHandler = new AppConfigHandler();
            var config = _configHandler.GetConfig();

            IAmazonRoute53 _amazonClient = new AmazonRoute53Client(config.Route53AccessKey, config.Route53SecretKey, RegionEndpoint.EUWest1);
            var request = new GetHealthCheckCountRequest() { };
            var response = await _amazonClient.GetHealthCheckCountAsync(request);

            return response.HealthCheckCount;
        }
Пример #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="profileName"></param>
        static void ExportRoute53Data(string profileName)
        {
            try
            {
                var assemblyName = Assembly.GetExecutingAssembly().GetName().Name;
                var currentTime = DateTime.Now.ToString("yyyyMMdd.HHmmss");
                var fileName = string.Format("{0}-{1}.txt", assemblyName, currentTime);
                var exportPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);

                // create Eoute53 client
                var route53Client = new AmazonRoute53Client(ProfileManager.GetAWSCredentials(profileName), RegionEndpoint.EUWest1);

                using (var writer = File.AppendText(exportPath))
                {
                    try
                    {
                        var zones = Route53.ListHostedZones(route53Client).OrderBy(x => x.Name);

                        // update user
                        Cmd.WriteLine("Exporting {0} zones from \"{1}\" to {2}\n", zones.Count(), profileName, exportPath);

                        // itterate zones
                        foreach (var zone in zones)
                        {
                            // enum all records in zone
                            var records = Route53.ListResourceRecordSets(route53Client, zone.Id).OrderBy(x => x.Name);

                            // export to file
                            Log.Write(writer, "{0}", zone.Name);
                            
                            foreach (var recordSet in records)
                            {
                                // update user
                                Cmd.WriteInPlace("Exporting zone: {0,-64} ({1} records ... {2})", zone.Name, records.Count(), recordSet.Name.EscapeSpecialCharacters());

                                // todo unused fields ...
                                // recordSet.Weight, 
                                // recordSet.AliasTarget, 
                                // recordSet.Failover, 
                                // recordSet.GeoLocation, 
                                // recordSet.HealthCheckId, 
                                // recordSet.Region, 
                                // recordSet.SetIdentifier

                                // export to file
                                Log.Write(writer, "  {0,-70} TTL={1,-6} Type={2,-8} {3}",
                                    recordSet.Name.EscapeSpecialCharacters(),
                                    recordSet.TTL,
                                    recordSet.Type,
                                    string.Join(" ", recordSet.ResourceRecords.Select(n => n.Value).ToArray()));
                            }

                            // update the user
                            Cmd.WriteInPlace("Exporting zone: {0,-64} ({1} records)", zone.Name, records.Count());
                            Cmd.WriteLine();

                            // export to file
                            Log.Write(writer, "\n");
                        }
                    }
                    catch (AmazonRoute53Exception arex)
                    {
                        Cmd.WriteLine(Cmd.Red, "{0}", arex);
                        Log.Write(writer, arex.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Cmd.WriteLine(Cmd.Red, "{0}", ex);
            }
        }
 public DefaultRoute53Client(string awsAccessKey, string awsSecretKey, string region)
 {
     logger.Info("Creating Route53 client");
     client = new AmazonRoute53Client(awsAccessKey, awsSecretKey, Amazon.RegionEndpoint.GetBySystemName(region));
 }
 public Route53Client(string awsAccessKeyId, string awsSecretAccessKey)
 {
     client = new AmazonRoute53Client(awsAccessKeyId, awsSecretAccessKey);
 }
Пример #9
0
        private void InitConfig()
        {
            AddLog("Loading configuration values...");

            // _configHandler = new AppConfigHandler();
            _configHandler = new JsonConfigHandler();
            var config = _configHandler.GetConfig();
            _ipChecker = new AwsIpChecker();
            IAmazonRoute53 _amazonClient = new AmazonRoute53Client(config.Route53AccessKey, config.Route53SecretKey, RegionEndpoint.EUWest1);
            _dnsUpdater = new DnsUpdater(_configHandler, _ipChecker, _amazonClient);

            AddLog($"Found {config.DomainList.Count} domain(s)");
            foreach (HostedDomainInfo domainInfo in config.DomainList)
            {
                AddLog($"{domainInfo.DomainName}");
            }

            if (_timer != null)
            {
                // Stop to avoid multiple timer_Tick invocations
                _timer.Stop();
            }

            int interval = config.UpdateInterval;
            _timer = new System.Windows.Threading.DispatcherTimer();
            _timer.Tick += timer_Tick;
            _timer.Interval = new TimeSpan(0, interval, 0);
            _timer.Start();

            AddLog($"Time set to update domains every {interval} minutes");

            SetAutoStart();
        }
Пример #10
0
 public DefaultRoute53Client(string awsAccessKey, string awsSecretKey)
 {
     logger.Info("Creating Route53 client");
     client = new AmazonRoute53Client(awsAccessKey, awsSecretKey);
 }