[#207] aclsvc: Refactor object headers read
Resolve funlen linter for readObjectHeaders method. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
cd33a57f44
commit
9ef790f782
1 changed files with 84 additions and 77 deletions
|
@ -101,96 +101,103 @@ func requestHeaders(msg xHeaderSource) []eaclSDK.Header {
|
||||||
|
|
||||||
var errMissingOID = errors.New("object ID is missing")
|
var errMissingOID = errors.New("object ID is missing")
|
||||||
|
|
||||||
// nolint: funlen
|
|
||||||
func (h *cfg) readObjectHeaders(dst *headerSource) error {
|
func (h *cfg) readObjectHeaders(dst *headerSource) error {
|
||||||
switch m := h.msg.(type) {
|
switch m := h.msg.(type) {
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("unexpected message type %T", h.msg))
|
panic(fmt.Sprintf("unexpected message type %T", h.msg))
|
||||||
case requestXHeaderSource:
|
case requestXHeaderSource:
|
||||||
switch req := m.req.(type) {
|
return h.readObjectHeadersFromRequestXHeaderSource(m, dst)
|
||||||
case
|
|
||||||
*objectV2.GetRequest,
|
|
||||||
*objectV2.HeadRequest:
|
|
||||||
if h.obj == nil {
|
|
||||||
return errMissingOID
|
|
||||||
}
|
|
||||||
|
|
||||||
objHeaders, completed := h.localObjectHeaders(h.cnr, h.obj)
|
|
||||||
|
|
||||||
dst.objectHeaders = objHeaders
|
|
||||||
dst.incompleteObjectHeaders = !completed
|
|
||||||
case
|
|
||||||
*objectV2.GetRangeRequest,
|
|
||||||
*objectV2.GetRangeHashRequest,
|
|
||||||
*objectV2.DeleteRequest:
|
|
||||||
if h.obj == nil {
|
|
||||||
return errMissingOID
|
|
||||||
}
|
|
||||||
|
|
||||||
dst.objectHeaders = addressHeaders(h.cnr, h.obj)
|
|
||||||
case *objectV2.PutRequest:
|
|
||||||
if v, ok := req.GetBody().GetObjectPart().(*objectV2.PutObjectPartInit); ok {
|
|
||||||
oV2 := new(objectV2.Object)
|
|
||||||
oV2.SetObjectID(v.GetObjectID())
|
|
||||||
oV2.SetHeader(v.GetHeader())
|
|
||||||
|
|
||||||
dst.objectHeaders = headersFromObject(object.NewFromV2(oV2), h.cnr, h.obj)
|
|
||||||
}
|
|
||||||
case *objectV2.SearchRequest:
|
|
||||||
cnrV2 := req.GetBody().GetContainerID()
|
|
||||||
var cnr cid.ID
|
|
||||||
|
|
||||||
if cnrV2 != nil {
|
|
||||||
if err := cnr.ReadFromV2(*cnrV2); err != nil {
|
|
||||||
return fmt.Errorf("can't parse container ID: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dst.objectHeaders = []eaclSDK.Header{cidHeader(cnr)}
|
|
||||||
}
|
|
||||||
case responseXHeaderSource:
|
case responseXHeaderSource:
|
||||||
switch resp := m.resp.(type) {
|
return h.readObjectHeadersResponseXHeaderSource(m, dst)
|
||||||
default:
|
}
|
||||||
objectHeaders, completed := h.localObjectHeaders(h.cnr, h.obj)
|
}
|
||||||
|
|
||||||
dst.objectHeaders = objectHeaders
|
func (h *cfg) readObjectHeadersFromRequestXHeaderSource(m requestXHeaderSource, dst *headerSource) error {
|
||||||
dst.incompleteObjectHeaders = !completed
|
switch req := m.req.(type) {
|
||||||
case *objectV2.GetResponse:
|
case
|
||||||
if v, ok := resp.GetBody().GetObjectPart().(*objectV2.GetObjectPartInit); ok {
|
*objectV2.GetRequest,
|
||||||
oV2 := new(objectV2.Object)
|
*objectV2.HeadRequest:
|
||||||
oV2.SetObjectID(v.GetObjectID())
|
if h.obj == nil {
|
||||||
oV2.SetHeader(v.GetHeader())
|
return errMissingOID
|
||||||
|
}
|
||||||
|
|
||||||
dst.objectHeaders = headersFromObject(object.NewFromV2(oV2), h.cnr, h.obj)
|
objHeaders, completed := h.localObjectHeaders(h.cnr, h.obj)
|
||||||
}
|
|
||||||
case *objectV2.HeadResponse:
|
dst.objectHeaders = objHeaders
|
||||||
|
dst.incompleteObjectHeaders = !completed
|
||||||
|
case
|
||||||
|
*objectV2.GetRangeRequest,
|
||||||
|
*objectV2.GetRangeHashRequest,
|
||||||
|
*objectV2.DeleteRequest:
|
||||||
|
if h.obj == nil {
|
||||||
|
return errMissingOID
|
||||||
|
}
|
||||||
|
|
||||||
|
dst.objectHeaders = addressHeaders(h.cnr, h.obj)
|
||||||
|
case *objectV2.PutRequest:
|
||||||
|
if v, ok := req.GetBody().GetObjectPart().(*objectV2.PutObjectPartInit); ok {
|
||||||
oV2 := new(objectV2.Object)
|
oV2 := new(objectV2.Object)
|
||||||
|
oV2.SetObjectID(v.GetObjectID())
|
||||||
var hdr *objectV2.Header
|
oV2.SetHeader(v.GetHeader())
|
||||||
|
|
||||||
switch v := resp.GetBody().GetHeaderPart().(type) {
|
|
||||||
case *objectV2.ShortHeader:
|
|
||||||
hdr = new(objectV2.Header)
|
|
||||||
|
|
||||||
var idV2 refsV2.ContainerID
|
|
||||||
h.cnr.WriteToV2(&idV2)
|
|
||||||
|
|
||||||
hdr.SetContainerID(&idV2)
|
|
||||||
hdr.SetVersion(v.GetVersion())
|
|
||||||
hdr.SetCreationEpoch(v.GetCreationEpoch())
|
|
||||||
hdr.SetOwnerID(v.GetOwnerID())
|
|
||||||
hdr.SetObjectType(v.GetObjectType())
|
|
||||||
hdr.SetPayloadLength(v.GetPayloadLength())
|
|
||||||
case *objectV2.HeaderWithSignature:
|
|
||||||
hdr = v.GetHeader()
|
|
||||||
}
|
|
||||||
|
|
||||||
oV2.SetHeader(hdr)
|
|
||||||
|
|
||||||
dst.objectHeaders = headersFromObject(object.NewFromV2(oV2), h.cnr, h.obj)
|
dst.objectHeaders = headersFromObject(object.NewFromV2(oV2), h.cnr, h.obj)
|
||||||
}
|
}
|
||||||
}
|
case *objectV2.SearchRequest:
|
||||||
|
cnrV2 := req.GetBody().GetContainerID()
|
||||||
|
var cnr cid.ID
|
||||||
|
|
||||||
|
if cnrV2 != nil {
|
||||||
|
if err := cnr.ReadFromV2(*cnrV2); err != nil {
|
||||||
|
return fmt.Errorf("can't parse container ID: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dst.objectHeaders = []eaclSDK.Header{cidHeader(cnr)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *cfg) readObjectHeadersResponseXHeaderSource(m responseXHeaderSource, dst *headerSource) error {
|
||||||
|
switch resp := m.resp.(type) {
|
||||||
|
default:
|
||||||
|
objectHeaders, completed := h.localObjectHeaders(h.cnr, h.obj)
|
||||||
|
|
||||||
|
dst.objectHeaders = objectHeaders
|
||||||
|
dst.incompleteObjectHeaders = !completed
|
||||||
|
case *objectV2.GetResponse:
|
||||||
|
if v, ok := resp.GetBody().GetObjectPart().(*objectV2.GetObjectPartInit); ok {
|
||||||
|
oV2 := new(objectV2.Object)
|
||||||
|
oV2.SetObjectID(v.GetObjectID())
|
||||||
|
oV2.SetHeader(v.GetHeader())
|
||||||
|
|
||||||
|
dst.objectHeaders = headersFromObject(object.NewFromV2(oV2), h.cnr, h.obj)
|
||||||
|
}
|
||||||
|
case *objectV2.HeadResponse:
|
||||||
|
oV2 := new(objectV2.Object)
|
||||||
|
|
||||||
|
var hdr *objectV2.Header
|
||||||
|
|
||||||
|
switch v := resp.GetBody().GetHeaderPart().(type) {
|
||||||
|
case *objectV2.ShortHeader:
|
||||||
|
hdr = new(objectV2.Header)
|
||||||
|
|
||||||
|
var idV2 refsV2.ContainerID
|
||||||
|
h.cnr.WriteToV2(&idV2)
|
||||||
|
|
||||||
|
hdr.SetContainerID(&idV2)
|
||||||
|
hdr.SetVersion(v.GetVersion())
|
||||||
|
hdr.SetCreationEpoch(v.GetCreationEpoch())
|
||||||
|
hdr.SetOwnerID(v.GetOwnerID())
|
||||||
|
hdr.SetObjectType(v.GetObjectType())
|
||||||
|
hdr.SetPayloadLength(v.GetPayloadLength())
|
||||||
|
case *objectV2.HeaderWithSignature:
|
||||||
|
hdr = v.GetHeader()
|
||||||
|
}
|
||||||
|
|
||||||
|
oV2.SetHeader(hdr)
|
||||||
|
|
||||||
|
dst.objectHeaders = headersFromObject(object.NewFromV2(oV2), h.cnr, h.obj)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue