Information about the resource record set to create or delete.
Ejemplo n.º 1
0
 public void EditR53Record(Amazon.Route53.Model.ResourceRecordSet rrset, bool delete = false)
 {
     using (var r53 = new Amazon.Route53.AmazonRoute53Client(
                CommonParams.ResolveCredentials(),
                CommonParams.RegionEndpoint))
     {
         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 = r53.ChangeResourceRecordSets(rrRequ);
     }
 }
Ejemplo n.º 2
0
        private List<ResourceRecordSet> DefaultRecordSets(
            string domainName,
            string primaryIp,
            string secondaryIp,
            string healthCheckId,
            string setIdPrefix
            )
        {
            var primaryRecordSet = new ResourceRecordSet()
                .WithName(domainName)
                .WithType("A")
                .WithTTL(30)
                .WithResourceRecords(
                    new ResourceRecord().WithValue(primaryIp)
                )
                .WithHealthCheckId(healthCheckId)
                .WithFailover("PRIMARY")
                .WithSetIdentifier(setIdPrefix + "-primary");

            var secondaryRecordSet = new ResourceRecordSet()
                .WithName(domainName)
                .WithType("A")
                .WithTTL(30)
                .WithResourceRecords(
                    new ResourceRecord().WithValue(secondaryIp)
                )
                .WithFailover("SECONARY")
                .WithSetIdentifier(setIdPrefix + "-secondary");

            return new List<ResourceRecordSet> {
                primaryRecordSet,
                secondaryRecordSet
            };
        }
Ejemplo n.º 3
0
 public DlgEditDnsRecord(ZAwsEc2Controller controller, ResourceRecordSet records)
 {
     InitializeComponent();
     MyController = controller;
     MyRecords = records;
     comboBoxRecordType.SelectedIndex = 0;
 }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
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();
    }
Ejemplo n.º 6
0
        public ChangeResourceRecordSetsResponse updateRRSet(string hostedZoneId, ResourceRecordSet oldRRset, ResourceRecordSet newRRset)
        {
            logger.Info("Calling ChangeResourceRecordSets");
            List<Change> changes = new List<Change>() {
                new Change().WithAction(Action.DELETE.ToString()).WithResourceRecordSet(oldRRset),
                new Change().WithAction(Action.CREATE.ToString()).WithResourceRecordSet(newRRset)
            };

            ChangeBatch batch = new ChangeBatch().WithChanges(changes.ToArray());
            return client.ChangeResourceRecordSets(new ChangeResourceRecordSetsRequest()
                                                        .WithHostedZoneId(hostedZoneId)
                                                        .WithChangeBatch(batch));
        }
Ejemplo n.º 7
0
        public void EditCnameRecord(string dnsName, string dnsValue, bool delete = false)
        {
            var rrset = new Amazon.Route53.Model.ResourceRecordSet
            {
                TTL             = ResourceRecordTtl,
                Name            = dnsName,
                Type            = Amazon.Route53.RRType.CNAME,
                ResourceRecords = new List <Amazon.Route53.Model.ResourceRecord>
                {
                    new Amazon.Route53.Model.ResourceRecord(dnsValue)
                }
            };

            EditR53Record(rrset);
        }
Ejemplo n.º 8
0
        public void EditARecord(string dnsName, string dnsValue, bool delete = false)
        {
            var rrset = new Amazon.Route53.Model.ResourceRecordSet
            {
                TTL = ResourceRecordTtl,
                Name = dnsName,
                Type = Amazon.Route53.RRType.A,
                ResourceRecords = new List<Amazon.Route53.Model.ResourceRecord>
                {
                    new Amazon.Route53.Model.ResourceRecord(dnsValue)
                }
            };

            EditR53Record(rrset);
        }
Ejemplo n.º 9
0
        public async Task EditARecord(string dnsName, string dnsValue, bool delete = false)
        {
            var rrSet = new Amazon.Route53.Model.ResourceRecordSet
            {
                TTL             = DefaultRecordTtl,
                Name            = dnsName,
                Type            = Amazon.Route53.RRType.A,
                ResourceRecords = new List <Amazon.Route53.Model.ResourceRecord>
                {
                    new Amazon.Route53.Model.ResourceRecord(dnsValue)
                }
            };

            await EditR53Record(rrSet);
        }
Ejemplo n.º 10
0
        public void EditTxtRecord(string dnsName, IEnumerable <string> dnsValues, bool delete = false)
        {
            var dnsValuesJoined = string.Join("\" \"", dnsValues);
            var rrset           = new Amazon.Route53.Model.ResourceRecordSet
            {
                TTL             = ResourceRecordTtl,
                Name            = dnsName,
                Type            = Amazon.Route53.RRType.TXT,
                ResourceRecords = new List <Amazon.Route53.Model.ResourceRecord>
                {
                    new Amazon.Route53.Model.ResourceRecord(
                        $"\"{dnsValuesJoined}\"")
                }
            };

            EditR53Record(rrset, delete);
        }
