/// <summary>
        /// Helper method to get the AWS Credentials from environment variables
        /// </summary>
        /// <param name="environment">The cake environment.</param>
        /// <returns>A new <see cref="Route53Settings"/> instance to be used in calls to the <see cref="IRoute53Manager"/>.</returns>
        public static Route53Settings CreateRoute53Settings(this ICakeEnvironment environment)
        {
            if (environment == null)
            {
                throw new ArgumentNullException("environment");
            }

            Route53Settings settings = new Route53Settings();

            //AWS Fallback
            AWSCredentials creds = FallbackCredentialsFactory.GetCredentials();

            if (creds != null)
            {
                settings.Credentials = creds;
            }

            //Environment Variables
            string region = environment.GetEnvironmentVariable("AWS_REGION");

            if (!String.IsNullOrEmpty(region))
            {
                settings.Region = RegionEndpoint.GetBySystemName(region);
            }

            return(settings);
        }
Esempio n. 2
0
        /// <summary>
        /// Delete a hosted zone.
        /// </summary>
        /// <param name="hostedZoneId">The ID of the hosted zone that contains the resource record sets that you want to delete</param>
        /// <param name="settings">The <see cref="Route53Settings"/> required to connect to Route53.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        public async Task <bool> DeleteHostedZone(string hostedZoneId, Route53Settings settings, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (String.IsNullOrEmpty(hostedZoneId))
            {
                throw new ArgumentNullException("hostedZoneId");
            }



            DeleteHostedZoneRequest request = new DeleteHostedZoneRequest(hostedZoneId);

            AmazonRoute53Client      client   = this.GetClient(settings);
            DeleteHostedZoneResponse response = await client.DeleteHostedZoneAsync(request);

            if (response.HttpStatusCode == HttpStatusCode.OK)
            {
                await this.WaitForChange(client, response.ChangeInfo.Id, 10000, 60);

                _Log.Verbose("deleted hosted zone");
                return(true);
            }
            else
            {
                _Log.Error("Could not delete hosted zone");
                return(false);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Retrieve the hosted zone for a specific domain.
        /// </summary>
        /// <param name="domain">The name of the domain</param>
        /// <param name="settings">The <see cref="Route53Settings"/> required to connect to Route53.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        public async Task <HostedZone> GetHostedZone(string domain, Route53Settings settings, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (String.IsNullOrEmpty(domain))
            {
                throw new ArgumentNullException("domain");
            }



            IList <HostedZone> zones = await this.GetHostedZones(settings);

            HostedZone zone = null;

            if (zones != null)
            {
                zone = zones.FirstOrDefault(z => z.Name == domain);
            }

            if (zone == null)
            {
                _Log.Error("Could not find a hosted zone with the domain {0}", domain);
            }

            return(zone);
        }
Esempio n. 4
0
        /// <summary>
        /// Specifies the endpoints available to AWS clients.
        /// </summary>
        /// <param name="settings">The Route53 settings.</param>
        /// <param name="region">The endpoints available to AWS clients.</param>
        /// <returns>The same <see cref="Route53Settings"/> instance so that multiple calls can be chained.</returns>
        public static Route53Settings SetRegion(this Route53Settings settings, RegionEndpoint region)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.Region = region;
            return(settings);
        }
Esempio n. 5
0
        /// <summary>
        /// Specifies the endpoints available to AWS clients.
        /// </summary>
        /// <param name="settings">The Route53 settings.</param>
        /// <param name="region">The endpoints available to AWS clients.</param>
        /// <returns>The same <see cref="Route53Settings"/> instance so that multiple calls can be chained.</returns>
        public static Route53Settings SetRegion(this Route53Settings settings, string region)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.Region = RegionEndpoint.GetBySystemName(region);
            return(settings);
        }
Esempio n. 6
0
        /// <summary>
        /// Specifies the AWS Secret Key to use as credentials.
        /// </summary>
        /// <param name="settings">The Route53 settings.</param>
        /// <param name="key">The AWS Secret Key</param>
        /// <returns>The same <see cref="Route53Settings"/> instance so that multiple calls can be chained.</returns>
        public static Route53Settings SetSecretKey(this Route53Settings settings, string key)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.SecretKey = key;
            return(settings);
        }
