func (s *statusGetterSuite) SetUpTest(c *gc.C) { s.statusBaseSuite.SetUpTest(c) s.getter = common.NewStatusGetter(s.State, func() (common.AuthFunc, error) { return s.authFunc, nil }) }
// NewProvisionerAPI creates a new server-side ProvisionerAPI facade. func NewProvisionerAPI(st *state.State, resources *common.Resources, authorizer common.Authorizer) (*ProvisionerAPI, error) { if !authorizer.AuthMachineAgent() && !authorizer.AuthEnvironManager() { return nil, common.ErrPerm } getAuthFunc := func() (common.AuthFunc, error) { isEnvironManager := authorizer.AuthEnvironManager() isMachineAgent := authorizer.AuthMachineAgent() authEntityTag := authorizer.GetAuthTag() return func(tag names.Tag) bool { if isMachineAgent && tag == authEntityTag { // A machine agent can always access its own machine. return true } switch tag := tag.(type) { case names.MachineTag: parentId := state.ParentId(tag.Id()) if parentId == "" { // All top-level machines are accessible by the // environment manager. return isEnvironManager } // All containers with the authenticated machine as a // parent are accessible by it. // TODO(dfc) sometimes authEntity tag is nil, which is fine because nil is // only equal to nil, but it suggests someone is passing an authorizer // with a nil tag. return isMachineAgent && names.NewMachineTag(parentId) == authEntityTag default: return false } }, nil } env, err := st.Environment() if err != nil { return nil, err } urlGetter := common.NewToolsURLGetter(env.UUID(), st) return &ProvisionerAPI{ Remover: common.NewRemover(st, false, getAuthFunc), StatusSetter: common.NewStatusSetter(st, getAuthFunc), StatusGetter: common.NewStatusGetter(st, getAuthFunc), DeadEnsurer: common.NewDeadEnsurer(st, getAuthFunc), PasswordChanger: common.NewPasswordChanger(st, getAuthFunc), LifeGetter: common.NewLifeGetter(st, getAuthFunc), StateAddresser: common.NewStateAddresser(st), APIAddresser: common.NewAPIAddresser(st, resources), EnvironWatcher: common.NewEnvironWatcher(st, resources, authorizer), EnvironMachinesWatcher: common.NewEnvironMachinesWatcher(st, resources, authorizer), InstanceIdGetter: common.NewInstanceIdGetter(st, getAuthFunc), ToolsFinder: common.NewToolsFinder(st, st, urlGetter), st: st, resources: resources, authorizer: authorizer, getAuthFunc: getAuthFunc, }, nil }
// NewInstancePollerAPI creates a new server-side InstancePoller API // facade. func NewInstancePollerAPI( st *state.State, resources facade.Resources, authorizer facade.Authorizer, clock clock.Clock, ) (*InstancePollerAPI, error) { if !authorizer.AuthModelManager() { // InstancePoller must run as environment manager. return nil, common.ErrPerm } accessMachine := common.AuthFuncForTagKind(names.MachineTagKind) sti := getState(st) // Life() is supported for machines. lifeGetter := common.NewLifeGetter( sti, accessMachine, ) // ModelConfig() and WatchForModelConfigChanges() are allowed // with unrestriced access. modelWatcher := common.NewModelWatcher( sti, resources, authorizer, ) // WatchModelMachines() is allowed with unrestricted access. machinesWatcher := common.NewModelMachinesWatcher( sti, resources, authorizer, ) // InstanceId() is supported for machines. instanceIdGetter := common.NewInstanceIdGetter( sti, accessMachine, ) // Status() is supported for machines. statusGetter := common.NewStatusGetter( sti, accessMachine, ) return &InstancePollerAPI{ LifeGetter: lifeGetter, ModelWatcher: modelWatcher, ModelMachinesWatcher: machinesWatcher, InstanceIdGetter: instanceIdGetter, StatusGetter: statusGetter, st: sti, resources: resources, authorizer: authorizer, accessMachine: accessMachine, clock: clock, }, nil }
// NewStatusAPI creates a new server-side Status setter API facade. func NewStatusAPI(st *state.State, getCanModify common.GetAuthFunc) *StatusAPI { unitSetter := common.NewStatusSetter(st, getCanModify) unitGetter := common.NewStatusGetter(st, getCanModify) serviceSetter := common.NewServiceStatusSetter(st, getCanModify) serviceGetter := common.NewServiceStatusGetter(st, getCanModify) agentSetter := common.NewStatusSetter(&unitAgentFinder{st}, getCanModify) return &StatusAPI{ agentSetter: agentSetter, unitSetter: unitSetter, unitGetter: unitGetter, serviceSetter: serviceSetter, serviceGetter: serviceGetter, getCanModify: getCanModify, } }
// NewStatusAPI creates a new server-side Status setter API facade. func NewStatusAPI(st *state.State, getCanModify common.GetAuthFunc) *StatusAPI { // TODO(fwereade): so *all* of these have exactly the same auth // characteristics? I think not. unitSetter := common.NewStatusSetter(st, getCanModify) unitGetter := common.NewStatusGetter(st, getCanModify) serviceSetter := common.NewServiceStatusSetter(st, getCanModify) serviceGetter := common.NewServiceStatusGetter(st, getCanModify) agentSetter := common.NewStatusSetter(&common.UnitAgentFinder{st}, getCanModify) return &StatusAPI{ agentSetter: agentSetter, unitSetter: unitSetter, unitGetter: unitGetter, serviceSetter: serviceSetter, serviceGetter: serviceGetter, getCanModify: getCanModify, } }