Пример #1
0
        public async IAsyncEnumerable <DnsRecord> GetAllRecords(DomainId domain, DomainName name, [EnumeratorCancellation] CancellationToken cancellationToken = default)
        {
            var parentDomainName = await DomainCache.EnsureAndGet(domain, cancellationToken).ConfigureAwait(false);

            var subDomain = name.WithoutParent(parentDomainName);

            await foreach (var record in Get <DnsRecord>($"dns/managed/{domain}/records?recordName={subDomain}").ProcessDomainCache(DomainCache, cancellationToken).ConfigureAwait(false))
            {
                yield return(record);
            }
        }
Пример #2
0
        public async IAsyncEnumerable <TRecord> GetAllRecords <TRecord>(DomainId domain, DomainName name, [EnumeratorCancellation] CancellationToken cancellationToken = default) where TRecord : DnsRecord
        {
            var type             = GetTypeString <TRecord>();
            var parentDomainName = await DomainCache.EnsureAndGet(domain, cancellationToken).ConfigureAwait(false);

            var subDomain = name.WithoutParent(parentDomainName);

            await foreach (var record in Get <DnsRecord>($"dns/managed/{domain}/records?recordName={subDomain}&type={type}").ProcessDomainCache(DomainCache, cancellationToken).ConfigureAwait(false))
            {
                if (record is not TRecord typedRecord)
                {
                    throw new InvalidOperationException("DNSMadeEasy returned records of the wrong type");
                }

                yield return(typedRecord);
            }
        }
Пример #3
0
        public async Task CreateTXTRecord(DomainId parentDomainId, DomainName name, string value, TimeToLive timeToLive, GlobalTrafficDirectorLocation globalTrafficDirectorLocation = default, CancellationToken cancellationToken = default)
        {
            var parentDomain = await DomainCache.EnsureAndGet(parentDomainId, cancellationToken).ConfigureAwait(false);

            if (!name.IsSubdomainOf(parentDomain))
            {
                throw new ArgumentException($"The specified domain `{name}` is not a subdomain of the parent `{parentDomain}`", nameof(name));
            }

            await Post($"dns/managed/{parentDomainId}/records", new
            {
                type = "TXT",
                name = name.WithoutParent(parentDomain),
                value,
                ttl         = timeToLive,
                gtdLocation = globalTrafficDirectorLocation
            }, cancellationToken).ConfigureAwait(false);
        }
Пример #4
0
        public async Task CreateARecord(DomainId parentDomainId, DomainName name, IPv4 target, TimeToLive timeToLive, string?dynamicDnsPassword = null, GlobalTrafficDirectorLocation globalTrafficDirectorLocation = default, bool isSystemMonitoringEnabled = false, bool isFailoverEnabled = false, CancellationToken cancellationToken = default)
        {
            var parentDomain = await DomainCache.EnsureAndGet(parentDomainId, cancellationToken).ConfigureAwait(false);

            if (!name.IsSubdomainOf(parentDomain))
            {
                throw new ArgumentException($"The specified domain `{name}` is not a subdomain of the parent `{parentDomain}`", nameof(name));
            }

            await Post($"dns/managed/{parentDomainId}/records", new
            {
                type        = "A",
                name        = name.WithoutParent(parentDomain),
                value       = target,
                ttl         = timeToLive,
                dynamicDns  = dynamicDnsPassword != null,
                password    = dynamicDnsPassword,
                gtdLocation = globalTrafficDirectorLocation,
                monitor     = isSystemMonitoringEnabled,
                failover    = isFailoverEnabled
            }, cancellationToken).ConfigureAwait(false);
        }
Пример #5
0
        public async Task UpdateDomain(DomainId domainId, Value <DomainName> name      = default, Value <bool> gtdEnabled    = default, Value <SoaId?> soaId                 = default,
                                       Value <TemplateId?> templateId                  = default, Value <VanityId?> vanityId = default, Value <TransferAclId?> transferAclId = default, Value <FolderId> folderId = default,
                                       Value <ImmutableArray <DomainName>?> axfrServer = default, Value <ImmutableArray <DomainName>?> delegateNameServers = default, CancellationToken cancellationToken = default)
        {
            await Put($"dns/managed/{domainId}", new
            {
                name,
                gtdEnabled,
                soaId,
                templateId,
                vanityId,
                transferAclId,
                folderId,
                axfrServer,
                delegateNameServers
            }, cancellationToken).ConfigureAwait(false);

            if (name.HasValue)
            {
                DomainCache.Set(domainId, name);
            }
        }
Пример #6
0
        public async ValueTask <DnsRecords> CreateMultiRecordCollection(DomainId domain, CancellationToken cancellationToken = default)
        {
            var domainName = await DomainCache.EnsureAndGet(domain, cancellationToken).ConfigureAwait(false);

            return(new DnsRecords(domain, domainName));
        }
Пример #7
0
 public static async IAsyncEnumerable <T> ProcessDomainCache <T>(this IAsyncEnumerable <T> values, DomainCache domainCache, [EnumeratorCancellation]  CancellationToken cancellationToken = default) where T : IDomainCacheUpdatable <T>
 {
     await foreach (var value in values)
     {
         yield return(await value.UpdateFromCache(domainCache, cancellationToken).ConfigureAwait(false));
     }
 }
Пример #8
0
        public static async Task <Domain> ProcessDomainCache(this Task <Domain> domain, DomainCache domainCache)
        {
            var domainValue = await domain.ConfigureAwait(false);

            domainCache.Set(domainValue.Id, domainValue.Name);
            return(domainValue);
        }
Пример #9
0
 public static async IAsyncEnumerable <DomainSummary> ProcessDomainCache(this IAsyncEnumerable <DomainSummary> domains, DomainCache domainCache)
 {
     await foreach (var domain in domains)
     {
         domainCache.Set(domain.Id, domain.Name);
         yield return(domain);
     }
 }
Пример #10
0
        async ValueTask <DnsRecord> IDomainCacheUpdatable <DnsRecord> .UpdateFromCache(DomainCache domainCache, CancellationToken cancellationToken)
        {
            var parentDomain = await domainCache.EnsureAndGet(ParentDomainId, cancellationToken).ConfigureAwait(false);

            var newName = parentDomain.WithSubdomain(Name);

            return(UpdateFromCache(newName, parentDomain));
        }