/// <summary> /// Checks if an S3 multi-region access point already exists. /// Note: does not validate that the MRAP is ready. /// </summary> /// <param name="s3ControlClient">S3Control client</param> /// <param name="accountId">AWS account ID that is expected to contain the MRAP</param> /// <param name="mrapName">Name of the multi-region access point</param> /// <returns>The MRAP's ARN if it exists, an empty string otherwise</returns> private static string CheckIfMRAPExists(IAmazonS3Control s3ControlClient, string accountId, string mrapName) { var nextToken = ""; var request = new ListMultiRegionAccessPointsRequest { AccountId = accountId }; ListMultiRegionAccessPointsResponse response; // Use a loop instead of paginators since we need net35 support do { request.NextToken = nextToken; response = s3ControlClient.ListMultiRegionAccessPoints(request); foreach (var accessPoint in response.AccessPoints) { if (accessPoint.Name == mrapName) { return($"arn:aws:s3::{accountId}:accesspoint/{accessPoint.Alias}"); } } nextToken = response.NextToken; }while (!string.IsNullOrEmpty(nextToken)); return(""); }
/// <summary> /// Creates an S3 Multi-Region Access Point and waits for it to be ready /// </summary> /// <param name="s3ControlClient">S3Control client to create the MRAP with</param> /// <param name="mrapRequest">Prepared CreateMultiRegionAccessPoint request</param> /// <returns>Alias of the new Multi-Region Access Point</returns> public static string CreateMRAPWithWait(IAmazonS3Control s3ControlClient, CreateMultiRegionAccessPointRequest mrapRequest) { var asyncRequestArn = s3ControlClient.CreateMultiRegionAccessPoint(mrapRequest).RequestTokenARN; var mrapAlias = UtilityMethods.WaitUntilSuccess(() => { var request = new GetMultiRegionAccessPointRequest { AccountId = mrapRequest.AccountId, Name = mrapRequest.Details.Name }; var response = s3ControlClient.GetMultiRegionAccessPoint(request); if (response.AccessPoint.Status == MultiRegionAccessPointStatus.READY) { return(response.AccessPoint.Alias); } else { throw new Exception("S3 Multi-Region Access Point not ready yet, will continue waiting."); } }); return(mrapAlias); }
private Amazon.S3Control.Model.DeleteBucketResponse CallAWSServiceOperation(IAmazonS3Control client, Amazon.S3Control.Model.DeleteBucketRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon S3 Control", "DeleteBucket"); try { #if DESKTOP return(client.DeleteBucket(request)); #elif CORECLR return(client.DeleteBucketAsync(request).GetAwaiter().GetResult()); #else #error "Unknown build edition" #endif } catch (AmazonServiceException exc) { var webException = exc.InnerException as System.Net.WebException; if (webException != null) { throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException); } throw; } }
/// <summary> /// Deletes an S3 Multi-Region Access Point and waits for the delete to succeed /// </summary> /// <param name="s3ControlClient">S3Control client to delete the MRAP with</param> /// <param name="deleteRequest">Prepared DeleteMultiRegionAccessPoint request</param> public static void DeleteMRAPWithWait(IAmazonS3Control s3ControlClient, DeleteMultiRegionAccessPointRequest deleteRequest) { var asyncRequestArn = s3ControlClient.DeleteMultiRegionAccessPoint(deleteRequest).RequestTokenARN; UtilityMethods.WaitUntilSuccess(() => { var request = new DescribeMultiRegionAccessPointOperationRequest { AccountId = deleteRequest.AccountId, RequestTokenARN = asyncRequestArn }; var response = s3ControlClient.DescribeMultiRegionAccessPointOperation(request); if (response.AsyncOperation.RequestStatus == "SUCCEEDED") { return; } else { throw new Exception("S3 Multi-Region Access Point not deleted yet, will continue waiting."); } }); }
internal ListJobsPaginator(IAmazonS3Control client, ListJobsRequest request) { this._client = client; this._request = request; }
internal ListRegionalBucketsPaginator(IAmazonS3Control client, ListRegionalBucketsRequest request) { this._client = client; this._request = request; }
internal S3ControlPaginatorFactory(IAmazonS3Control client) { this.client = client; }
internal ListAccessPointsForObjectLambdaPaginator(IAmazonS3Control client, ListAccessPointsForObjectLambdaRequest request) { this._client = client; this._request = request; }
/// <summary> /// Gets a long-lived S3 Multi-Region Access Point for running integration tests against if /// if exists in the current account. If not, creates it and waits for it to be ready. /// </summary> /// <param name="s3ControlClient">S3Control client to create the MRAP with</param> /// <param name="s3Client">S3 client to create the backing bucket with</param> /// <returns>ARN of the new Multi-Region Access Point</returns> public static string GetOrCreateTestMRAP(IAmazonS3Control s3ControlClient, IAmazonS3 s3Client) { var accountId = new AmazonSecurityTokenServiceClient().GetCallerIdentity(new GetCallerIdentityRequest()).Account; // If the MRAP already exists, return it var mrapArn = CheckIfMRAPExists(s3ControlClient, accountId, TEST_MRAP_NAME); if (!string.IsNullOrEmpty(mrapArn)) { return(mrapArn); } // Otherwise the MRAP doesn't exist, so we must create it, starting with the backing bucket. var putBucketRequest = new PutBucketRequest { BucketName = $"{accountId}-{TEST_MRAP_NAME}" }; var backingBucketName = CreateBucketWithWait(s3Client, putBucketRequest); var createMrapRequest = new CreateMultiRegionAccessPointRequest { AccountId = accountId, Details = new CreateMultiRegionAccessPointInput { Name = TEST_MRAP_NAME, Regions = new List <Region> { new Region { Bucket = backingBucketName } } } }; // Initiate the MRAP creation var asyncRequestArn = s3ControlClient.CreateMultiRegionAccessPoint(createMrapRequest).RequestTokenARN; // Wait until its status is READY UtilityMethods.WaitUntilSuccess(() => { var request = new GetMultiRegionAccessPointRequest { AccountId = accountId, Name = TEST_MRAP_NAME }; var response = s3ControlClient.GetMultiRegionAccessPoint(request); if (response.AccessPoint.Status == MultiRegionAccessPointStatus.READY) { // Wait for SSL provisioning to finish Thread.Sleep(TimeSpan.FromMinutes(1)); return($"arn:aws:s3::{accountId}:accesspoint/{response.AccessPoint.Alias}"); } else { throw new Exception("S3 Multi-Region Access Point not ready yet, will continue waiting."); } }); throw new Exception($"{nameof(GetOrCreateTestMRAP)} timed out while creating a new Multi-Region Access Point"); }
internal ListStorageLensConfigurationsPaginator(IAmazonS3Control client, ListStorageLensConfigurationsRequest request) { this._client = client; this._request = request; }
internal ListMultiRegionAccessPointsPaginator(IAmazonS3Control client, ListMultiRegionAccessPointsRequest request) { this._client = client; this._request = request; }