Esempio n. 7
0
        /// <summary>
        /// Specifies the AWS Session Token to use as credentials.
        /// </summary>
        /// <param name="settings">The Route53 settings.</param>
        /// <param name="token">The AWS Session Token.</param>
        /// <returns>The same <see cref="Route53Settings"/> instance so that multiple calls can be chained.</returns>
        public static Route53Settings SetSessionToken(this Route53Settings settings, string token)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            if (string.IsNullOrEmpty(token))
            {
                throw new ArgumentNullException("token");
            }

            settings.SessionToken = token;
            return(settings);
        }
Esempio n. 8
0
        /// <summary>
        /// Retrieve a list of your hosted zones.
        /// </summary>
        /// <param name="settings">The <see cref="Route53Settings"/> required to connect to Route53.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        public async Task <IList <HostedZone> > GetHostedZones(Route53Settings settings, CancellationToken cancellationToken = default(CancellationToken))
        {
            ListHostedZonesRequest request = new ListHostedZonesRequest();

            AmazonRoute53Client     client   = this.GetClient(settings);
            ListHostedZonesResponse response = await client.ListHostedZonesAsync(request);

            if (response.HttpStatusCode == HttpStatusCode.OK)
            {
                _Log.Verbose("Listing hosted zones");
                return(response.HostedZones);
            }
            else
            {
                _Log.Error("Could not list hosted zones");
                return(null);
            }
        }
Esempio n. 9
0
        //Helpers
        private AmazonRoute53Client GetClient(Route53Settings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            if (settings.Region == null)
            {
                throw new ArgumentNullException("settings.Region");
            }

            if (settings.Credentials == null)
            {
                if (String.IsNullOrEmpty(settings.AccessKey))
                {
                    throw new ArgumentNullException("settings.AccessKey");
                }
                if (String.IsNullOrEmpty(settings.SecretKey))
                {
                    throw new ArgumentNullException("settings.SecretKey");
                }

                if (!String.IsNullOrEmpty(settings.SessionToken))
                {
                    return(new AmazonRoute53Client(settings.AccessKey, settings.SecretKey, settings.SessionToken, settings.Region));
                }
                else
                {
                    return(new AmazonRoute53Client(settings.AccessKey, settings.SecretKey, settings.Region));
                }
            }
            else
            {
                return(new AmazonRoute53Client(settings.Credentials, settings.Region));
            }
        }
Esempio n. 10
0
 public static async Task <bool> DeleteHostedZone(this ICakeContext context, string hostedZoneId, Route53Settings settings)
 {
     return(await context.CreateManager().DeleteHostedZone(hostedZoneId, settings));
 }
Esempio n. 11
0
 public static async Task <string> CreateHostedZone(this ICakeContext context, string domain, string vpc, VPCRegion region, Route53Settings settings)
 {
     return(await context.CreateManager().CreateHostedZone(domain, vpc, region, settings));
 }
Esempio n. 12
0
 public static async Task <IList <ResourceRecordSet> > GetResourceRecordSets(this ICakeContext context, string hostedZoneId, Route53Settings settings)
 {
     return(await context.CreateManager().GetResourceRecordSets(hostedZoneId, settings));
 }
Esempio n. 13
0
 public static async Task <string> DeleteResourceRecordSet(this ICakeContext context, string hostedZoneId, string name, RRType type, string value, long ttl, Route53Settings settings)
 {
     return(await context.CreateManager().DeleteResourceRecordSet(hostedZoneId, name, type, value, ttl, settings));
 }
Esempio n. 14
0
 public static async Task <string> CreateResourceRecordSet(this ICakeContext context, string hostedZoneId, string name, RRType type, Route53Settings settings)
 {
     return(await context.CreateManager().CreateResourceRecordSet(hostedZoneId, name, type, EC2InstanceMetadata.PrivateIpAddress, 300, settings));
 }
