Skip to content

Commit 046282e

Browse files
committed
feat: auto select cloud provider based on config
1 parent cfbddc6 commit 046282e

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

cmd/node/main.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,7 @@ func main() {
173173
os.Exit(1)
174174
}
175175

176-
//TODO: make this auto select a provider based on config
177-
cloudStorage, err := cloud.NewGCSBucket(
178-
context.Background(),
179-
cfg.Cloud.BucketName,
180-
cfg.Cloud.GCPCredentialJSONPath,
181-
)
176+
cloudStorage, err := cloud.NewCloudProvider(context.Background(), cfg.Cloud)
182177
if err != nil {
183178
logger.Errorf("failed to create cloud storage: %v", err)
184179
os.Exit(1)

internal/cloud/cloud.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package cloud
22

3+
import (
4+
"context"
5+
"fmt"
6+
"zenGate-Global/merkle-oracle-node/internal/config"
7+
)
8+
39
// Ref is an opaque reference to a blob stored in the cloud.
410
type Ref string
511

@@ -14,3 +20,25 @@ type Cloud interface {
1420
// It returns the raw bytes or an error if the read fails.
1521
Read(ref Ref) ([]byte, error)
1622
}
23+
24+
// NewCloudProvider automatically selects and creates the appropriate cloud provider based on configuration
25+
func NewCloudProvider(
26+
ctx context.Context,
27+
config config.CloudConfig,
28+
) (Cloud, error) {
29+
hasPinata := config.PinataJWT != ""
30+
31+
hasGCP := config.GCPCredentialJSONPath != "" && config.BucketName != ""
32+
33+
if hasGCP {
34+
return NewGCSBucket(
35+
ctx,
36+
config.BucketName,
37+
config.GCPCredentialJSONPath,
38+
)
39+
} else if hasPinata {
40+
return NewPinataCloud(config.PinataJWT, config.PinataGatewayURL)
41+
} else {
42+
return nil, fmt.Errorf("no cloud storage provider configured: please provide either Pinata JWT or GCP credentials")
43+
}
44+
}

0 commit comments

Comments
 (0)