github.com/juju/juju@v0.0.0-20240327075706-a90865de2538/worker/controlsocket/shim.go (about) 1 // Copyright 2023 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package controlsocket 5 6 import ( 7 "github.com/juju/errors" 8 "github.com/juju/names/v5" 9 10 "github.com/juju/juju/core/permission" 11 "github.com/juju/juju/state" 12 ) 13 14 // State defines the state methods that the controlsocket worker needs. 15 type State interface { 16 User(tag names.UserTag) (user, error) 17 AddUser(name string, displayName string, password string, creator string) (user, error) 18 RemoveUser(tag names.UserTag) error 19 Model() (model, error) 20 } 21 22 // stateShim allows the real state to implement State. 23 type stateShim struct { 24 st *state.State 25 } 26 27 func (s stateShim) User(tag names.UserTag) (user, error) { 28 u, err := s.st.User(tag) 29 return u, errors.Trace(err) 30 } 31 32 func (s stateShim) AddUser(name, displayName, password, creator string) (user, error) { 33 u, err := s.st.AddUser(name, displayName, password, creator) 34 return u, errors.Trace(err) 35 } 36 37 func (s stateShim) Model() (model, error) { 38 m, err := s.st.Model() 39 return m, errors.Trace(err) 40 } 41 42 func (s stateShim) RemoveUser(tag names.UserTag) error { 43 return errors.Trace(s.st.RemoveUser(tag)) 44 } 45 46 // model defines the model methods that the controlsocket worker needs. 47 type model interface { 48 AddUser(state.UserAccessSpec) (permission.UserAccess, error) 49 } 50 51 // user defines the user methods that the controlsocket worker needs. 52 type user interface { 53 Name() string 54 CreatedBy() string 55 UserTag() names.UserTag 56 PasswordValid(string) bool 57 }