Ejemplo n.º 11
0
        public void EditTxtRecord(string dnsName, IEnumerable<string> dnsValues, bool delete = false)
        {
            var dnsValuesJoined = string.Join("\" \"", dnsValues);
            var rrset = new Amazon.Route53.Model.ResourceRecordSet
            {
                TTL = ResourceRecordTtl,
                Name = dnsName,
                Type = Amazon.Route53.RRType.TXT,
                ResourceRecords = new List<Amazon.Route53.Model.ResourceRecord>
                {
                    new Amazon.Route53.Model.ResourceRecord(
                            $"\"{dnsValuesJoined}\"")
                }
            };

            EditR53Record(rrset, delete);
        }
Ejemplo n.º 12
0
        public ChangeResourceRecordSetsResponse updateRRSet(
            string hostedZoneId, ResourceRecordSet oldRRset, ResourceRecordSet newRRset)
        {
            logger.Info("Calling ChangeResourceRecordSets");
            Change delete = new Change()
            {
                Action = Action.DELETE.ToString(),
                ResourceRecordSet = oldRRset
            };
            Change create = new Change() {
                Action = Action.CREATE.ToString(),
                ResourceRecordSet = newRRset
            };
            List<Change> changes = new List<Change>() { delete, create };

            ChangeBatch batch = new ChangeBatch() { Changes = changes };

            return client.ChangeResourceRecordSets(new ChangeResourceRecordSetsRequest(){
                HostedZoneId = hostedZoneId,
                ChangeBatch = batch
            });
        }
