forked from TrueCloudLab/frostfs-node
[#1428] node/acl: Make container ID as required param
Change pointer to value in request information since requests could not exist without container ID. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
6cb9c13c5e
commit
d69eb2aaf3
5 changed files with 14 additions and 21 deletions
|
@ -144,10 +144,11 @@ func (c *Checker) CheckEACL(msg interface{}, reqInfo v2.RequestInfo) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var table eaclSDK.Table
|
var table eaclSDK.Table
|
||||||
|
cid := reqInfo.ContainerID()
|
||||||
|
|
||||||
bearerTok := reqInfo.Bearer()
|
bearerTok := reqInfo.Bearer()
|
||||||
if bearerTok == nil {
|
if bearerTok == nil {
|
||||||
pTable, err := c.eaclSrc.GetEACL(reqInfo.ContainerID())
|
pTable, err := c.eaclSrc.GetEACL(&cid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, container.ErrEACLNotFound) {
|
if errors.Is(err, container.ErrEACLNotFound) {
|
||||||
return nil
|
return nil
|
||||||
|
@ -168,7 +169,7 @@ func (c *Checker) CheckEACL(msg interface{}, reqInfo v2.RequestInfo) error {
|
||||||
hdrSrcOpts := make([]eaclV2.Option, 0, 3)
|
hdrSrcOpts := make([]eaclV2.Option, 0, 3)
|
||||||
|
|
||||||
addr := addressSDK.NewAddress()
|
addr := addressSDK.NewAddress()
|
||||||
addr.SetContainerID(*reqInfo.ContainerID())
|
addr.SetContainerID(cid)
|
||||||
addr.SetObjectID(*reqInfo.ObjectID())
|
addr.SetObjectID(*reqInfo.ObjectID())
|
||||||
|
|
||||||
hdrSrcOpts = append(hdrSrcOpts,
|
hdrSrcOpts = append(hdrSrcOpts,
|
||||||
|
@ -195,7 +196,7 @@ func (c *Checker) CheckEACL(msg interface{}, reqInfo v2.RequestInfo) error {
|
||||||
action := c.validator.CalculateAction(new(eaclSDK.ValidationUnit).
|
action := c.validator.CalculateAction(new(eaclSDK.ValidationUnit).
|
||||||
WithRole(reqInfo.RequestRole()).
|
WithRole(reqInfo.RequestRole()).
|
||||||
WithOperation(reqInfo.Operation()).
|
WithOperation(reqInfo.Operation()).
|
||||||
WithContainerID(reqInfo.ContainerID()).
|
WithContainerID(&cid).
|
||||||
WithSenderKey(reqInfo.SenderKey()).
|
WithSenderKey(reqInfo.SenderKey()).
|
||||||
WithHeaderSource(hdrSrc).
|
WithHeaderSource(hdrSrc).
|
||||||
WithEACLTable(&table),
|
WithEACLTable(&table),
|
||||||
|
|
|
@ -19,8 +19,6 @@ type senderClassifier struct {
|
||||||
netmap core.Source
|
netmap core.Source
|
||||||
}
|
}
|
||||||
|
|
||||||
var errContainerIDNotSet = errors.New("container id is not set")
|
|
||||||
|
|
||||||
type classifyResult struct {
|
type classifyResult struct {
|
||||||
role eaclSDK.Role
|
role eaclSDK.Role
|
||||||
isIR bool
|
isIR bool
|
||||||
|
@ -29,12 +27,8 @@ type classifyResult struct {
|
||||||
|
|
||||||
func (c senderClassifier) classify(
|
func (c senderClassifier) classify(
|
||||||
req MetaWithToken,
|
req MetaWithToken,
|
||||||
idCnr *cidSDK.ID,
|
idCnr cidSDK.ID,
|
||||||
cnr *container.Container) (res *classifyResult, err error) {
|
cnr *container.Container) (res *classifyResult, err error) {
|
||||||
if idCnr == nil {
|
|
||||||
return nil, errContainerIDNotSet
|
|
||||||
}
|
|
||||||
|
|
||||||
ownerCnr := cnr.OwnerID()
|
ownerCnr := cnr.OwnerID()
|
||||||
if ownerCnr == nil {
|
if ownerCnr == nil {
|
||||||
return nil, errors.New("missing container owner")
|
return nil, errors.New("missing container owner")
|
||||||
|
|
|
@ -23,7 +23,7 @@ type RequestInfo struct {
|
||||||
operation eaclSDK.Operation // put, get, head, etc.
|
operation eaclSDK.Operation // put, get, head, etc.
|
||||||
cnrOwner *user.ID // container owner
|
cnrOwner *user.ID // container owner
|
||||||
|
|
||||||
idCnr *containerIDSDK.ID
|
idCnr containerIDSDK.ID
|
||||||
|
|
||||||
oid *oidSDK.ID
|
oid *oidSDK.ID
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ func (r RequestInfo) ObjectID() *oidSDK.ID {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerID return container ID.
|
// ContainerID return container ID.
|
||||||
func (r RequestInfo) ContainerID() *containerIDSDK.ID {
|
func (r RequestInfo) ContainerID() containerIDSDK.ID {
|
||||||
return r.idCnr
|
return r.idCnr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -202,8 +202,6 @@ func (b Service) Head(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b Service) Search(request *objectV2.SearchRequest, stream object.SearchStream) error {
|
func (b Service) Search(request *objectV2.SearchRequest, stream object.SearchStream) error {
|
||||||
var id *cidSDK.ID
|
|
||||||
|
|
||||||
id, err := getContainerIDFromRequest(request)
|
id, err := getContainerIDFromRequest(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -442,9 +440,9 @@ func (g *searchStreamBasicChecker) Send(resp *objectV2.SearchResponse) error {
|
||||||
|
|
||||||
func (b Service) findRequestInfo(
|
func (b Service) findRequestInfo(
|
||||||
req MetaWithToken,
|
req MetaWithToken,
|
||||||
cid *cidSDK.ID,
|
cid cidSDK.ID,
|
||||||
op eaclSDK.Operation) (info RequestInfo, err error) {
|
op eaclSDK.Operation) (info RequestInfo, err error) {
|
||||||
cnr, err := b.containers.Get(cid) // fetch actual container
|
cnr, err := b.containers.Get(&cid) // fetch actual container
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return info, err
|
return info, err
|
||||||
} else if cnr.OwnerID() == nil {
|
} else if cnr.OwnerID() == nil {
|
||||||
|
|
|
@ -20,9 +20,9 @@ import (
|
||||||
|
|
||||||
var errMissingContainerID = errors.New("missing container ID")
|
var errMissingContainerID = errors.New("missing container ID")
|
||||||
|
|
||||||
func getContainerIDFromRequest(req interface{}) (*containerIDSDK.ID, error) {
|
func getContainerIDFromRequest(req interface{}) (containerIDSDK.ID, error) {
|
||||||
var idV2 *refsV2.ContainerID
|
var idV2 *refsV2.ContainerID
|
||||||
id := new(containerIDSDK.ID)
|
var id containerIDSDK.ID
|
||||||
|
|
||||||
switch v := req.(type) {
|
switch v := req.(type) {
|
||||||
case *objectV2.GetRequest:
|
case *objectV2.GetRequest:
|
||||||
|
@ -30,7 +30,7 @@ func getContainerIDFromRequest(req interface{}) (*containerIDSDK.ID, error) {
|
||||||
case *objectV2.PutRequest:
|
case *objectV2.PutRequest:
|
||||||
part, ok := v.GetBody().GetObjectPart().(*objectV2.PutObjectPartInit)
|
part, ok := v.GetBody().GetObjectPart().(*objectV2.PutObjectPartInit)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("can't get container ID in chunk")
|
return containerIDSDK.ID{}, errors.New("can't get container ID in chunk")
|
||||||
}
|
}
|
||||||
|
|
||||||
idV2 = part.GetHeader().GetContainerID()
|
idV2 = part.GetHeader().GetContainerID()
|
||||||
|
@ -45,11 +45,11 @@ func getContainerIDFromRequest(req interface{}) (*containerIDSDK.ID, error) {
|
||||||
case *objectV2.GetRangeHashRequest:
|
case *objectV2.GetRangeHashRequest:
|
||||||
idV2 = v.GetBody().GetAddress().GetContainerID()
|
idV2 = v.GetBody().GetAddress().GetContainerID()
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("unknown request type")
|
return containerIDSDK.ID{}, errors.New("unknown request type")
|
||||||
}
|
}
|
||||||
|
|
||||||
if idV2 == nil {
|
if idV2 == nil {
|
||||||
return nil, errMissingContainerID
|
return containerIDSDK.ID{}, errMissingContainerID
|
||||||
}
|
}
|
||||||
|
|
||||||
return id, id.ReadFromV2(*idV2)
|
return id, id.ReadFromV2(*idV2)
|
||||||
|
|
Loading…
Reference in a new issue