Skip to content

Commit a22caee

Browse files
feat(storagecontrol): managed folders samples (#2708)
1 parent b7ee90a commit a22caee

8 files changed

Lines changed: 304 additions & 0 deletions
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License").
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using Xunit;
16+
17+
namespace Storage.Samples.Tests;
18+
19+
[Collection(nameof(StorageFixture))]
20+
public class StorageControlCreateManagedFolderTest
21+
{
22+
private readonly StorageFixture _fixture;
23+
24+
public StorageControlCreateManagedFolderTest(StorageFixture fixture)
25+
{
26+
_fixture = fixture;
27+
}
28+
29+
[Fact]
30+
public void TestStorageControlCreateManagedFolder()
31+
{
32+
StorageControlCreateManagedFolderSample sample = new StorageControlCreateManagedFolderSample();
33+
var managedFolder = sample.StorageControlCreateManagedFolder(_fixture.BucketNameHns, "createTestManagedFolder");
34+
Assert.Contains("createTestManagedFolder", managedFolder.Name);
35+
}
36+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License").
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using Xunit;
16+
17+
namespace Storage.Samples.Tests;
18+
19+
[Collection(nameof(StorageFixture))]
20+
public class StorageControlDeleteManagedFolderTest
21+
{
22+
private readonly StorageFixture _fixture;
23+
24+
public StorageControlDeleteManagedFolderTest(StorageFixture fixture)
25+
{
26+
_fixture = fixture;
27+
}
28+
29+
[Fact]
30+
public void TestStorageControlDeleteManagedFolder()
31+
{
32+
StorageControlCreateManagedFolderSample createSample = new StorageControlCreateManagedFolderSample();
33+
var managedFolder = createSample.StorageControlCreateManagedFolder(_fixture.BucketNameHns, "deleteTestManagedFolder");
34+
35+
StorageControlDeleteManagedFolderSample deleteSample = new StorageControlDeleteManagedFolderSample();
36+
deleteSample.StorageControlDeleteManagedFolder(_fixture.BucketNameHns, "deleteTestManagedFolder");
37+
38+
StorageControlListManagedFoldersSample listManagedFoldersSample = new StorageControlListManagedFoldersSample();
39+
var managedFolders = listManagedFoldersSample.StorageControlListManagedFolders(_fixture.BucketNameHns);
40+
41+
Assert.DoesNotContain(managedFolder, managedFolders);
42+
}
43+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License").
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using Xunit;
16+
17+
namespace Storage.Samples.Tests;
18+
19+
[Collection(nameof(StorageFixture))]
20+
public class StorageControlGetManagedFolderTest
21+
{
22+
private readonly StorageFixture _fixture;
23+
24+
public StorageControlGetManagedFolderTest(StorageFixture fixture)
25+
{
26+
_fixture = fixture;
27+
}
28+
29+
[Fact]
30+
public void TestStorageControlGetManagedFolder()
31+
{
32+
StorageControlCreateManagedFolderSample createManagedFolderSample = new StorageControlCreateManagedFolderSample();
33+
createManagedFolderSample.StorageControlCreateManagedFolder(_fixture.BucketNameHns, "getTestManagedFolder");
34+
35+
StorageControlGetManagedFolderSample getManagedFolderSample = new StorageControlGetManagedFolderSample();
36+
var managedFolder = getManagedFolderSample.StorageControlGetManagedFolder(_fixture.BucketNameHns, "getTestManagedFolder");
37+
38+
Assert.Contains("getTestManagedFolder", managedFolder.Name);
39+
}
40+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License").
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using Xunit;
16+
17+
namespace Storage.Samples.Tests;
18+
19+
[Collection(nameof(StorageFixture))]
20+
public class StorageControlListManagedFoldersTest
21+
{
22+
private readonly StorageFixture _fixture;
23+
24+
public StorageControlListManagedFoldersTest(StorageFixture fixture)
25+
{
26+
_fixture = fixture;
27+
}
28+
29+
[Fact]
30+
public void TestStorageControlListManagedFolders()
31+
{
32+
StorageControlCreateManagedFolderSample createSample = new StorageControlCreateManagedFolderSample();
33+
var managedFolder = createSample.StorageControlCreateManagedFolder(_fixture.BucketNameHns, "listTestManagedFolder");
34+
35+
StorageControlListManagedFoldersSample listSample = new StorageControlListManagedFoldersSample();
36+
var managedFolders = listSample.StorageControlListManagedFolders(_fixture.BucketNameHns);
37+
38+
Assert.Contains(managedFolder, managedFolders);
39+
}
40+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License").
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// [START storage_control_managed_folder_create]
16+
using Google.Cloud.Storage.Control.V2;
17+
using System;
18+
19+
public class StorageControlCreateManagedFolderSample
20+
{
21+
public ManagedFolder StorageControlCreateManagedFolder(string bucketId = "your-unique-bucket-name",
22+
string managedFolderId = "your_managed_folder_id")
23+
{
24+
StorageControlClient storageControl = StorageControlClient.Create();
25+
26+
ManagedFolder managedFolder = storageControl.CreateManagedFolder(
27+
// Set project to "_" to signify globally scoped bucket
28+
new BucketName("_", bucketId),
29+
new ManagedFolder(),
30+
managedFolderId
31+
);
32+
33+
Console.WriteLine($"Managed Folder {managedFolderId} created in bucket {bucketId}");
34+
return managedFolder;
35+
}
36+
}
37+
// [END storage_control_managed_folder_create]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License").
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// [START storage_control_managed_folder_delete]
16+
using Google.Cloud.Storage.Control.V2;
17+
using System;
18+
19+
public class StorageControlDeleteManagedFolderSample
20+
{
21+
public void StorageControlDeleteManagedFolder(string bucketId = "your-unique-bucket-name",
22+
string managedFolderId = "your_managed_folder_id")
23+
{
24+
StorageControlClient storageControl = StorageControlClient.Create();
25+
26+
ManagedFolderName managedFolderResourceName =
27+
// Set project to "_" to signify globally scoped bucket
28+
new ManagedFolderName("_", bucketId, managedFolderId);
29+
30+
storageControl.DeleteManagedFolder(managedFolderResourceName);
31+
32+
Console.WriteLine($"Deleted managed folder {managedFolderId} from bucket {bucketId}");
33+
}
34+
}
35+
// [END storage_control_managed_folder_delete]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License").
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// [START storage_control_managed_folder_get]
16+
using Google.Cloud.Storage.Control.V2;
17+
using System;
18+
19+
public class StorageControlGetManagedFolderSample
20+
{
21+
public ManagedFolder StorageControlGetManagedFolder(string bucketId = "your-unique-bucket-name",
22+
string managedFolderId = "your_managed_folder_Id")
23+
{
24+
StorageControlClient storageControl = StorageControlClient.Create();
25+
26+
ManagedFolderName managedFolderResourceName =
27+
// Set project to "_" to signify globally scoped bucket
28+
new ManagedFolderName("_", bucketId, managedFolderId);
29+
30+
ManagedFolder managedFolder = storageControl.GetManagedFolder(managedFolderResourceName);
31+
32+
Console.WriteLine($"Got managed folder: {managedFolder.Name}");
33+
return managedFolder;
34+
}
35+
}
36+
// [END storage_control_managed_folder_get]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License").
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// [START storage_control_managed_folder_list]
16+
using Google.Cloud.Storage.Control.V2;
17+
using System;
18+
using System.Collections.Generic;
19+
20+
public class StorageControlListManagedFoldersSample
21+
{
22+
public IEnumerable<ManagedFolder> StorageControlListManagedFolders(string bucketId = "your-unique-bucket-name")
23+
{
24+
StorageControlClient storageControl = StorageControlClient.Create();
25+
26+
// Use "_" for project ID to signify globally scoped bucket
27+
BucketName bucketResourceName = new BucketName("_", bucketId);
28+
var managedFolders = storageControl.ListManagedFolders(bucketResourceName);
29+
30+
foreach (var managedFolder in managedFolders)
31+
{
32+
Console.Write(managedFolder.Name);
33+
}
34+
return managedFolders;
35+
}
36+
}
37+
// [END storage_control_managed_folder_list]

0 commit comments

Comments
 (0)