github.com/juju/juju@v0.0.0-20240327075706-a90865de2538/api/controller/caasmodelconfigmanager/client.go (about) 1 // Copyright 2021 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package caasmodelconfigmanager 5 6 import ( 7 "github.com/juju/errors" 8 9 "github.com/juju/juju/api/base" 10 "github.com/juju/juju/api/common" 11 apiwatcher "github.com/juju/juju/api/watcher" 12 "github.com/juju/juju/core/watcher" 13 "github.com/juju/juju/rpc/params" 14 ) 15 16 // Client allows access to the CAAS model config manager API endpoint. 17 type Client struct { 18 facade base.FacadeCaller 19 *common.ControllerConfigAPI 20 } 21 22 // NewClient returns a client used to access the CAAS Application Provisioner API. 23 func NewClient(caller base.APICaller) (*Client, error) { 24 _, isModel := caller.ModelTag() 25 if !isModel { 26 return nil, errors.New("expected model specific API connection") 27 } 28 facadeCaller := base.NewFacadeCaller(caller, "CAASModelConfigManager") 29 return &Client{ 30 facade: facadeCaller, 31 ControllerConfigAPI: common.NewControllerConfig(facadeCaller), 32 }, nil 33 } 34 35 // WatchControllerConfig provides a watcher for changes on controller config. 36 func (c *Client) WatchControllerConfig() (watcher.NotifyWatcher, error) { 37 var result params.NotifyWatchResult 38 if err := c.facade.FacadeCall("WatchControllerConfig", nil, &result); err != nil { 39 return nil, err 40 } 41 if result.Error != nil { 42 return nil, result.Error 43 } 44 return apiwatcher.NewNotifyWatcher(c.facade.RawAPICaller(), result), nil 45 }