public void ValidateGetPublicUrl() { var storageConfiguration = new PiranhaS3StorageOptions { BucketName = ValidUnitTestBucketName, KeyPrefix = ValidUnitTestKeyPrefix, PublicUrlRoot = ValidUnitTestUriHost }; S3Storage s3Storage = new S3Storage(storageConfiguration, null, null); // Test null id input var returnUri = s3Storage.GetPublicUrl(null); Assert.Null(returnUri); // Test empty id input returnUri = s3Storage.GetPublicUrl(" "); Assert.Null(returnUri); // Test Valid Url generation string testId = Guid.NewGuid().ToString(); returnUri = s3Storage.GetPublicUrl(testId); var expectedUri = Url.Combine(ValidUnitTestUriHost, ValidUnitTestKeyPrefix, testId); Assert.Equal(expectedUri, returnUri); }
public void Storage_wipes_cache_directory_on_shutdown() { Assert.IsFalse(Directory.Exists(_tempDirectory), "temp dir already exists"); var storage = Storage; Assert.IsTrue(Directory.Exists(_tempDirectory), "temp dir did not get created when storage was fired up"); var cacheFile = Path.Combine(_tempDirectory, "foo"); File.WriteAllText(cacheFile, "bar"); Assert.IsTrue(File.Exists(cacheFile), "manually created cache file is missing"); _s3Storage = null; storage.Dispose(); Assert.IsFalse(Directory.Exists(_tempDirectory), "temp dir is still there after dispose"); }
public void Teardown() { MockPlug.DeregisterAll(); if (!string.IsNullOrEmpty(_tempFilename)) { _filestream.Dispose(); File.Delete(_tempFilename); } if (_s3Storage != null) { _s3Storage.Dispose(); } _s3Storage = null; }
private static void FSToS3(ResourceBE[] attachmentList) { XDoc s3config = new XDoc("config") .Start("publickey").Value(_public_key).End() .Start("privatekey").Value(_private_key).End() .Start("bucket").Value(_default_bucket).End() .Start("prefix").Value(_prefix).End(); S3Storage s3 = new S3Storage(s3config, LogUtils.CreateLog <S3Storage>()); XDoc fsconfig = new XDoc("config") .Start("path").Value(_attachmentPath).End(); FSStorage fs = new FSStorage(fsconfig); transferFiles(attachmentList, fs, s3); }
public IRequest Marshall(BundleInstanceRequest bundleInstanceRequest) { IRequest request = new DefaultRequest(bundleInstanceRequest, "AmazonEC2"); request.Parameters.Add("Action", "BundleInstance"); request.Parameters.Add("Version", "2014-02-01"); if (bundleInstanceRequest != null && bundleInstanceRequest.IsSetInstanceId()) { request.Parameters.Add("InstanceId", StringUtils.FromString(bundleInstanceRequest.InstanceId)); } if (bundleInstanceRequest != null) { Storage storage = bundleInstanceRequest.Storage; if (storage != null) { S3Storage s3 = storage.S3; if (s3 != null && s3.IsSetBucket()) { request.Parameters.Add("Storage.S3.Bucket", StringUtils.FromString(s3.Bucket)); } if (s3 != null && s3.IsSetPrefix()) { request.Parameters.Add("Storage.S3.Prefix", StringUtils.FromString(s3.Prefix)); } if (s3 != null && s3.IsSetAWSAccessKeyId()) { request.Parameters.Add("Storage.S3.AWSAccessKeyId", StringUtils.FromString(s3.AWSAccessKeyId)); } if (s3 != null && s3.IsSetUploadPolicy()) { request.Parameters.Add("Storage.S3.UploadPolicy", StringUtils.FromString(s3.UploadPolicy)); } if (s3 != null && s3.IsSetUploadPolicySignature()) { request.Parameters.Add("Storage.S3.UploadPolicySignature", StringUtils.FromString(s3.UploadPolicySignature)); } } } return(request); }
public async Task ValidateOpenAsync() { // Validate with passed in fake AwsOptions var awsOptions = new AWSOptions { Region = RegionEndpoint.USWest2, Credentials = new BasicAWSCredentials("accessId", "secretKey") }; var s3Storage = new S3Storage(ValidStorageOptions, awsOptions, null); using (var s3StorageSession = await s3Storage.OpenAsync()) { Assert.NotNull(s3StorageSession); } // Validate without creds passed in - we'll use env vars. try { Environment.SetEnvironmentVariable("AWS_ACCESS_KEY_ID", "accessId"); Environment.SetEnvironmentVariable("AWS_SECRET_KEY", "secretKey"); Environment.SetEnvironmentVariable("AWS_REGION", "us-west-2"); var s3StorageNoCreds = new S3Storage(ValidStorageOptions, null, null); using (var s3StorageSessionNoCreds = await s3StorageNoCreds.OpenAsync()) { Assert.NotNull(s3StorageSessionNoCreds); } } finally { Environment.SetEnvironmentVariable("AWS_ACCESS_KEY_ID", null); Environment.SetEnvironmentVariable("AWS_SECRET_KEY", null); Environment.SetEnvironmentVariable("AWS_REGION", null); } }
public ActionResult Index(CreateProject createProject, HttpPostedFileBase stfsUpload) { if (!ModelState.IsValid) { return(View()); } // Get the User var user = Helpers.GetAuthenticatedUser(); if (user == null) { return(View()); } // Check Name is Unique if (_dbContext.Projects.Count(p => !p.IsDeleted && p.Name.ToLower().Equals(createProject.ProjectName.ToLower())) > 0) { ModelState.AddModelError("ProjectName", "You can't have 2 Projects with the same name."); return(View()); } // Do file validation stuff if (stfsUpload == null) { ModelState.AddModelError("File", "You must select a Halo 4 Gametype to create a project."); return(View()); } else { var outputPath = Path.GetTempFileName(); var variantExtrated = Path.GetTempFileName(); System.IO.File.WriteAllBytes(outputPath, VariousFunctions.StreamToByteArray(stfsUpload.InputStream)); try { var stfsParsed = new StfsPackage(outputPath); // Validate contains variant if (!stfsParsed.FileExists("variant")) { throw new Exception(); } // Extract variant stfsParsed.ExtractFile("variant", variantExtrated); var gametype = GameType.Load(variantExtrated); // TODO: seralize gametype data var seralizedData = ""; // Write data to Database var project = new Project { Name = createProject.ProjectName, Description = createProject.ProjectDescription, UserId = user.Id }; // Write data to the S3 Bucket try { var s3 = new S3Storage(); s3.WriteObject(VariousFunctions.StreamToByteArray(stfsUpload.InputStream), S3Storage.StorageLocations.Stfs, project.StfsId); s3.WriteObject(seralizedData, S3Storage.StorageLocations.Solution, project.SolutionId); } catch { return(RedirectToAction("Index").Error("There was an unknown error trying to create the project.")); } // Save project to database _dbContext.Projects.Add(project); _dbContext.SaveChanges(); // Delete files now we done, yo System.IO.File.Delete(outputPath); System.IO.File.Delete(variantExtrated); // Redirect outa here return(RedirectToAction("Edit", new { id = project.Id })); } catch { // Uh Oh, NSA - get the f**k out of here, and delete all the evidence. System.IO.File.Delete(outputPath); System.IO.File.Delete(variantExtrated); ModelState.AddModelError("File", "Invalid Halo 4 Gametype."); return(View()); } } }