Esempio n. 15
0
        /// <summary>
        /// To retrieve a list of record sets for a particular hosted zone.
        /// </summary>
        /// <param name="hostedZoneId">The ID of the hosted zone whos record sets you want to list</param>
        /// <param name="settings">The <see cref="Route53Settings"/> required to connect to Route53.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        public async Task <IList <ResourceRecordSet> > GetResourceRecordSets(string hostedZoneId, Route53Settings settings, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (String.IsNullOrEmpty(hostedZoneId))
            {
                throw new ArgumentNullException("hostedZoneId");
            }



            ListResourceRecordSetsRequest request = new ListResourceRecordSetsRequest(hostedZoneId);

            AmazonRoute53Client            client   = this.GetClient(settings);
            ListResourceRecordSetsResponse response = await client.ListResourceRecordSetsAsync(request);

            if (response.HttpStatusCode == HttpStatusCode.OK)
            {
                _Log.Verbose("Listing record sets");
                return(response.ResourceRecordSets);
            }
            else
            {
                _Log.Error("Could not list record sets");
                return(null);
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Create a new hosted zone. When you create a zone, its initial status is PENDING. This means that it is not yet available on all DNS servers.
        /// The status of the zone changes to INSYNC when the NS and SOA records are available on all Route 53 DNS servers.
        /// </summary>
        /// <param name="domain">The name of the domain</param>
        /// <param name="vpc">The VPC that you want your hosted zone to be associated with. By providing this parameter, your newly created hosted cannot be resolved anywhere other than the given VPC.</param>
        /// <param name="region">The region of your VPC</param>
        /// <param name="settings">The <see cref="Route53Settings"/> required to connect to Route53.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        public async Task <string> CreateHostedZone(string domain, string vpc, VPCRegion region, Route53Settings settings, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (String.IsNullOrEmpty(domain))
            {
                throw new ArgumentNullException("domain");
            }



            CreateHostedZoneRequest request = new CreateHostedZoneRequest(domain, "");

            if (!String.IsNullOrEmpty(vpc))
            {
                request.VPC = new VPC()
                {
                    VPCId     = vpc,
                    VPCRegion = region
                };
            }

            AmazonRoute53Client      client   = this.GetClient(settings);
            CreateHostedZoneResponse response = await client.CreateHostedZoneAsync(request);

            if (response.HttpStatusCode == HttpStatusCode.OK)
            {
                await this.WaitForChange(client, response.ChangeInfo.Id, 10000, 60);

                _Log.Verbose("Created hosted zone");
                return(response.HostedZone.Id);
            }
            else
            {
                _Log.Error("Could not create hosted zone");
                return("");
            }
        }
Esempio n. 17
0
 public static async Task <HostedZone> GetHostedZone(this ICakeContext context, string domain, Route53Settings settings)
 {
     return(await context.CreateManager().GetHostedZone(domain, settings));
 }
Esempio n. 18
0
 public static async Task <IList <HostedZone> > GetHostedZones(this ICakeContext context, Route53Settings settings)
 {
     return(await context.CreateManager().GetHostedZones(settings));
 }
Esempio n. 19
0
        /// <summary>
        /// Delete a DNS record for a hosted zone.
        /// </summary>
        /// <param name="hostedZoneId">The ID of the hosted zone that contains the resource record sets that you want to change</param>
        /// <param name="name">The name of the DNS record set.</param>
        /// <param name="type">The type of the DNS record set.</param>
        /// <param name="value">The value of the record set.</param>
        /// <param name="ttl">The time to live of the record set.</param>
        /// <param name="settings">The <see cref="Route53Settings"/> required to upload to Amazon S3.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        public async Task <string> DeleteResourceRecordSet(string hostedZoneId, string name, RRType type, string value, long ttl, Route53Settings settings, CancellationToken cancellationToken = default(CancellationToken))
        {
            var recordSet = new ResourceRecordSet()
            {
                Name            = name,
                Type            = type,
                TTL             = ttl,
                ResourceRecords = new List <ResourceRecord> {
                    new ResourceRecord(value)
                }
            };

            var change1 = new Change()
            {
                ResourceRecordSet = recordSet,
                Action            = ChangeAction.DELETE
            };

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

            var recordsetRequest = new ChangeResourceRecordSetsRequest()
            {
                HostedZoneId = hostedZoneId,
                ChangeBatch  = changeBatch
            };



            AmazonRoute53Client client = this.GetClient(settings);
            ChangeResourceRecordSetsResponse response = await client.ChangeResourceRecordSetsAsync(recordsetRequest);

            if (response.HttpStatusCode == HttpStatusCode.OK)
            {
                await this.WaitForChange(client, response.ChangeInfo.Id, 10000, 60);

                _Log.Verbose("Updated record set");
                return(response.ChangeInfo.Id);
            }
            else
            {
                _Log.Error("Could not change resource records");
                return("");
            }
        }