github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/apiserver/facades/controller/charmrevisionupdater/interface.go (about) 1 // Copyright 2020 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package charmrevisionupdater 5 6 import ( 7 "github.com/juju/charm/v12" 8 "github.com/juju/errors" 9 "github.com/juju/names/v5" 10 11 "github.com/juju/juju/apiserver/common" 12 "github.com/juju/juju/cloud" 13 "github.com/juju/juju/environs/config" 14 "github.com/juju/juju/state" 15 ) 16 17 // State is the subset of *state.State that we need. 18 type State interface { 19 AddCharmPlaceholder(curl *charm.URL) error 20 AllApplications() ([]Application, error) 21 Charm(curl string) (*state.Charm, error) 22 Cloud(name string) (cloud.Cloud, error) 23 ControllerUUID() string 24 Model() (Model, error) 25 Resources() state.Resources 26 AliveRelationKeys() []string 27 } 28 29 // Application is the subset of *state.Application that we need. 30 type Application interface { 31 CharmURL() (curl *string, force bool) 32 CharmOrigin() *state.CharmOrigin 33 ApplicationTag() names.ApplicationTag 34 UnitCount() int 35 } 36 37 // Model is the subset of *state.Model that we need. 38 type Model interface { 39 CloudName() string 40 CloudRegion() string 41 Config() (*config.Config, error) 42 IsControllerModel() bool 43 Metrics() (state.ModelMetrics, error) 44 ModelTag() names.ModelTag 45 UUID() string 46 } 47 48 // StateShim takes a *state.State and implements this package's State interface. 49 type StateShim struct { 50 *state.State 51 } 52 53 func (s StateShim) AllApplications() ([]Application, error) { 54 stateApps, err := s.State.AllApplications() 55 if err != nil { 56 return nil, errors.Trace(err) 57 } 58 apps := make([]Application, len(stateApps)) 59 for i, a := range stateApps { 60 apps[i] = a 61 } 62 return apps, nil 63 } 64 65 func (s StateShim) Model() (Model, error) { 66 return s.State.Model() 67 } 68 69 // charmhubClientStateShim takes a *state.State and implements common.ModelGetter. 70 type charmhubClientStateShim struct { 71 state State 72 } 73 74 func (s charmhubClientStateShim) Model() (common.ConfigModel, error) { 75 return s.state.Model() 76 }