Ejemplo n.º 13
0
        public void EditR53Record(Amazon.Route53.Model.ResourceRecordSet rrset, bool delete = false)
        {
            using (var r53 = new Amazon.Route53.AmazonRoute53Client(
                       CommonParams.ResolveCredentials(),
                       CommonParams.RegionEndpoint))
            {
                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
                            }
                        }
                    }
                };

                LOG.Debug("Submiting R53 action [{0}] to zone [{1}] for record [{2}]",
                          rrRequ.ChangeBatch.Changes[0].Action,
                          rrRequ.HostedZoneId,
                          rrRequ.ChangeBatch.Changes[0].ResourceRecordSet.Name);

                var rrResp = r53.ChangeResourceRecordSets(rrRequ);

                if (LOG.IsDebugEnabled)
                {
                    LOG.Debug("R53 response: [{0}]",
                              NLog.Targets.DefaultJsonSerializer.Instance.SerializeObject(rrResp));
                }
            }
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Instantiates Change with the parameterized properties
 /// </summary>
 /// <param name="action">The action to perform: <ul> <li><code>CREATE</code>: Creates a resource record set that has the specified values.</li> <li><CODE>DELETE</CODE>: Deletes a existing resource record set that has the specified values for <code>Name</code>, <code>Type</code>, <code>SetIdentifier</code> (for latency, weighted, geolocation, and failover resource record sets), and <code>TTL</code> (except alias resource record sets, for which the TTL is determined by the AWS resource that you're routing DNS queries to).</li> <li><code>UPSERT</code>: If a resource record set does not already exist, Amazon Route 53 creates it. If a resource record set does exist, Amazon Route 53 updates it with the values in the request. Amazon Route 53 can update an existing resource record set only when all of the following values match: <code>Name</code>, <code>Type</code>, and <code>SetIdentifier</code> (for weighted, latency, geolocation, and failover resource record sets).</li> </ul></param>
 /// <param name="resourceRecordSet">Information about the resource record set to create or delete.</param>
 public Change(ChangeAction action, ResourceRecordSet resourceRecordSet)
 {
     _action = action;
     _resourceRecordSet = resourceRecordSet;
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Instantiates Change with the parameterized properties
 /// </summary>
 /// <param name="action">The action to perform: <ul> <li><code>CREATE</code>: Creates a resource record set that has the specified values.</li> <li><CODE>DELETE</CODE>: Deletes a existing resource record set that has the specified values for <code>Name</code>, <code>Type</code>, <code>SetIdentifier</code> (for latency, weighted, geolocation, and failover resource record sets), and <code>TTL</code> (except alias resource record sets, for which the TTL is determined by the AWS resource that you're routing DNS queries to).</li> <li><code>UPSERT</code>: If a resource record set does not already exist, Amazon Route 53 creates it. If a resource record set does exist, Amazon Route 53 updates it with the values in the request. Amazon Route 53 can update an existing resource record set only when all of the following values match: <code>Name</code>, <code>Type</code>, and <code>SetIdentifier</code> (for weighted, latency, geolocation, and failover resource record sets).</li> </ul></param>
 /// <param name="resourceRecordSet">Information about the resource record set to create or delete.</param>
 public Change(ChangeAction action, ResourceRecordSet resourceRecordSet)
 {
     _action            = action;
     _resourceRecordSet = resourceRecordSet;
 }
        public void TestExecuteWhenSettingLocalIpAddress()
        {
            var options = new ChangeResourceRecordSets.Options
                          {
                              Host = "sub.domain.com",
                              GetLocalIp = true,
                              Ttl = 300
                          };

            var hostedZone = new HostedZone { Id = "AAAAAAAAA1234" };

            route53ServiceMock
                .Setup(call => call.GetZone("domain.com"))
                .Returns(hostedZone);

            var match = new ResourceRecordSet { Name = "sub.domain.com" };

            var records = new List<ResourceRecordSet> { match };

            route53ServiceMock
                .Setup(call => call.ListResourceRecordSets("AAAAAAAAA1234"))
                .Returns(records);

            route53ServiceMock
                .Setup(call => call.GetLocalIpAddress())
                .Returns("172.16.3.3");

            var result = command.Execute(options);

            route53ServiceMock
                .Verify(call => call.ReplaceResourceRecordSet("AAAAAAAAA1234", match, It.IsAny<ResourceRecordSet>()), Times.Once());

            Assert.AreEqual(0, result);
        }
Ejemplo n.º 17
0
 public Change WithResourceRecordSet(ResourceRecordSet resourceRecordSet)
 {
     this.resourceRecordSet = resourceRecordSet;
     return(this);
 }
Ejemplo n.º 18
0
 public Change WithResourceRecordSet(ResourceRecordSet resourceRecordSet)
 {
     this.resourceRecordSet = resourceRecordSet;
     return this;
 }
Ejemplo n.º 19
0
 internal void DeleteRecord(ResourceRecordSet s)
 {
     ChangeResourceRecordSetsResponse resp =
     myController.route53.ChangeResourceRecordSets(new ChangeResourceRecordSetsRequest()
                                                         .WithHostedZoneId(this.ResponseData.Id)
                                                         .WithChangeBatch(new ChangeBatch()
                                                                             .WithChanges(
                                                                                 new Change()
                                                                                     .WithAction("DELETE")
                                                                                     .WithResourceRecordSet(s))));
     Thread.Sleep(2000);
     UpdateInfo();
 }
Ejemplo n.º 20
0
 internal bool AddRecord(ResourceRecordSet s)
 {
     try
     {
         ChangeResourceRecordSetsResponse resp =
         myController.route53.ChangeResourceRecordSets(new ChangeResourceRecordSetsRequest()
                                                             .WithHostedZoneId(this.ResponseData.Id)
                                                             .WithChangeBatch(new ChangeBatch()
                                                                                 .WithChanges(
                                                                                     new Change()
                                                                                         .WithAction("CREATE")
                                                                                         .WithResourceRecordSet(s))));
         Thread.Sleep(2000);
         UpdateInfo();
         return true;
     }
     catch (Exception ex)
     {
         Program.TraceLine("Failed adding a recordset, reason: ", ex);
         return false;
     }
 }
Ejemplo n.º 21
0
        private List<ResourceRecordSet> MaintenanceRecordSets(string domainName, string ip)
        {
            var primaryRecordSet = new ResourceRecordSet()
                .WithName(domainName)
                .WithType("A")
                .WithTTL(30)
                .WithResourceRecords(
                    new ResourceRecord().WithValue(ip)
                );

            return new List<ResourceRecordSet> {
                primaryRecordSet
            };
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Replaces the resource record set.
        /// </summary>
        /// <param name="hostedZoneId">The hosted zone identifier.</param>
        /// <param name="oldRecord">The old record.</param>
        /// <param name="newRecord">The new record.</param>
        /// <returns></returns>
        public ChangeInfo ReplaceResourceRecordSet(string hostedZoneId, ResourceRecordSet oldRecord, ResourceRecordSet newRecord)
        {
            var changes = new List<Change>
                          {
                              new Change
                              {
                                  Action = ChangeAction.DELETE,
                                  ResourceRecordSet = oldRecord
                              },
                              new Change
                              {
                                  Action = ChangeAction.CREATE,
                                  ResourceRecordSet = newRecord
                              }
                          };

            return SubmitChangeResourceRecordSets(hostedZoneId, changes);
        }
        private ChangeResourceRecordSetsRequest GetChangeResourceRecordSetsRequest(string hostname, string ipAddress, string action, List<HostedZone> zones)
        {
            string domain = DomainName.Parse(hostname).Domain;
            string hostedZoneId = zones.Single(z => z.Name.StartsWith(domain)).Id;

            var record = new ResourceRecord() { Value = ipAddress };

            var recordSet = new ResourceRecordSet()
                                {
                                    Name = hostname,
                                    TTL = 300, //5 min.
                                    Type = DnsRecordType.A,
                                    ResourceRecords = new List<ResourceRecord> {record}
                                };

            var change = new Change() {Action = action, ResourceRecordSet = recordSet};

            var request = new ChangeResourceRecordSetsRequest()
                          	{
                          		ChangeBatch = new ChangeBatch()
                          		              	{
                          		              		Changes = new List<Change> {change},
                          		              		Comment = string.Format("Automatically updated by {0}", this.ToString())
                          		              	},
                          		HostedZoneId = hostedZoneId
                          	};
            return request;
        }