github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/apiserver/testing/fakeauthorizer.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package testing 5 6 import ( 7 "github.com/juju/names" 8 ) 9 10 // FakeAuthorizer implements the common.Authorizer interface. 11 type FakeAuthorizer struct { 12 Tag names.Tag 13 EnvironManager bool 14 } 15 16 func (fa FakeAuthorizer) AuthOwner(tag names.Tag) bool { 17 return fa.Tag == tag 18 } 19 20 func (fa FakeAuthorizer) AuthModelManager() bool { 21 return fa.EnvironManager 22 } 23 24 // AuthMachineAgent returns whether the current client is a machine agent. 25 func (fa FakeAuthorizer) AuthMachineAgent() bool { 26 _, isMachine := fa.GetAuthTag().(names.MachineTag) 27 return isMachine 28 } 29 30 // AuthUnitAgent returns whether the current client is a unit agent. 31 func (fa FakeAuthorizer) AuthUnitAgent() bool { 32 _, isUnit := fa.GetAuthTag().(names.UnitTag) 33 return isUnit 34 } 35 36 // AuthClient returns whether the authenticated entity is a client 37 // user. 38 func (fa FakeAuthorizer) AuthClient() bool { 39 _, isUser := fa.GetAuthTag().(names.UserTag) 40 return isUser 41 } 42 43 func (fa FakeAuthorizer) GetAuthTag() names.Tag { 44 return fa.Tag 45 }