示例#1
0
文件: policy.go 项目: tomzhang/p2
func NewUserPolicy(
	keyringPath string,
	deployPolicyPath string,
	preparerApp string,
	preparerUser string,
) (p Policy, err error) {
	keyringWatcher, err := util.NewFileWatcher(
		func(path string) (interface{}, error) {
			return LoadKeyring(path)
		},
		keyringPath,
	)
	if err != nil {
		return
	}
	defer func() {
		if err != nil {
			keyringWatcher.Close()
		}
	}()
	deployWatcher, err := util.NewFileWatcher(
		func(path string) (interface{}, error) {
			return LoadDeployPol(path)
		},
		deployPolicyPath,
	)
	if err != nil {
		return
	}
	p = UserPolicy{keyringWatcher, deployWatcher, preparerApp, preparerUser}
	return
}
示例#2
0
文件: policy.go 项目: tomzhang/p2
func NewFileKeyringPolicy(
	keyringPath string,
	authorizedDeployers map[string][]string,
) (Policy, error) {
	watcher, err := util.NewFileWatcher(
		func(path string) (interface{}, error) {
			return LoadKeyring(path)
		},
		keyringPath,
	)
	if err != nil {
		return nil, err
	}
	return FileKeyringPolicy{keyringPath, authorizedDeployers, watcher}, nil
}