2020-08-17 13:02:24 +00:00
|
|
|
package acl
|
|
|
|
|
|
|
|
import (
|
2023-03-07 10:38:56 +00:00
|
|
|
acl "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
|
|
|
|
protoutil "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
|
2020-08-17 13:02:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-08-17 13:57:51 +00:00
|
|
|
filterHeaderTypeField = 1
|
|
|
|
filterMatchTypeField = 2
|
|
|
|
filterNameField = 3
|
|
|
|
filterValueField = 4
|
|
|
|
|
|
|
|
targetTypeField = 1
|
|
|
|
targetKeysField = 2
|
|
|
|
|
|
|
|
recordOperationField = 1
|
|
|
|
recordActionField = 2
|
|
|
|
recordFiltersField = 3
|
|
|
|
recordTargetsField = 4
|
|
|
|
|
2020-09-04 07:50:36 +00:00
|
|
|
tableVersionField = 1
|
|
|
|
tableContainerIDField = 2
|
|
|
|
tableRecordsField = 3
|
2020-08-20 10:07:35 +00:00
|
|
|
|
|
|
|
lifetimeExpirationField = 1
|
|
|
|
lifetimeNotValidBeforeField = 2
|
|
|
|
lifetimeIssuedAtField = 3
|
|
|
|
|
2024-05-28 08:54:38 +00:00
|
|
|
tokenAPEChainsTargetField = 1
|
|
|
|
tokenAPEChainsChainsField = 2
|
|
|
|
|
|
|
|
bearerTokenBodyACLField = 1
|
|
|
|
bearerTokenBodyOwnerField = 2
|
|
|
|
bearerTokenBodyLifetimeField = 3
|
|
|
|
bearerTokenBodyImpersonate = 4
|
|
|
|
bearerTokenTokenAPEChainsField = 5
|
2020-08-20 10:07:35 +00:00
|
|
|
|
|
|
|
bearerTokenBodyField = 1
|
|
|
|
bearerTokenSignatureField = 2
|
2020-08-17 13:02:24 +00:00
|
|
|
)
|
|
|
|
|
2020-08-17 14:47:43 +00:00
|
|
|
// StableMarshal marshals unified acl table structure in a protobuf
|
|
|
|
// compatible way without field order shuffle.
|
2022-04-05 08:24:34 +00:00
|
|
|
func (t *Table) StableMarshal(buf []byte) []byte {
|
2020-08-17 13:57:51 +00:00
|
|
|
if t == nil {
|
2022-04-05 08:24:34 +00:00
|
|
|
return []byte{}
|
2020-08-17 13:57:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, t.StableSize())
|
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
var offset int
|
2020-08-17 13:57:51 +00:00
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
offset += protoutil.NestedStructureMarshal(tableVersionField, buf[offset:], t.version)
|
|
|
|
offset += protoutil.NestedStructureMarshal(tableContainerIDField, buf[offset:], t.cid)
|
2020-08-17 13:57:51 +00:00
|
|
|
|
|
|
|
for i := range t.records {
|
2022-04-05 08:24:34 +00:00
|
|
|
offset += protoutil.NestedStructureMarshal(tableRecordsField, buf[offset:], &t.records[i])
|
2020-08-17 13:57:51 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
return buf
|
2020-08-17 13:02:24 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 14:47:43 +00:00
|
|
|
// StableSize of acl table structure marshalled by StableMarshal function.
|
2020-08-17 13:57:51 +00:00
|
|
|
func (t *Table) StableSize() (size int) {
|
|
|
|
if t == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 11:31:53 +00:00
|
|
|
size += protoutil.NestedStructureSize(tableVersionField, t.version)
|
|
|
|
size += protoutil.NestedStructureSize(tableContainerIDField, t.cid)
|
2020-08-17 13:57:51 +00:00
|
|
|
|
|
|
|
for i := range t.records {
|
2022-03-01 13:32:54 +00:00
|
|
|
size += protoutil.NestedStructureSize(tableRecordsField, &t.records[i])
|
2020-08-17 13:57:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return size
|
2020-08-17 13:02:24 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 11:55:45 +00:00
|
|
|
func (t *Table) Unmarshal(data []byte) error {
|
2021-03-12 12:57:23 +00:00
|
|
|
return message.Unmarshal(t, data, new(acl.EACLTable))
|
2020-11-13 11:55:45 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 14:47:43 +00:00
|
|
|
// StableMarshal marshals unified acl record structure in a protobuf
|
|
|
|
// compatible way without field order shuffle.
|
2022-04-05 08:24:34 +00:00
|
|
|
func (r *Record) StableMarshal(buf []byte) []byte {
|
2020-08-17 13:49:19 +00:00
|
|
|
if r == nil {
|
2022-04-05 08:24:34 +00:00
|
|
|
return []byte{}
|
2020-08-17 13:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, r.StableSize())
|
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
var offset int
|
2020-08-17 13:49:19 +00:00
|
|
|
|
2022-03-12 12:20:19 +00:00
|
|
|
offset += protoutil.EnumMarshal(recordOperationField, buf[offset:], int32(r.op))
|
|
|
|
offset += protoutil.EnumMarshal(recordActionField, buf[offset:], int32(r.action))
|
2020-08-17 13:49:19 +00:00
|
|
|
|
|
|
|
for i := range r.filters {
|
2022-04-05 08:24:34 +00:00
|
|
|
offset += protoutil.NestedStructureMarshal(recordFiltersField, buf[offset:], &r.filters[i])
|
2020-08-17 13:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i := range r.targets {
|
2022-04-05 08:24:34 +00:00
|
|
|
offset += protoutil.NestedStructureMarshal(recordTargetsField, buf[offset:], &r.targets[i])
|
2020-08-17 13:49:19 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
return buf
|
2020-08-17 13:02:24 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 14:47:43 +00:00
|
|
|
// StableSize of acl record structure marshalled by StableMarshal function.
|
2020-08-17 13:49:19 +00:00
|
|
|
func (r *Record) StableSize() (size int) {
|
|
|
|
if r == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 11:31:53 +00:00
|
|
|
size += protoutil.EnumSize(recordOperationField, int32(r.op))
|
|
|
|
size += protoutil.EnumSize(recordActionField, int32(r.action))
|
2020-08-17 13:49:19 +00:00
|
|
|
|
|
|
|
for i := range r.filters {
|
2022-03-01 13:32:54 +00:00
|
|
|
size += protoutil.NestedStructureSize(recordFiltersField, &r.filters[i])
|
2020-08-17 13:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i := range r.targets {
|
2022-03-01 13:32:54 +00:00
|
|
|
size += protoutil.NestedStructureSize(recordTargetsField, &r.targets[i])
|
2020-08-17 13:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return size
|
2020-08-17 13:02:24 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 11:48:19 +00:00
|
|
|
func (r *Record) Unmarshal(data []byte) error {
|
2021-03-12 12:57:23 +00:00
|
|
|
return message.Unmarshal(r, data, new(acl.EACLRecord))
|
2020-11-13 11:48:19 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 14:47:43 +00:00
|
|
|
// StableMarshal marshals unified header filter structure in a protobuf
|
|
|
|
// compatible way without field order shuffle.
|
2022-04-05 08:24:34 +00:00
|
|
|
func (f *HeaderFilter) StableMarshal(buf []byte) []byte {
|
2020-08-17 13:02:24 +00:00
|
|
|
if f == nil {
|
2022-04-05 08:24:34 +00:00
|
|
|
return []byte{}
|
2020-08-17 13:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, f.StableSize())
|
|
|
|
}
|
|
|
|
|
2022-03-12 12:20:19 +00:00
|
|
|
var offset int
|
2020-08-17 13:02:24 +00:00
|
|
|
|
2022-03-12 12:20:19 +00:00
|
|
|
offset += protoutil.EnumMarshal(filterHeaderTypeField, buf[offset:], int32(f.hdrType))
|
|
|
|
offset += protoutil.EnumMarshal(filterMatchTypeField, buf[offset:], int32(f.matchType))
|
|
|
|
offset += protoutil.StringMarshal(filterNameField, buf[offset:], f.key)
|
|
|
|
protoutil.StringMarshal(filterValueField, buf[offset:], f.value)
|
2020-08-17 13:02:24 +00:00
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
return buf
|
2020-08-17 13:02:24 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 14:47:43 +00:00
|
|
|
// StableSize of header filter structure marshalled by StableMarshal function.
|
2020-08-17 13:02:24 +00:00
|
|
|
func (f *HeaderFilter) StableSize() (size int) {
|
|
|
|
if f == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 11:31:53 +00:00
|
|
|
size += protoutil.EnumSize(filterHeaderTypeField, int32(f.hdrType))
|
|
|
|
size += protoutil.EnumSize(filterMatchTypeField, int32(f.matchType))
|
|
|
|
size += protoutil.StringSize(filterNameField, f.key)
|
|
|
|
size += protoutil.StringSize(filterValueField, f.value)
|
2020-08-17 13:02:24 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
2020-11-13 11:31:53 +00:00
|
|
|
func (f *HeaderFilter) Unmarshal(data []byte) error {
|
2021-03-12 12:57:23 +00:00
|
|
|
return message.Unmarshal(f, data, new(acl.EACLRecord_Filter))
|
2020-11-13 11:31:53 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 07:50:36 +00:00
|
|
|
// StableMarshal marshals unified role info structure in a protobuf
|
2020-08-17 14:47:43 +00:00
|
|
|
// compatible way without field order shuffle.
|
2022-04-05 08:24:34 +00:00
|
|
|
func (t *Target) StableMarshal(buf []byte) []byte {
|
2020-08-17 13:09:09 +00:00
|
|
|
if t == nil {
|
2022-04-05 08:24:34 +00:00
|
|
|
return []byte{}
|
2020-08-17 13:09:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, t.StableSize())
|
|
|
|
}
|
|
|
|
|
2022-03-12 12:20:19 +00:00
|
|
|
var offset int
|
2020-08-17 13:09:09 +00:00
|
|
|
|
2022-03-12 12:20:19 +00:00
|
|
|
offset += protoutil.EnumMarshal(targetTypeField, buf[offset:], int32(t.role))
|
|
|
|
protoutil.RepeatedBytesMarshal(targetKeysField, buf[offset:], t.keys)
|
2020-08-17 13:09:09 +00:00
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
return buf
|
2020-08-17 13:02:24 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 07:50:36 +00:00
|
|
|
// StableSize of role info structure marshalled by StableMarshal function.
|
2020-09-10 10:01:31 +00:00
|
|
|
func (t *Target) StableSize() (size int) {
|
2020-08-17 13:09:09 +00:00
|
|
|
if t == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 11:31:53 +00:00
|
|
|
size += protoutil.EnumSize(targetTypeField, int32(t.role))
|
|
|
|
size += protoutil.RepeatedBytesSize(targetKeysField, t.keys)
|
2020-08-17 13:09:09 +00:00
|
|
|
|
|
|
|
return size
|
2020-08-17 13:02:24 +00:00
|
|
|
}
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2020-11-13 11:40:57 +00:00
|
|
|
func (t *Target) Unmarshal(data []byte) error {
|
2021-03-12 12:57:23 +00:00
|
|
|
return message.Unmarshal(t, data, new(acl.EACLRecord_Target))
|
2020-11-13 11:40:57 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
func (l *TokenLifetime) StableMarshal(buf []byte) []byte {
|
2020-08-20 10:07:35 +00:00
|
|
|
if l == nil {
|
2022-04-05 08:24:34 +00:00
|
|
|
return []byte{}
|
2020-08-20 10:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, l.StableSize())
|
|
|
|
}
|
|
|
|
|
2022-03-12 12:20:19 +00:00
|
|
|
var offset int
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2022-03-12 12:20:19 +00:00
|
|
|
offset += protoutil.UInt64Marshal(lifetimeExpirationField, buf[offset:], l.exp)
|
|
|
|
offset += protoutil.UInt64Marshal(lifetimeNotValidBeforeField, buf[offset:], l.nbf)
|
|
|
|
protoutil.UInt64Marshal(lifetimeIssuedAtField, buf[offset:], l.iat)
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
return buf
|
2020-08-20 10:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *TokenLifetime) StableSize() (size int) {
|
|
|
|
if l == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 11:31:53 +00:00
|
|
|
size += protoutil.UInt64Size(lifetimeExpirationField, l.exp)
|
|
|
|
size += protoutil.UInt64Size(lifetimeNotValidBeforeField, l.nbf)
|
|
|
|
size += protoutil.UInt64Size(lifetimeIssuedAtField, l.iat)
|
2020-08-20 10:07:35 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:00:03 +00:00
|
|
|
func (l *TokenLifetime) Unmarshal(data []byte) error {
|
2021-03-12 12:57:23 +00:00
|
|
|
return message.Unmarshal(l, data, new(acl.BearerToken_Body_TokenLifetime))
|
2020-11-13 12:00:03 +00:00
|
|
|
}
|
|
|
|
|
2024-05-28 08:54:38 +00:00
|
|
|
func (c *APEOverride) StableMarshal(buf []byte) []byte {
|
|
|
|
if c == nil {
|
|
|
|
return []byte{}
|
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, c.StableSize())
|
|
|
|
}
|
|
|
|
|
|
|
|
var offset int
|
|
|
|
|
|
|
|
offset += protoutil.NestedStructureMarshal(tokenAPEChainsTargetField, buf[offset:], c.target)
|
|
|
|
for i := range c.chains {
|
|
|
|
offset += protoutil.NestedStructureMarshal(tokenAPEChainsChainsField, buf[offset:], c.chains[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *APEOverride) StableSize() (size int) {
|
|
|
|
if c == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
size += protoutil.NestedStructureSize(tokenAPEChainsTargetField, c.target)
|
|
|
|
for i := range c.chains {
|
|
|
|
size += protoutil.NestedStructureSize(tokenAPEChainsChainsField, c.chains[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *APEOverride) Unmarshal(data []byte) error {
|
|
|
|
return message.Unmarshal(c, data, new(acl.BearerToken_Body_APEOverride))
|
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
func (bt *BearerTokenBody) StableMarshal(buf []byte) []byte {
|
2020-08-20 10:07:35 +00:00
|
|
|
if bt == nil {
|
2022-04-05 08:24:34 +00:00
|
|
|
return []byte{}
|
2020-08-20 10:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, bt.StableSize())
|
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
var offset int
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
offset += protoutil.NestedStructureMarshal(bearerTokenBodyACLField, buf[offset:], bt.eacl)
|
|
|
|
offset += protoutil.NestedStructureMarshal(bearerTokenBodyOwnerField, buf[offset:], bt.ownerID)
|
2023-02-21 08:23:08 +00:00
|
|
|
offset += protoutil.NestedStructureMarshal(bearerTokenBodyLifetimeField, buf[offset:], bt.lifetime)
|
2024-05-28 08:54:38 +00:00
|
|
|
offset += protoutil.BoolMarshal(bearerTokenBodyImpersonate, buf[offset:], bt.impersonate)
|
|
|
|
protoutil.NestedStructureMarshal(bearerTokenTokenAPEChainsField, buf[offset:], bt.apeOverride)
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
return buf
|
2020-08-20 10:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (bt *BearerTokenBody) StableSize() (size int) {
|
|
|
|
if bt == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 11:31:53 +00:00
|
|
|
size += protoutil.NestedStructureSize(bearerTokenBodyACLField, bt.eacl)
|
|
|
|
size += protoutil.NestedStructureSize(bearerTokenBodyOwnerField, bt.ownerID)
|
|
|
|
size += protoutil.NestedStructureSize(bearerTokenBodyLifetimeField, bt.lifetime)
|
2023-02-21 08:23:08 +00:00
|
|
|
size += protoutil.BoolSize(bearerTokenBodyImpersonate, bt.impersonate)
|
2024-05-28 08:54:38 +00:00
|
|
|
size += protoutil.NestedStructureSize(bearerTokenTokenAPEChainsField, bt.apeOverride)
|
2020-08-20 10:07:35 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:03:29 +00:00
|
|
|
func (bt *BearerTokenBody) Unmarshal(data []byte) error {
|
2021-03-12 12:57:23 +00:00
|
|
|
return message.Unmarshal(bt, data, new(acl.BearerToken_Body))
|
2020-11-13 12:03:29 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
func (bt *BearerToken) StableMarshal(buf []byte) []byte {
|
2020-08-20 10:07:35 +00:00
|
|
|
if bt == nil {
|
2022-04-05 08:24:34 +00:00
|
|
|
return []byte{}
|
2020-08-20 10:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, bt.StableSize())
|
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
var offset int
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
offset += protoutil.NestedStructureMarshal(bearerTokenBodyField, buf[offset:], bt.body)
|
|
|
|
protoutil.NestedStructureMarshal(bearerTokenSignatureField, buf[offset:], bt.sig)
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
return buf
|
2020-08-20 10:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (bt *BearerToken) StableSize() (size int) {
|
|
|
|
if bt == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-13 11:31:53 +00:00
|
|
|
size += protoutil.NestedStructureSize(bearerTokenBodyField, bt.body)
|
|
|
|
size += protoutil.NestedStructureSize(bearerTokenSignatureField, bt.sig)
|
2020-08-20 10:07:35 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
2020-11-13 12:08:37 +00:00
|
|
|
|
|
|
|
func (bt *BearerToken) Unmarshal(data []byte) error {
|
2021-03-12 12:57:23 +00:00
|
|
|
return message.Unmarshal(bt, data, new(acl.BearerToken))
|
2020-11-13 12:08:37 +00:00
|
|
|
}
|