コード例 #1
0
        /// <summary>
        /// Helper method to get the AWS Credentials from environment variables
        /// </summary>
        /// <param name="environment">The cake environment.</param>
        /// <returns>A new <see cref="DeploySettings"/> instance to be used in calls to the <see cref="IDeployManager"/>.</returns>
        public static DeploySettings CreateDeploySettings(this ICakeEnvironment environment)
        {
            if (environment == null)
            {
                throw new ArgumentNullException("environment");
            }

            DeploySettings settings = new DeploySettings();



            //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);
        }
コード例 #2
0
        /// <summary>
        /// Gets the deployment info
        /// </summary>
        /// <param name="deploymentID">A deployment ID associated with the applicable IAM user or AWS account.</param>
        /// <param name="settings">The <see cref="DeploySettings"/> used during the request to AWS.</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 <DeploymentInfo> GetDeploymentInfo(string deploymentID, DeploySettings settings, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (String.IsNullOrEmpty(deploymentID))
            {
                throw new ArgumentNullException("deploymentID");
            }



            // Create Request
            AmazonCodeDeployClient client  = this.CreateClient(settings);
            GetDeploymentRequest   request = new GetDeploymentRequest();

            request.DeploymentId = deploymentID;



            // Check Response
            GetDeploymentResponse response = await client.GetDeploymentAsync(request, cancellationToken);

            if (response.HttpStatusCode == HttpStatusCode.OK)
            {
                _Log.Verbose("Successfully found deployment info '{0}'", deploymentID);
                return(response.DeploymentInfo);
            }
            else
            {
                _Log.Error("Failed to get deployment info '{0}'", deploymentID);
                return(null);
            }
        }
        /// <summary>
        /// Specifies the endpoints available to AWS clients.
        /// </summary>
        /// <param name="settings">The CodeDeploy settings.</param>
        /// <param name="region">The endpoints available to AWS clients.</param>
        /// <returns>The same <see cref="DeploySettings"/> instance so that multiple calls can be chained.</returns>
        public static DeploySettings SetRegion(this DeploySettings settings, RegionEndpoint region)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

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

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

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

            settings.SessionToken = token;
            return(settings);
        }
コード例 #7
0
        /// <summary>
        /// Registers with AWS CodeDeploy a revision for the specified application.
        /// </summary>
        /// <param name="applicationName">The name of an AWS CodeDeploy application associated with the applicable IAM user or AWS account.</param>
        /// <param name="settings">The <see cref="DeploySettings"/> used during the request to AWS.</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> RegisterApplicationRevision(string applicationName, DeploySettings settings, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (String.IsNullOrEmpty(applicationName))
            {
                throw new ArgumentNullException("applicationName");
            }



            // Create Request
            AmazonCodeDeployClient             client  = this.CreateClient(settings);
            RegisterApplicationRevisionRequest request = new RegisterApplicationRevisionRequest();

            request.ApplicationName = applicationName;

            request.Revision = new RevisionLocation()
            {
                RevisionType = RevisionLocationType.S3,

                S3Location = new S3Location()
                {
                    BundleType = BundleType.Zip,

                    Bucket  = settings.S3Bucket,
                    Key     = settings.S3Key,
                    Version = settings.S3Version
                }
            };



            // Check Response
            RegisterApplicationRevisionResponse response = await client.RegisterApplicationRevisionAsync(request, cancellationToken);

            if (response.HttpStatusCode == HttpStatusCode.OK)
            {
                _Log.Verbose("Successfully deployed application '{0}'", applicationName);
                return(true);
            }
            else
            {
                _Log.Error("Failed to deploy application '{0}'", applicationName);
                return(false);
            }
        }
コード例 #8
0
        private AmazonCodeDeployClient CreateClient(DeploySettings 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 AmazonCodeDeployClient(settings.AccessKey, settings.SecretKey, settings.SessionToken, settings.Region));
                }
                else
                {
                    return(new AmazonCodeDeployClient(settings.AccessKey, settings.SecretKey, settings.Region));
                }
            }
            else
            {
                return(new AmazonCodeDeployClient(settings.Credentials, settings.Region));
            }
        }
コード例 #9
0
 public static async Task <bool> RegisterApplicationRevision(this ICakeContext context, string applicationName, DeploySettings settings)
 {
     return(await context.CreateManager().RegisterApplicationRevision(applicationName, settings));
 }
コード例 #10
0
 public static async Task <DeploymentInfo> GetDeploymentInfo(this ICakeContext context, string deploymentID, DeploySettings settings, CancellationToken cancellationToken)
 {
     return(await context.CreateManager().GetDeploymentInfo(deploymentID, settings, cancellationToken));
 }
コード例 #11
0
 public static async Task <bool> CreateDeployment(this ICakeContext context, string applicationName, string deploymentGroup, DeploySettings settings, CancellationToken cancellationToken)
 {
     return(await context.CreateManager().CreateDeployment(applicationName, deploymentGroup, settings, cancellationToken));
 }