public IEnumerable <S3TargetPropertiesBase> GetOptions(S3TargetMode mode) { switch (mode) { case S3TargetMode.EntirePackage: return(new List <S3TargetPropertiesBase> { GetPackageOptions() }); case S3TargetMode.FileSelections: return(GetFileSelections()); default: throw new ArgumentOutOfRangeException("Invalid s3 target mode provided", nameof(mode)); } }
public UploadAwsS3Convention(ICalamariFileSystem fileSystem, IAwsEnvironmentGeneration awsEnvironmentGeneration, string bucket, S3TargetMode targetMode, IProvideS3TargetOptions optionsProvider, IFileSubstituter fileSubstituter ) { this.fileSystem = fileSystem; this.awsEnvironmentGeneration = awsEnvironmentGeneration; this.bucket = bucket; this.targetMode = targetMode; this.optionsProvider = optionsProvider; this.fileSubstituter = fileSubstituter; this.md5HashSupported = HashCalculator.IsAvailableHashingAlgorithm(MD5.Create); }
public UploadAwsS3Convention( ILog log, ICalamariFileSystem fileSystem, AwsEnvironmentGeneration awsEnvironmentGeneration, string bucket, S3TargetMode targetMode, IProvideS3TargetOptions optionsProvider, IBucketKeyProvider bucketKeyProvider, ISubstituteInFiles substituteInFiles ) { this.log = log; this.fileSystem = fileSystem; this.awsEnvironmentGeneration = awsEnvironmentGeneration; this.bucket = bucket; this.targetMode = targetMode; this.optionsProvider = optionsProvider; this.bucketKeyProvider = bucketKeyProvider; this.substituteInFiles = substituteInFiles; this.md5HashSupported = HashCalculator.IsAvailableHashingAlgorithm(MD5.Create); }
protected string Upload(string packageName, List <S3TargetPropertiesBase> propertiesList, VariableDictionary customVariables = null, S3TargetMode s3TargetMode = S3TargetMode.FileSelections) { const string packageVersion = "1.0.0"; var bucketKeyPrefix = $"calamaritest/{Guid.NewGuid():N}/"; var variables = new CalamariVariables(); propertiesList.ForEach(properties => { switch (properties) { case S3MultiFileSelectionProperties multiFileSelectionProperties: multiFileSelectionProperties.BucketKeyPrefix = bucketKeyPrefix; variables.Set(AwsSpecialVariables.S3.FileSelections, JsonConvert.SerializeObject(propertiesList, GetEnrichedSerializerSettings())); break; case S3SingleFileSelectionProperties singleFileSelectionProperties: singleFileSelectionProperties.BucketKeyPrefix = bucketKeyPrefix; variables.Set(AwsSpecialVariables.S3.FileSelections, JsonConvert.SerializeObject(propertiesList, GetEnrichedSerializerSettings())); break; case S3PackageOptions packageOptions: packageOptions.BucketKeyPrefix = bucketKeyPrefix; variables.Set(AwsSpecialVariables.S3.PackageOptions, JsonConvert.SerializeObject(packageOptions, GetEnrichedSerializerSettings())); variables.Set(PackageVariables.PackageId, packageName); variables.Set(PackageVariables.PackageVersion, packageVersion); break; } }); var variablesFile = Path.GetTempFileName(); variables.Set("Octopus.Action.AwsAccount.Variable", "AWSAccount"); variables.Set("AWSAccount.AccessKey", ExternalVariables.Get(ExternalVariable.AwsAcessKey)); variables.Set("AWSAccount.SecretKey", ExternalVariables.Get(ExternalVariable.AwsSecretKey)); variables.Set("Octopus.Action.Aws.Region", region); if (customVariables != null) { variables.Merge(customVariables); } variables.Save(variablesFile); var packageDirectory = TestEnvironment.GetTestPath("AWS", "S3", packageName); using (var package = new TemporaryFile(PackageBuilder.BuildSimpleZip(packageName, packageVersion, packageDirectory))) using (new TemporaryFile(variablesFile)) { var log = new InMemoryLog(); var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); var command = new UploadAwsS3Command( log, variables, fileSystem, new SubstituteInFiles(log, fileSystem, new FileSubstituter(log, fileSystem), variables), new ExtractPackage(new CombinedPackageExtractor(log, variables, new CommandLineRunner(log, variables)), fileSystem, variables, log), new StructuredConfigVariablesService(new PrioritisedList <IFileFormatVariableReplacer> { new JsonFormatVariableReplacer(fileSystem, log), new XmlFormatVariableReplacer(fileSystem, log), new YamlFormatVariableReplacer(fileSystem, log), new PropertiesFormatVariableReplacer(fileSystem, log), }, variables, fileSystem, log) ); var result = command.Execute(new[] { "--package", $"{package.FilePath}", "--variables", $"{variablesFile}", "--bucket", bucketName, "--targetMode", s3TargetMode.ToString() }); result.Should().Be(0); } return(bucketKeyPrefix); }