File tree Expand file tree Collapse file tree 2 files changed +29
-6
lines changed
Expand file tree Collapse file tree 2 files changed +29
-6
lines changed Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff line change 11package 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.
410type 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+ }
You can’t perform that action at this time.
0 commit comments