77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
|
package apemanager
|
||
|
|
||
|
import (
|
||
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status"
|
||
|
statusgrpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/grpc"
|
||
|
)
|
||
|
|
||
|
// LocalizeFailStatus checks if passed global status.Code is related to ape manager failure and:
|
||
|
//
|
||
|
// then localizes the code and returns true,
|
||
|
// else leaves the code unchanged and returns false.
|
||
|
//
|
||
|
// Arg must be non-nil.
|
||
|
func LocalizeFailStatus(c *status.Code) bool {
|
||
|
return status.LocalizeIfInSection(c, uint32(statusgrpc.Section_SECTION_APE_MANAGER))
|
||
|
}
|
||
|
|
||
|
// GlobalizeFail globalizes local code of ape manager failure.
|
||
|
//
|
||
|
// Arg must be non-nil.
|
||
|
func GlobalizeFail(c *status.Code) {
|
||
|
c.GlobalizeSection(uint32(statusgrpc.Section_SECTION_APE_MANAGER))
|
||
|
}
|
||
|
|
||
|
const (
|
||
|
// StatusAPEManagerAccessDenied is a local status.Code value for
|
||
|
// ACCESS_DENIED ape manager failure.
|
||
|
StatusAPEManagerAccessDenied status.Code = iota
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
// detailAccessDeniedDesc is a StatusAccessDenied detail ID for
|
||
|
// human-readable description.
|
||
|
detailAccessDeniedDesc = iota
|
||
|
)
|
||
|
|
||
|
// WriteAccessDeniedDesc writes human-readable description of StatusAccessDenied
|
||
|
// into status.Status as a detail. The status must not be nil.
|
||
|
//
|
||
|
// Existing details are expected to be ID-unique, otherwise undefined behavior.
|
||
|
func WriteAccessDeniedDesc(st *status.Status, desc string) {
|
||
|
var found bool
|
||
|
|
||
|
st.IterateDetails(func(d *status.Detail) bool {
|
||
|
if d.ID() == detailAccessDeniedDesc {
|
||
|
found = true
|
||
|
d.SetValue([]byte(desc))
|
||
|
}
|
||
|
|
||
|
return found
|
||
|
})
|
||
|
|
||
|
if !found {
|
||
|
var d status.Detail
|
||
|
|
||
|
d.SetID(detailAccessDeniedDesc)
|
||
|
d.SetValue([]byte(desc))
|
||
|
|
||
|
st.AppendDetails(d)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ReadAccessDeniedDesc looks up for status detail with human-readable description
|
||
|
// of StatusAccessDenied. Returns empty string if detail is missing.
|
||
|
func ReadAccessDeniedDesc(st status.Status) (desc string) {
|
||
|
st.IterateDetails(func(d *status.Detail) bool {
|
||
|
if d.ID() == detailAccessDeniedDesc {
|
||
|
desc = string(d.Value())
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
return false
|
||
|
})
|
||
|
|
||
|
return
|
||
|
}
|