blob: d47e4ea0f74c3a84e2e9120592a2e2f541f6b7e2 [file] [log] [blame]
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package namespace
import (
"v.io/v23"
"v.io/v23/context"
"v.io/v23/naming"
"v.io/v23/options"
"v.io/v23/rpc"
"v.io/v23/security/access"
"v.io/x/lib/vlog"
)
// setAccessListInMountTable sets the AccessList in a single server.
func setAccessListInMountTable(ctx *context.T, client rpc.Client, name string, acl access.Permissions, etag, id string, opts []rpc.CallOpt) (s status) {
s.id = id
ctx, _ = context.WithTimeout(ctx, callTimeout)
call, err := client.StartCall(ctx, name, "SetPermissions", []interface{}{acl, etag}, append(opts, options.NoResolve{})...)
s.err = err
if err != nil {
return
}
s.err = call.Finish()
return
}
func (ns *namespace) SetPermissions(ctx *context.T, name string, acl access.Permissions, etag string, opts ...naming.NamespaceOpt) error {
defer vlog.LogCall()()
client := v23.GetClient(ctx)
// Apply to all mount tables implementing the name.
f := func(ctx *context.T, mt, id string) status {
return setAccessListInMountTable(ctx, client, mt, acl, etag, id, getCallOpts(opts))
}
err := ns.dispatch(ctx, name, f, opts)
vlog.VI(1).Infof("SetPermissions(%s, %v, %s) -> %v", name, acl, etag, err)
return err
}
// GetPermissions gets an AccessList from a mount table.
func (ns *namespace) GetPermissions(ctx *context.T, name string, opts ...naming.NamespaceOpt) (acl access.Permissions, etag string, err error) {
defer vlog.LogCall()()
client := v23.GetClient(ctx)
// Resolve to all the mount tables implementing name.
me, rerr := ns.ResolveToMountTable(ctx, name, opts...)
if rerr != nil {
err = rerr
return
}
mts := me.Names()
call, serr := ns.parallelStartCall(ctx, client, mts, "GetPermissions", []interface{}{}, getCallOpts(opts))
if serr != nil {
err = serr
return
}
err = call.Finish(&acl, &etag)
return
}