github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/apiserver/facades/controller/remoterelations/state.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package remoterelations 5 6 import ( 7 "github.com/juju/errors" 8 "gopkg.in/juju/names.v2" 9 "gopkg.in/macaroon.v2-unstable" 10 11 common "github.com/juju/juju/apiserver/common/crossmodel" 12 "github.com/juju/juju/state" 13 ) 14 15 // RemoteRelationState provides the subset of global state required by the 16 // remote relations facade. 17 type RemoteRelationsState interface { 18 common.Backend 19 20 // WatchRemoteApplications returns a StringsWatcher that notifies of changes to 21 // the lifecycles of the remote applications in the model. 22 WatchRemoteApplications() state.StringsWatcher 23 24 // WatchRemoteApplicationRelations returns a StringsWatcher that notifies of 25 // changes to the lifecycles of relations involving the specified remote 26 // application. 27 WatchRemoteApplicationRelations(applicationName string) (state.StringsWatcher, error) 28 29 // WatchRemoteRelations returns a StringsWatcher that notifies of changes to 30 // the lifecycles of remote relations in the model. 31 WatchRemoteRelations() state.StringsWatcher 32 33 // RemoveRemoteEntity removes the specified entity from the remote entities collection. 34 RemoveRemoteEntity(entity names.Tag) error 35 36 // SaveMacaroon saves the given macaroon for the specified entity. 37 SaveMacaroon(entity names.Tag, mac *macaroon.Macaroon) error 38 } 39 40 // TODO - CAAS(ericclaudejones): This should contain state alone, model will be 41 // removed once all relevant methods are moved from state to model. 42 type stateShim struct { 43 common.Backend 44 st *state.State 45 } 46 47 func (st stateShim) RemoveRemoteEntity(entity names.Tag) error { 48 r := st.st.RemoteEntities() 49 return r.RemoveRemoteEntity(entity) 50 } 51 52 func (st stateShim) GetToken(entity names.Tag) (string, error) { 53 r := st.st.RemoteEntities() 54 return r.GetToken(entity) 55 } 56 57 func (st stateShim) SaveMacaroon(entity names.Tag, mac *macaroon.Macaroon) error { 58 r := st.st.RemoteEntities() 59 return r.SaveMacaroon(entity, mac) 60 } 61 62 func (st stateShim) WatchRemoteApplications() state.StringsWatcher { 63 return st.st.WatchRemoteApplications() 64 } 65 66 func (st stateShim) WatchRemoteRelations() state.StringsWatcher { 67 return st.st.WatchRemoteRelations() 68 } 69 70 func (st stateShim) WatchRemoteApplicationRelations(applicationName string) (state.StringsWatcher, error) { 71 a, err := st.st.RemoteApplication(applicationName) 72 if err != nil { 73 return nil, errors.Trace(err) 74 } 75 return a.WatchRelations(), nil 76 }