github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/apiserver/facades/controller/caasfirewaller/state.go (about) 1 // Copyright 2017 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package caasfirewaller 5 6 import ( 7 "github.com/juju/names/v5" 8 9 charmscommon "github.com/juju/juju/apiserver/common/charms" 10 "github.com/juju/juju/core/config" 11 "github.com/juju/juju/core/network" 12 "github.com/juju/juju/state" 13 ) 14 15 // CAASFirewallerState provides the subset of global state 16 // required by the CAAS operator facade. 17 type CAASFirewallerState interface { 18 FindEntity(tag names.Tag) (state.Entity, error) 19 Application(string) (Application, error) 20 21 WatchApplications() state.StringsWatcher 22 WatchOpenedPorts() state.StringsWatcher 23 } 24 25 // Application provides the subset of application state 26 // required by the CAAS operator facade. 27 type Application interface { 28 IsExposed() bool 29 ApplicationConfig() (config.ConfigAttributes, error) 30 Watch() state.NotifyWatcher 31 Charm() (ch charmscommon.Charm, force bool, err error) 32 OpenedPortRanges() (network.GroupedPortRanges, error) 33 } 34 35 type stateShim struct { 36 *state.State 37 } 38 39 func (s *stateShim) Application(id string) (Application, error) { 40 app, err := s.State.Application(id) 41 if err != nil { 42 return nil, err 43 } 44 return &applicationShim{app}, nil 45 } 46 47 type applicationShim struct { 48 *state.Application 49 } 50 51 func (a *applicationShim) Charm() (charmscommon.Charm, bool, error) { 52 return a.Application.Charm() 53 } 54 55 func (a *applicationShim) OpenedPortRanges() (network.GroupedPortRanges, error) { 56 pg, err := a.Application.OpenedPortRanges() 57 if err != nil { 58 return nil, err 59 } 60 return pg.ByEndpoint(), nil 61 }