private Task InstallAsync(RunningDeployment deployment) { Guard.NotNull(deployment, "Deployment should not be null"); Guard.NotNull(bucketFactory, "Bucket factory should not be null"); AmazonS3Client ClientFactory() => ClientHelpers.CreateS3Client(awsEnvironmentGeneration); return(EnsureBucketExists(ClientFactory, bucketFactory(deployment))); }
private async Task InstallAsync(RunningDeployment deployment) { //The bucket should exist at this point Guard.NotNull(deployment, "deployment can not be null"); if (!md5HashSupported) { Log.Info("MD5 hashes are not supported in executing environment. Files will always be uploaded."); } var options = optionsProvider.GetOptions(targetMode); AmazonS3Client Factory() => ClientHelpers.CreateS3Client(awsEnvironmentGeneration); try { (await UploadAll(options, Factory, deployment)).Tee(responses => { var results = responses.Where(z => z.IsSuccess()).ToArray(); if (targetMode == S3TargetMode.EntirePackage && results.FirstOrDefault() != null) { SetOutputVariables(deployment, results.FirstOrDefault()); } else if (targetMode == S3TargetMode.FileSelections) { foreach (var result in results) { var fileName = Path.GetFileName(result.BucketKey); SetOutputVariables(deployment, result, fileName); } } }); } catch (AmazonS3Exception exception) { if (exception.ErrorCode == "AccessDenied") { throw new PermissionException("The AWS account used to perform the operation does not have the " + $"the required permissions to upload to bucket {bucket}"); } throw new UnknownException( $"An unrecognized {exception.ErrorCode} error was thrown while uploading to bucket {bucket}"); } catch (AmazonServiceException exception) { HandleAmazonServiceException(exception); throw; } }
public void Install(RunningDeployment deployment) { //The bucket should exist at this point Guard.NotNull(deployment, "deployment can not be null"); if (!md5HashSupported) { Log.Info("MD5 hashes are not supported in executing environment. Files will always be uploaded."); } var options = optionsProvider.GetOptions(targetMode); AmazonS3Client Factory() => ClientHelpers.CreateS3Client(awsEnvironmentGeneration); try { UploadAll(options, Factory, deployment).Tee(responses => { SetOutputVariables(deployment, responses); }); } catch (AmazonS3Exception exception) { if (exception.ErrorCode == "AccessDenied") { throw new PermissionException("The AWS account used to perform the operation does not have the " + $"the required permissions to upload to bucket {bucket}"); } throw new UnknownException( $"An unrecognised {exception.ErrorCode} error was thrown while uploading to bucket {bucket}"); } catch (AmazonServiceException exception) { HandleAmazonServiceException(exception); throw; } }
/// <summary> /// The SDK allows us to deploy a template from a URL, but does not apply parameters from a URL. So we /// must download the parameters file and parse it locally. /// </summary> static void DownloadS3(IVariables variables, ILog log, string templateParameterS3Url) { try { var environment = AwsEnvironmentGeneration.Create(log, variables).GetAwaiter().GetResult(); var s3Uri = new AmazonS3Uri(templateParameterS3Url); using (IAmazonS3 client = ClientHelpers.CreateS3Client(environment)) { var request = new GetObjectRequest { BucketName = s3Uri.Bucket, Key = s3Uri.Key }; var response = client.GetObjectAsync(request).GetAwaiter().GetResult(); response.WriteResponseStreamToFileAsync(ParametersFile, false, new CancellationTokenSource().Token).GetAwaiter().GetResult(); } } catch (UriFormatException ex) { log.Error($"The parameters URL of {templateParameterS3Url} is invalid"); throw; } }