当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.ID方法代码示例

本文整理汇总了Golang中github.com/juju/juju/apiserver/facade.Context.ID方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.ID方法的具体用法?Golang Context.ID怎么用?Golang Context.ID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/juju/juju/apiserver/facade.Context的用法示例。


在下文中一共展示了Context.ID方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: NewAllWatcher

// 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
}
开发者ID:bac,项目名称:juju,代码行数:27,代码来源:watcher.go

示例2: newFilesystemAttachmentsWatcher

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,
	)
}
开发者ID:bac,项目名称:juju,代码行数:9,代码来源:watcher.go

示例3: newEntitiesWatcher

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
}
开发者ID:bac,项目名称:juju,代码行数:18,代码来源:watcher.go

示例4: newRelationUnitsWatcher

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
}
开发者ID:bac,项目名称:juju,代码行数:18,代码来源:watcher.go

示例5: newMigrationStatusWatcher

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
}
开发者ID:bac,项目名称:juju,代码行数:20,代码来源:watcher.go


注:本文中的github.com/juju/juju/apiserver/facade.Context.ID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。