using System; namespace Amazon.S3 { /// /// Extensions methods added to Amazon.Arn type to help parse S3 specific resources from the ARN. /// public static class ArnExtensions { internal const string ResourceTypeAccessPoint = "accesspoint"; internal const string ResourceTypeBucketName = "bucket_name"; /// /// Attempt to parse the resource component of the ARN into access point resource name. /// /// An AWS ARN to parse /// The access point resouce identifier found in the ARN. /// True if the ARN contains an access point resource identifier. public static bool TryParseAccessPoint(this Arn arn, out string accessPoint) { accessPoint = null; if (string.IsNullOrEmpty(arn.Resource)) { return false; } if (arn.Resource.StartsWith(ResourceTypeAccessPoint + ":", StringComparison.Ordinal) || arn.Resource.StartsWith(ResourceTypeAccessPoint + "/", StringComparison.Ordinal)) { accessPoint = arn.Resource.Substring(ResourceTypeAccessPoint.Length + 1); return true; } return false; } /// /// Attempt to parse the resource component of the ARN into bucket name. /// /// An AWS ARN to parse /// The bucket name found in the ARN. /// True if the ARN contains a bucket name. public static bool TryParseBucket(this Arn arn, out string bucketName) { bucketName = null; if (string.IsNullOrEmpty(arn.Resource)) { return false; } if (arn.Resource.StartsWith(ResourceTypeBucketName + ":", StringComparison.Ordinal) || arn.Resource.StartsWith(ResourceTypeBucketName + "/", StringComparison.Ordinal)) { bucketName = arn.Resource.Substring(ResourceTypeBucketName.Length + 1); return true; } return false; } } }