Exemplo n.º 1
0
Arquivo: watcher.go Projeto: bac/juju
// NewAllWatcher returns a new API server endpoint for interacting
// with a watcher created by the WatchAll and WatchAllModels API calls.
func NewAllWatcher(context facade.Context) (facade.Facade, error) {
	id := context.ID()
	auth := context.Auth()
	resources := context.Resources()

	// HasPermission should not be replaced by auth.AuthClient() even if, at first sight, they seem
	// equivalent because this allows us to remove login permission for a user
	// (a permission that is given by default).
	isAuthorized, err := auth.HasPermission(permission.LoginAccess, context.State().ControllerTag())
	if err != nil {
		return nil, errors.Trace(err)
	}
	if !isAuthorized {
		return nil, common.ErrPerm
	}
	watcher, ok := resources.Get(id).(*state.Multiwatcher)
	if !ok {
		return nil, common.ErrUnknownWatcher
	}
	return &SrvAllWatcher{
		watcher:   watcher,
		id:        id,
		resources: resources,
	}, nil
}
Exemplo n.º 2
0
Arquivo: watcher.go Projeto: bac/juju
func newFilesystemAttachmentsWatcher(context facade.Context) (facade.Facade, error) {
	id := context.ID()
	auth := context.Auth()
	resources := context.Resources()
	st := context.State()
	return newMachineStorageIdsWatcher(
		st, resources, auth, id, storagecommon.ParseFilesystemAttachmentIds,
	)
}
Exemplo n.º 3
0
Arquivo: watcher.go Projeto: bac/juju
func newEntitiesWatcher(context facade.Context) (facade.Facade, error) {
	id := context.ID()
	auth := context.Auth()
	resources := context.Resources()

	if !isAgent(auth) {
		return nil, common.ErrPerm
	}
	watcher, ok := resources.Get(id).(EntitiesWatcher)
	if !ok {
		return nil, common.ErrUnknownWatcher
	}
	return &srvEntitiesWatcher{
		resources: resources,
		id:        id,
		watcher:   watcher,
	}, nil
}
Exemplo n.º 4
0
Arquivo: watcher.go Projeto: bac/juju
func newRelationUnitsWatcher(context facade.Context) (facade.Facade, error) {
	id := context.ID()
	auth := context.Auth()
	resources := context.Resources()

	if !isAgent(auth) {
		return nil, common.ErrPerm
	}
	watcher, ok := resources.Get(id).(state.RelationUnitsWatcher)
	if !ok {
		return nil, common.ErrUnknownWatcher
	}
	return &srvRelationUnitsWatcher{
		watcher:   watcher,
		id:        id,
		resources: resources,
	}, nil
}
Exemplo n.º 5
0
Arquivo: watcher.go Projeto: bac/juju
func newMigrationStatusWatcher(context facade.Context) (facade.Facade, error) {
	id := context.ID()
	auth := context.Auth()
	resources := context.Resources()
	st := context.State()

	if !(auth.AuthMachineAgent() || auth.AuthUnitAgent()) {
		return nil, common.ErrPerm
	}
	w, ok := resources.Get(id).(state.NotifyWatcher)
	if !ok {
		return nil, common.ErrUnknownWatcher
	}
	return &srvMigrationStatusWatcher{
		watcher:   w,
		id:        id,
		resources: resources,
		st:        getMigrationBackend(st),
	}, nil
}