Skip to content

Commit

Permalink
feat: Add support for glob pattern storage
Browse files Browse the repository at this point in the history
  • Loading branch information
hemanshv committed Jun 1, 2023
1 parent 634e1e8 commit d0e4541
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
Expand Up @@ -72,6 +72,17 @@ public async Task PrefixAndDelimiter(string prefix, string expectedNames)
await AssertObjects(prefix, options, expectedNames.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
}

[Theory]
[InlineData("la*", "large.txt")]
[InlineData("a/*.txt", "a/o1.txt", "a/o2.txt")]
[InlineData("a/x/*.txt", "a/x/o3.txt", "a/x/o4.txt")]
public void MatchGlob(string globPattern, params string[] expectedNames)
{
var options = new ListObjectsOptions { MatchGlob = globPattern };
IEnumerable<Object> actual = _fixture.Client.ListObjects(_fixture.ReadBucket, prefix: null, options);
AssertObjectNames(actual, expectedNames);
}

[Fact]
public async Task CancellationTokenRespected()
{
Expand Down
Expand Up @@ -35,6 +35,7 @@ public void ModifyRequest_DefaultOptions()
Assert.Null(request.PageToken);
Assert.Null(request.StartOffset);
Assert.Null(request.EndOffset);
Assert.Null(request.MatchGlob);
}

[Fact]
Expand All @@ -52,7 +53,8 @@ public void ModifyRequest_AllOptions()
PageToken = "nextpage",
Fields = "items(name),nextPageToken",
StartOffset = "start",
EndOffset = "end"
EndOffset = "end",
MatchGlob = "a/*.txt"
};
options.ModifyRequest(request);
Assert.Equal(10, request.MaxResults);
Expand All @@ -65,6 +67,7 @@ public void ModifyRequest_AllOptions()
Assert.Equal("items(name),nextPageToken", request.Fields);
Assert.Equal("start", request.StartOffset);
Assert.Equal("end", request.EndOffset);
Assert.Equal("a/*.txt", request.MatchGlob);
}
}
}
Expand Up @@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="ConfigureAwaitChecker.Analyzer" Version="5.0.0" PrivateAssets="All" />
<PackageReference Include="Google.Api.Gax.Rest" Version="[4.4.0, 5.0.0)" />
<PackageReference Include="Google.Apis.Storage.v1" Version="[1.60.0.2742, 2.0.0.0)" />
<PackageReference Include="Google.Apis.Storage.v1" Version="[1.60.0.2981, 2.0.0.0)" />
</ItemGroup>
<ItemGroup>
<Compile Update="StorageClient.*.cs">
Expand Down
Expand Up @@ -56,6 +56,12 @@ public sealed class ListObjectsOptions
/// </summary>
public Projection? Projection { get; set; }

/// <summary>
/// A glob pattern used to filter results. See https://cloud.google.com/storage/docs/json_api/v1/objects/list#list-object-glob
/// for more details.
/// </summary>
public string MatchGlob { get; set; }

/// <summary>
/// If set, this is the ID of the project which will be billed for the request.
/// The caller must have suitable permissions for the project being billed.
Expand Down Expand Up @@ -143,6 +149,10 @@ internal void ModifyRequest(ListRequest request)
{
request.EndOffset = EndOffset;
}
if (MatchGlob != null)
{
request.MatchGlob = MatchGlob;
}
}
}
}
2 changes: 1 addition & 1 deletion apis/apis.json
Expand Up @@ -4247,7 +4247,7 @@
"description": "Recommended Google client library to access the Google Cloud Storage API. It wraps the Google.Apis.Storage.v1 client library, making common operations simpler in client code. Google Cloud Storage stores and retrieves potentially large, immutable data objects.",
"dependencies": {
"Google.Api.Gax.Rest": "4.4.0",
"Google.Apis.Storage.v1": "1.60.0.2742"
"Google.Apis.Storage.v1": "1.60.0.2981"
},
"testDependencies": {
"Google.Api.Gax.Testing": "4.4.0",
Expand Down

0 comments on commit d0e4541

Please sign in to comment.