[GH-ISSUE #1651] Updating a bucket returns 404 #211

Open
opened 2026-03-03 12:09:11 +03:00 by kerem · 1 comment
Owner

Originally created by @airzym on GitHub (Jun 21, 2024).
Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/1651

I'm trying to create a bucket with versioning enabled.

I've followed Google Cloud documentation here, with the addition of creating the bucket, my code looks like the following:

public class LocalEmulatorStorageClientProvider : IStorageClientProvider
{
    public const string BucketName = "test-bucket";
    
    public async Task<StorageClient> CreateStorageClient()
    {
        var storageClient = await new StorageClientBuilder
        {
            BaseUri = "http://localhost:8083/storage/v1/",
            UnauthenticatedAccess = true,
        }.BuildAsync();

        if (!BucketExists(storageClient, BucketName))
        {
            await storageClient.CreateBucketAsync("test-project", BucketName);
            var bucket = await storageClient.GetBucketAsync(BucketName);
            bucket.Versioning = new Bucket.VersioningData
            {
                Enabled = true
            };
            await storageClient.UpdateBucketAsync(bucket);
        }
        
        return storageClient;
    }

    private bool BucketExists(StorageClient storageClient, string bucketName)
    {
        try
        {
            storageClient.GetBucket(bucketName);
            return true;
        }
        catch (Exception ex)
        {
            return false;
        }
    }
}

I'm running into a problem where the client throws when calling UpdateBucketAsync() with the following exception: The service storage has thrown an exception. HttpStatusCode is NotFound. Not Found which corresponds to the fake-gcs-server container logs:

2024-06-21 07:39:33 time=2024-06-21T06:39:33.521Z level=INFO msg="server started at http://0.0.0.0:8083"
2024-06-21 07:40:01 time=2024-06-21T06:40:01.553Z level=INFO msg="192.168.65.1 - - [21/Jun/2024:06:40:01 +0000] \"GET /storage/v1/b/test-bucket HTTP/1.1\" 404 119\n"
2024-06-21 07:40:14 time=2024-06-21T06:40:14.256Z level=INFO msg="192.168.65.1 - - [21/Jun/2024:06:40:14 +0000] \"POST /storage/v1/b?project=test-project HTTP/1.1\" 200 345\n"
2024-06-21 07:40:14 time=2024-06-21T06:40:14.291Z level=INFO msg="192.168.65.1 - - [21/Jun/2024:06:40:14 +0000] \"GET /storage/v1/b/test-bucket HTTP/1.1\" 200 345\n"
2024-06-21 07:40:35 time=2024-06-21T06:40:35.034Z level=INFO msg="192.168.65.1 - - [21/Jun/2024:06:40:35 +0000] \"PUT /storage/v1/b/test-bucket HTTP/1.1\" 404 119\n"

Theres nothing I can spot in the docs that suggest I'm missing something here.

Originally created by @airzym on GitHub (Jun 21, 2024). Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/1651 I'm trying to create a bucket with versioning enabled. I've followed Google Cloud documentation [here](https://cloud.google.com/storage/docs/samples/storage-enable-versioning#storage_enable_versioning-csharp), with the addition of creating the bucket, my code looks like the following: ```csharp public class LocalEmulatorStorageClientProvider : IStorageClientProvider { public const string BucketName = "test-bucket"; public async Task<StorageClient> CreateStorageClient() { var storageClient = await new StorageClientBuilder { BaseUri = "http://localhost:8083/storage/v1/", UnauthenticatedAccess = true, }.BuildAsync(); if (!BucketExists(storageClient, BucketName)) { await storageClient.CreateBucketAsync("test-project", BucketName); var bucket = await storageClient.GetBucketAsync(BucketName); bucket.Versioning = new Bucket.VersioningData { Enabled = true }; await storageClient.UpdateBucketAsync(bucket); } return storageClient; } private bool BucketExists(StorageClient storageClient, string bucketName) { try { storageClient.GetBucket(bucketName); return true; } catch (Exception ex) { return false; } } } ``` I'm running into a problem where the client throws when calling `UpdateBucketAsync()` with the following exception: `The service storage has thrown an exception. HttpStatusCode is NotFound. Not Found` which corresponds to the `fake-gcs-server` container logs: ``` 2024-06-21 07:39:33 time=2024-06-21T06:39:33.521Z level=INFO msg="server started at http://0.0.0.0:8083" 2024-06-21 07:40:01 time=2024-06-21T06:40:01.553Z level=INFO msg="192.168.65.1 - - [21/Jun/2024:06:40:01 +0000] \"GET /storage/v1/b/test-bucket HTTP/1.1\" 404 119\n" 2024-06-21 07:40:14 time=2024-06-21T06:40:14.256Z level=INFO msg="192.168.65.1 - - [21/Jun/2024:06:40:14 +0000] \"POST /storage/v1/b?project=test-project HTTP/1.1\" 200 345\n" 2024-06-21 07:40:14 time=2024-06-21T06:40:14.291Z level=INFO msg="192.168.65.1 - - [21/Jun/2024:06:40:14 +0000] \"GET /storage/v1/b/test-bucket HTTP/1.1\" 200 345\n" 2024-06-21 07:40:35 time=2024-06-21T06:40:35.034Z level=INFO msg="192.168.65.1 - - [21/Jun/2024:06:40:35 +0000] \"PUT /storage/v1/b/test-bucket HTTP/1.1\" 404 119\n" ``` Theres nothing I can spot in the docs that suggest I'm missing something here.
Author
Owner

@christophergunn commented on GitHub (Jun 21, 2024):

It looks like your failing request is a PUT request to update a bucket. I'm no GoLang expert, but it seems that the code doesn't support PUT requests on that route:

server.go

<!-- gh-comment-id:2182191206 --> @christophergunn commented on GitHub (Jun 21, 2024): It looks like your failing request is a `PUT` request to update a bucket. I'm no GoLang expert, but it seems that the code doesn't support `PUT` requests on that route: [server.go](https://github.com/fsouza/fake-gcs-server/blob/73c48fc47ecf5b9bf3e1db182ad7fab477b56cb5/fakestorage/server.go#L264)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/fake-gcs-server#211
No description provided.