Exemplo n.º 1
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, GetHostedZoneResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            if (context.IsStartOfDocument)
            {
                targetDepth += 1;
            }

            while (context.Read())
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("HostedZone", targetDepth))
                    {
                        var unmarshaller = HostedZoneUnmarshaller.Instance;
                        response.HostedZone = unmarshaller.Unmarshall(context);
                        continue;
                    }
                    if (context.TestExpression("DelegationSet", targetDepth))
                    {
                        var unmarshaller = DelegationSetUnmarshaller.Instance;
                        response.DelegationSet = unmarshaller.Unmarshall(context);
                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth < originalDepth)
                {
                    return;
                }
            }

            return;
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            GetHostedZoneResponse response = new GetHostedZoneResponse();

            UnmarshallResult(context, response);

            return(response);
        }
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            GetHostedZoneResponse response = new GetHostedZoneResponse();

            while (context.Read())
            {
                if (context.IsStartElement)
                {
                    response.GetHostedZoneResult = GetHostedZoneResultUnmarshaller.GetInstance().Unmarshall(context);
                    break;
                }
            }

            return(response);
        }
Exemplo n.º 4
0
        public bool PrepareChallengeForValidation(string dnsKeyName, string dnsKeyValue)
        {
            try
            {
                route53Client = new AmazonRoute53Client();
                HostedZone zone = null;
                if (zoneId != null)
                {
                    GetHostedZoneResponse zoneResp = route53Client.GetHostedZone(new Amazon.Route53.Model.GetHostedZoneRequest {
                        Id = zoneId
                    });
                    zone = zoneResp.HostedZone;
                }
                else
                {
                    ListHostedZonesResponse zones = route53Client.ListHostedZones();
                    string recordToZone           = dnsKeyName;
                    while (recordToZone.IndexOf('.') > 0)
                    {
                        recordToZone = recordToZone.Substring(recordToZone.IndexOf('.') + 1);
                        zone         = zones.HostedZones.Where(z => z.Name.Contains(recordToZone)).FirstOrDefault();
                        if (zone != null)
                        {
                            break;
                        }
                    }
                }
                if (zone == null)
                {
                    logger.Error("Could not find DNS zone");
                    return(false);
                }

                ListResourceRecordSetsResponse txtRecordsResponse = route53Client.ListResourceRecordSets(new ListResourceRecordSetsRequest
                {
                    StartRecordName = dnsKeyName,
                    StartRecordType = "TXT",
                    MaxItems        = "1",
                    HostedZoneId    = zone.Id
                });
                ResourceRecordSet txtRecord = txtRecordsResponse.ResourceRecordSets.FirstOrDefault(r => (r.Name == dnsKeyName || r.Name == dnsKeyName + ".") && r.Type.Value == "TXT");

                if (txtRecord != null)
                {
                    ApplyDnsChange(zone, txtRecord, ChangeAction.DELETE);
                }

                txtRecord = new ResourceRecordSet()
                {
                    Name            = dnsKeyName,
                    TTL             = 5,
                    Type            = RRType.TXT,
                    ResourceRecords = new List <ResourceRecord>
                    {
                        new ResourceRecord {
                            Value = "\"" + dnsKeyValue + "\""
                        }
                    }
                };

                ApplyDnsChange(zone, txtRecord, ChangeAction.UPSERT);
            }
            catch (AmazonRoute53Exception exp)
            {
                logger.Error($"Could not update AWS Route53 record: ", exp);
                return(false);
            }
            return(true);
        }