Skip to content

Commit 0370df0

Browse files
Fix to respect environment specific cloud storage (#162)
* Fix to respect environment specific cloud storage * fix integration test --------- Co-authored-by: James Kwon <96548424+hongil0316@users.noreply.github.com>
1 parent 3aa3a99 commit 0370df0

File tree

4 files changed

+9
-34
lines changed

4 files changed

+9
-34
lines changed

gateways/storage/files.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package storage
22

33
import (
4-
"bytes"
54
"context"
65
"fmt"
76
"io"
@@ -18,7 +17,6 @@ import (
1817
// StorageService defines the interface for interacting with cloud storage.
1918
type StorageService interface {
2019
UploadFile(ctx context.Context, bucket, object, filePath string) (string, error)
21-
StreamFileUpload(w io.Writer, objectName, blob string) (string, string, error)
2220
GetFileUrl(ctx context.Context, bucketName, objectPath string) (string, error)
2321
GenerateSignedURL(bucketName, objectName string) (string, error)
2422
}
@@ -95,33 +93,6 @@ func (s *storageService) UploadFile(ctx context.Context, bucket, object, filePat
9593
return publicURL, nil
9694
}
9795

98-
// StreamFileUpload uploads an object via a stream to GCP storage.
99-
func (s *storageService) StreamFileUpload(w io.Writer, objectName, blob string) (string, string, error) {
100-
ctx := context.Background()
101-
102-
b := []byte(blob)
103-
buf := bytes.NewBuffer(b)
104-
105-
ctx, cancel := context.WithTimeout(ctx, time.Second*50)
106-
defer cancel()
107-
108-
// Upload the object as a stream
109-
wc := s.client.Bucket(s.config.CloudStorageBucketName).Object(objectName).NewWriter(ctx)
110-
wc.ChunkSize = 0 // Note: retries are not supported for chunk size 0
111-
112-
if _, err := io.Copy(wc, buf); err != nil {
113-
return "", "", fmt.Errorf("io.Copy: %w", err)
114-
}
115-
116-
if err := wc.Close(); err != nil {
117-
return "", "", fmt.Errorf("Writer.Close: %w", err)
118-
}
119-
120-
log.Ctx(ctx).Info().Msgf("%v uploaded to %v.\n", objectName, s.config.CloudStorageBucketName)
121-
122-
return s.config.CloudStorageBucketName, objectName, nil
123-
}
124-
12596
// GetFileUrl gets the public URL of a file from GCP storage.
12697
func (s *storageService) GetFileUrl(ctx context.Context, bucketName, objectPath string) (string, error) {
12798
defer tracing.TraceDefaultSegment(ctx, "StorageService.GetFileUrl")()

integration-tests/comfy_node_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ func TestRegistryComfyNode(t *testing.T) {
2121
defer cleanup()
2222

2323
// Initialize server implementation and authorization middleware
24-
impl := NewStrictServerImplementationWithMocks(client, &config.Config{})
24+
impl := NewStrictServerImplementationWithMocks(client, &config.Config{
25+
CloudStorageBucketName: "test-bucket",
26+
})
2527
authz := authorization.NewAuthorizationManager(client, impl.RegistryService, impl.NewRelicApp).AuthorizationMiddleware()
2628

2729
// Setup test user context and publisher

integration-tests/node_version_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ func TestRegistryNodeVersion(t *testing.T) {
2828
defer cleanup()
2929

3030
// Initialize server implementation and authorization middleware
31-
impl := NewStrictServerImplementationWithMocks(client, &config.Config{})
31+
impl := NewStrictServerImplementationWithMocks(client, &config.Config{
32+
CloudStorageBucketName: "test-bucket",
33+
})
3234
authz := authorization.NewAuthorizationManager(client, impl.RegistryService, impl.NewRelicApp).AuthorizationMiddleware()
3335

3436
// Setup user context and publisher
@@ -47,7 +49,7 @@ func TestRegistryNodeVersion(t *testing.T) {
4749
nodeVersion := randomNodeVersion(0)
4850
signedUrl := "test-url"
4951
downloadUrl := fmt.Sprintf(
50-
"https://storage.googleapis.com/comfy-registry/%s/%s/%s/node.zip", publisherId, *node.Id, *nodeVersion.Version)
52+
"https://storage.googleapis.com/test-bucket/%s/%s/%s/node.zip", publisherId, *node.Id, *nodeVersion.Version)
5153

5254
// Mock external service responses for storage and Discord
5355
impl.mockStorageService.
@@ -388,7 +390,7 @@ func TestRegistryNodeVersion(t *testing.T) {
388390
// Creating a new random node and version for scanning
389391
node := randomNode()
390392
nodeVersion := randomNodeVersion(0)
391-
downloadUrl := fmt.Sprintf("https://storage.googleapis.com/comfy-registry/%s/%s/%s/node.zip", publisherId, *node.Id, *nodeVersion.Version)
393+
downloadUrl := fmt.Sprintf("https://storage.googleapis.com/test-bucket/%s/%s/%s/node.zip", publisherId, *node.Id, *nodeVersion.Version)
392394

393395
// Mocking the behavior of services for URL generation and message sending
394396
impl.mockStorageService.On("GenerateSignedURL", mock.Anything, mock.Anything).Return("test-url", nil)

services/registry/registry_svc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ func (s *RegistryService) CreateNodeVersion(
389389

390390
log.Ctx(ctx).Info().Msgf(
391391
"creating node version: %v for nodeId %v", nodeVersion, nodeID)
392-
bucketName := "comfy-registry"
392+
bucketName := s.config.CloudStorageBucketName
393393
return db.WithTxResult(ctx, client, func(tx *ent.Tx) (*NodeVersionCreation, error) {
394394
// If the node version is not provided, we will generate a new version
395395
if nodeVersion.Version != nil {

0 commit comments

Comments
 (0)