private async Task <Snapshot> GetSnapshotFromVersion(S3ObjectVersion version) { var req = new GetObjectMetadataRequest { BucketName = _bucket, Key = version.Key, VersionId = version.VersionId }; var res = await _client.GetObjectMetadataAsync(req).ConfigureAwait(false); return(new Snapshot { Id = version.VersionId, Metadata = ActualMetadata(res.Metadata, res.VersionId, res.LastModified, res.ContentLength, res.Headers.ContentType, res.ETag) }); }
public static S3FileKey ToVersionedS3FileKey(this S3ObjectVersion objectVersion, S3FileKey initialKey) { if (objectVersion == null) { throw new ArgumentNullException(nameof(objectVersion)); } if (initialKey == null) { throw new ArgumentNullException(nameof(initialKey)); } return(FileKeyGenerator.New() .WithFileName(initialKey.FileName) .WithFolderPath(initialKey.FolderPath) .WithBucketType(initialKey.BucketType) .WithVersion(objectVersion.VersionId) .Build()); }
/// <summary> /// Sets the server side encryption method for the S3 Object Version to the value /// specified. /// </summary> /// <param name="s3ObjectVer">The S3 Object Version</param> /// <param name="method">The server side encryption method</param> /// <param name="s3Client">The Amazon S3 Client to use for S3 specific operations.</param> /// <seealso cref="T:Amazon.S3.Model.S3StorageClass"/> public static void SetServerSideEncryption(S3ObjectVersion s3ObjectVer, ServerSideEncryptionMethod method, AmazonS3 s3Client) { SetServerSideEncryption(s3ObjectVer.BucketName, s3ObjectVer.Key, s3ObjectVer.VersionId, method, s3Client); }
/// <summary> /// Sets the storage class for the S3 Object Version to the value /// specified. /// </summary> /// <param name="s3ObjectVer">The S3 Object Version whose storage class needs changing</param> /// <param name="sClass">The new Storage Class for the object</param> /// <param name="s3Client">The Amazon S3 Client to use for S3 specific operations.</param> /// <seealso cref="T:Amazon.S3.Model.S3StorageClass"/> public static void SetObjectStorageClass(S3ObjectVersion s3ObjectVer, S3StorageClass sClass, AmazonS3 s3Client) { SetObjectStorageClass(s3ObjectVer.BucketName, s3ObjectVer.Key, s3ObjectVer.VersionId, sClass, s3Client); }
private static void UnmarshallResult(XmlUnmarshallerContext context, ListVersionsResponse response) { int currentDepth = context.get_CurrentDepth(); int num = currentDepth + 1; if (context.get_IsStartOfDocument()) { num += 2; } while (context.Read()) { if (context.get_IsStartElement() || context.get_IsAttribute()) { if (context.TestExpression("IsTruncated", num)) { response.IsTruncated = BoolUnmarshaller.GetInstance().Unmarshall(context); } else if (context.TestExpression("KeyMarker", num)) { response.KeyMarker = StringUnmarshaller.GetInstance().Unmarshall(context); } else if (context.TestExpression("Delimiter", num)) { response.Delimiter = StringUnmarshaller.GetInstance().Unmarshall(context); } else if (context.TestExpression("VersionIdMarker", num)) { response.VersionIdMarker = StringUnmarshaller.GetInstance().Unmarshall(context); } else if (context.TestExpression("NextKeyMarker", num)) { response.NextKeyMarker = StringUnmarshaller.GetInstance().Unmarshall(context); } else if (context.TestExpression("NextVersionIdMarker", num)) { response.NextVersionIdMarker = StringUnmarshaller.GetInstance().Unmarshall(context); } else if (context.TestExpression("Version", num)) { response.Versions.Add(VersionsItemUnmarshaller.Instance.Unmarshall(context)); } else if (context.TestExpression("DeleteMarker", num)) { S3ObjectVersion s3ObjectVersion = VersionsItemUnmarshaller.Instance.Unmarshall(context); s3ObjectVersion.IsDeleteMarker = true; response.Versions.Add(s3ObjectVersion); } else if (context.TestExpression("Name", num)) { response.Name = StringUnmarshaller.GetInstance().Unmarshall(context); } else if (context.TestExpression("Prefix", num)) { response.Prefix = StringUnmarshaller.GetInstance().Unmarshall(context); } else if (context.TestExpression("MaxKeys", num)) { response.MaxKeys = IntUnmarshaller.GetInstance().Unmarshall(context); } else if (context.TestExpression("CommonPrefixes", num)) { string text = CommonPrefixesItemUnmarshaller.Instance.Unmarshall(context); if (text != null) { response.CommonPrefixes.Add(text); } } } else if (context.get_IsEndElement() && context.get_CurrentDepth() < currentDepth) { break; } } }
/// <summary> /// This routine will retireve all objects within the specified S3 Bucket /// Any objects which have a modified date older than our target will be removed /// </summary> /// <param name="modifiedDate"></param> /// <returns></returns> private static async Task <List <S3Object> > ListObjects(DateTime modifiedDate) { try { List <S3Object> s3Objects = new List <S3Object>(); ListObjectsV2Request request = new ListObjectsV2Request() { BucketName = bucketName }; ListObjectsV2Response response; Console.WriteLine("Connecting to S3..."); do { response = await client.ListObjectsV2Async(request); foreach (S3Object entry in response.S3Objects) { if (entry.LastModified.IsAfter(modifiedDate)) { var listResponse = client.ListVersionsAsync(new ListVersionsRequest { BucketName = bucketName, Prefix = entry.Key }); S3ObjectVersion deleteMarkerVersion = listResponse.Result.Versions.FirstOrDefault(x => x.IsLatest); if (deleteMarkerVersion != null) { await client.DeleteObjectAsync(new DeleteObjectRequest { BucketName = bucketName, Key = entry.Key, VersionId = deleteMarkerVersion.VersionId }); } s3Objects.Add(entry); } } Console.WriteLine("Next Continuation Token: {0}", response.NextContinuationToken); request.ContinuationToken = response.NextContinuationToken; } while (response.IsTruncated); return(s3Objects); } catch (AmazonS3Exception e) { Console.WriteLine("Error encountered on server. Message:'{0}' when writing an object", e.Message); return(null); } catch (Exception e) { Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message); return(null); } }