github.com/cozy/cozy-stack@v0.0.0-20240327093429-939e4a21320e/model/cloudery/init.go (about) 1 package cloudery 2 3 import ( 4 "github.com/cozy/cozy-stack/model/instance" 5 "github.com/cozy/cozy-stack/pkg/config/config" 6 ) 7 8 var service Service 9 10 // Service handle all the interactions with the cloudery 11 // 12 // Several implementations exists: 13 // - [ClouderyService] interacts via HTTP 14 // - [NoopService] when no config is setup 15 // - [Mock] for the tests 16 type Service interface { 17 SaveInstance(inst *instance.Instance, cmd *SaveCmd) error 18 HasBlockingSubscription(inst *instance.Instance) (bool, error) 19 } 20 21 func Init(contexts map[string]config.ClouderyConfig) Service { 22 if contexts == nil { 23 service = new(NoopService) 24 return service 25 } 26 27 service = NewService(contexts) 28 return service 29 } 30 31 // SaveInstance data into the cloudery matching the instance context. 32 // 33 // Deprecated: Use [ClouderyService.SaveInstance] instead. 34 func SaveInstance(inst *instance.Instance, cmd *SaveCmd) error { 35 return service.SaveInstance(inst, cmd) 36 }