github.com/mwhudson/juju@v0.0.0-20160512215208-90ff01f3497f/apiserver/lifeflag/facade.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package lifeflag
     5  
     6  import (
     7  	"github.com/juju/names"
     8  
     9  	"github.com/juju/juju/apiserver/common"
    10  	"github.com/juju/juju/state"
    11  )
    12  
    13  type Backend interface {
    14  	ModelUUID() string
    15  	state.EntityFinder
    16  }
    17  
    18  func NewFacade(backend Backend, resources *common.Resources, authorizer common.Authorizer) (*Facade, error) {
    19  	if !authorizer.AuthModelManager() {
    20  		return nil, common.ErrPerm
    21  	}
    22  	expect := names.NewModelTag(backend.ModelUUID())
    23  	getCanAccess := func() (common.AuthFunc, error) {
    24  		return func(tag names.Tag) bool {
    25  			return tag == expect
    26  		}, nil
    27  	}
    28  	life := common.NewLifeGetter(backend, getCanAccess)
    29  	watch := common.NewAgentEntityWatcher(backend, resources, getCanAccess)
    30  	return &Facade{
    31  		LifeGetter:         life,
    32  		AgentEntityWatcher: watch,
    33  	}, nil
    34  }
    35  
    36  type Facade struct {
    37  	*common.LifeGetter
    38  	*common.AgentEntityWatcher
    39  }