~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/apiserver/testing/fakeauthorizer.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package testing
 
5
 
 
6
import (
 
7
        "gopkg.in/juju/names.v2"
 
8
 
 
9
        "github.com/juju/juju/core/description"
 
10
)
 
11
 
 
12
// FakeAuthorizer implements the facade.Authorizer interface.
 
13
type FakeAuthorizer struct {
 
14
        Tag            names.Tag
 
15
        EnvironManager bool
 
16
}
 
17
 
 
18
func (fa FakeAuthorizer) AuthOwner(tag names.Tag) bool {
 
19
        return fa.Tag == tag
 
20
}
 
21
 
 
22
func (fa FakeAuthorizer) AuthModelManager() bool {
 
23
        return fa.EnvironManager
 
24
}
 
25
 
 
26
// AuthMachineAgent returns whether the current client is a machine agent.
 
27
func (fa FakeAuthorizer) AuthMachineAgent() bool {
 
28
        _, isMachine := fa.GetAuthTag().(names.MachineTag)
 
29
        return isMachine
 
30
}
 
31
 
 
32
// AuthUnitAgent returns whether the current client is a unit agent.
 
33
func (fa FakeAuthorizer) AuthUnitAgent() bool {
 
34
        _, isUnit := fa.GetAuthTag().(names.UnitTag)
 
35
        return isUnit
 
36
}
 
37
 
 
38
// AuthClient returns whether the authenticated entity is a client
 
39
// user.
 
40
func (fa FakeAuthorizer) AuthClient() bool {
 
41
        _, isUser := fa.GetAuthTag().(names.UserTag)
 
42
        return isUser
 
43
}
 
44
 
 
45
func (fa FakeAuthorizer) GetAuthTag() names.Tag {
 
46
        return fa.Tag
 
47
}
 
48
 
 
49
func (fa FakeAuthorizer) HasPermission(operation description.Access, target names.Tag) (bool, error) {
 
50
        // TODO(perrito666) provide a way to pre-set the desired result here.
 
51
        return fa.Tag == target, nil
 
52
}