2020-08-17 09:22:51 +00:00
|
|
|
package acl
|
|
|
|
|
|
|
|
import (
|
2022-12-09 11:16:24 +00:00
|
|
|
acl "github.com/TrueCloudLab/frostfs-api-go/v2/acl/grpc"
|
|
|
|
"github.com/TrueCloudLab/frostfs-api-go/v2/refs"
|
|
|
|
refsGRPC "github.com/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
|
|
|
|
"github.com/TrueCloudLab/frostfs-api-go/v2/rpc/grpc"
|
|
|
|
"github.com/TrueCloudLab/frostfs-api-go/v2/rpc/message"
|
2020-08-17 09:22:51 +00:00
|
|
|
)
|
|
|
|
|
2020-09-04 07:50:36 +00:00
|
|
|
// RoleToGRPCField converts unified role enum into grpc enum.
|
|
|
|
func RoleToGRPCField(t Role) acl.Role {
|
2020-08-17 09:22:51 +00:00
|
|
|
switch t {
|
2020-09-04 07:50:36 +00:00
|
|
|
case RoleUser:
|
|
|
|
return acl.Role_USER
|
|
|
|
case RoleSystem:
|
|
|
|
return acl.Role_SYSTEM
|
|
|
|
case RoleOthers:
|
|
|
|
return acl.Role_OTHERS
|
2020-08-17 09:22:51 +00:00
|
|
|
default:
|
2020-09-04 07:50:36 +00:00
|
|
|
return acl.Role_ROLE_UNSPECIFIED
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-04 07:50:36 +00:00
|
|
|
// RoleFromGRPCField converts grpc enum into unified role enum.
|
|
|
|
func RoleFromGRPCField(t acl.Role) Role {
|
2020-08-17 09:22:51 +00:00
|
|
|
switch t {
|
2020-09-04 07:50:36 +00:00
|
|
|
case acl.Role_USER:
|
|
|
|
return RoleUser
|
|
|
|
case acl.Role_SYSTEM:
|
|
|
|
return RoleSystem
|
|
|
|
case acl.Role_OTHERS:
|
|
|
|
return RoleOthers
|
2020-08-17 09:22:51 +00:00
|
|
|
default:
|
2020-09-04 07:50:36 +00:00
|
|
|
return RoleUnknown
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-17 14:47:43 +00:00
|
|
|
// OperationToGRPCField converts unified operation enum into grpc enum.
|
2020-08-17 11:30:09 +00:00
|
|
|
func OperationToGRPCField(t Operation) acl.Operation {
|
2020-08-17 09:22:51 +00:00
|
|
|
switch t {
|
|
|
|
case OperationPut:
|
2020-08-17 11:30:09 +00:00
|
|
|
return acl.Operation_PUT
|
2020-08-17 09:22:51 +00:00
|
|
|
case OperationDelete:
|
2020-08-17 11:30:09 +00:00
|
|
|
return acl.Operation_DELETE
|
2020-08-17 09:22:51 +00:00
|
|
|
case OperationGet:
|
2020-08-17 11:30:09 +00:00
|
|
|
return acl.Operation_GET
|
2020-08-17 09:22:51 +00:00
|
|
|
case OperationHead:
|
2020-08-17 11:30:09 +00:00
|
|
|
return acl.Operation_HEAD
|
2020-08-17 09:22:51 +00:00
|
|
|
case OperationSearch:
|
2020-08-17 11:30:09 +00:00
|
|
|
return acl.Operation_SEARCH
|
2020-08-17 09:22:51 +00:00
|
|
|
case OperationRange:
|
2020-08-17 11:30:09 +00:00
|
|
|
return acl.Operation_GETRANGE
|
2020-08-17 09:22:51 +00:00
|
|
|
case OperationRangeHash:
|
2020-08-17 11:30:09 +00:00
|
|
|
return acl.Operation_GETRANGEHASH
|
2020-08-17 09:22:51 +00:00
|
|
|
default:
|
2020-08-17 11:30:09 +00:00
|
|
|
return acl.Operation_OPERATION_UNSPECIFIED
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-17 14:47:43 +00:00
|
|
|
// OperationFromGRPCField converts grpc enum into unified operation enum.
|
2020-08-17 11:30:09 +00:00
|
|
|
func OperationFromGRPCField(t acl.Operation) Operation {
|
2020-08-17 09:22:51 +00:00
|
|
|
switch t {
|
2020-08-17 11:30:09 +00:00
|
|
|
case acl.Operation_PUT:
|
2020-08-17 09:22:51 +00:00
|
|
|
return OperationPut
|
2020-08-17 11:30:09 +00:00
|
|
|
case acl.Operation_DELETE:
|
2020-08-17 09:22:51 +00:00
|
|
|
return OperationDelete
|
2020-08-17 11:30:09 +00:00
|
|
|
case acl.Operation_GET:
|
2020-08-17 09:22:51 +00:00
|
|
|
return OperationGet
|
2020-08-17 11:30:09 +00:00
|
|
|
case acl.Operation_HEAD:
|
2020-08-17 09:22:51 +00:00
|
|
|
return OperationHead
|
2020-08-17 11:30:09 +00:00
|
|
|
case acl.Operation_SEARCH:
|
2020-08-17 09:22:51 +00:00
|
|
|
return OperationSearch
|
2020-08-17 11:30:09 +00:00
|
|
|
case acl.Operation_GETRANGE:
|
2020-08-17 09:22:51 +00:00
|
|
|
return OperationRange
|
2020-08-17 11:30:09 +00:00
|
|
|
case acl.Operation_GETRANGEHASH:
|
2020-08-17 09:22:51 +00:00
|
|
|
return OperationRangeHash
|
|
|
|
default:
|
|
|
|
return OperationUnknown
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-17 14:47:43 +00:00
|
|
|
// ActionToGRPCField converts unified action enum into grpc enum.
|
2020-08-17 11:30:09 +00:00
|
|
|
func ActionToGRPCField(t Action) acl.Action {
|
2020-08-17 09:22:51 +00:00
|
|
|
switch t {
|
|
|
|
case ActionDeny:
|
2020-08-17 11:30:09 +00:00
|
|
|
return acl.Action_DENY
|
2020-08-17 09:22:51 +00:00
|
|
|
case ActionAllow:
|
2020-08-17 11:30:09 +00:00
|
|
|
return acl.Action_ALLOW
|
2020-08-17 09:22:51 +00:00
|
|
|
default:
|
2020-08-17 11:30:09 +00:00
|
|
|
return acl.Action_ACTION_UNSPECIFIED
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-17 14:47:43 +00:00
|
|
|
// ActionFromGRPCField converts grpc enum into unified action enum.
|
2020-08-17 11:30:09 +00:00
|
|
|
func ActionFromGRPCField(t acl.Action) Action {
|
2020-08-17 09:22:51 +00:00
|
|
|
switch t {
|
2020-08-17 11:30:09 +00:00
|
|
|
case acl.Action_DENY:
|
2020-08-17 09:22:51 +00:00
|
|
|
return ActionDeny
|
2020-08-17 11:30:09 +00:00
|
|
|
case acl.Action_ALLOW:
|
2020-08-17 09:22:51 +00:00
|
|
|
return ActionAllow
|
|
|
|
default:
|
|
|
|
return ActionUnknown
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-17 14:47:43 +00:00
|
|
|
// HeaderTypeToGRPCField converts unified header type enum into grpc enum.
|
2020-08-17 11:30:09 +00:00
|
|
|
func HeaderTypeToGRPCField(t HeaderType) acl.HeaderType {
|
2020-08-17 09:22:51 +00:00
|
|
|
switch t {
|
|
|
|
case HeaderTypeRequest:
|
2020-08-17 11:30:09 +00:00
|
|
|
return acl.HeaderType_REQUEST
|
2020-08-17 09:22:51 +00:00
|
|
|
case HeaderTypeObject:
|
2020-08-17 11:30:09 +00:00
|
|
|
return acl.HeaderType_OBJECT
|
2021-09-14 10:51:20 +00:00
|
|
|
case HeaderTypeService:
|
|
|
|
return acl.HeaderType_SERVICE
|
2020-08-17 09:22:51 +00:00
|
|
|
default:
|
2020-08-17 11:30:09 +00:00
|
|
|
return acl.HeaderType_HEADER_UNSPECIFIED
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-17 14:47:43 +00:00
|
|
|
// HeaderTypeFromGRPCField converts grpc enum into unified header type enum.
|
2020-08-17 11:30:09 +00:00
|
|
|
func HeaderTypeFromGRPCField(t acl.HeaderType) HeaderType {
|
2020-08-17 09:22:51 +00:00
|
|
|
switch t {
|
2020-08-17 11:30:09 +00:00
|
|
|
case acl.HeaderType_REQUEST:
|
2020-08-17 09:22:51 +00:00
|
|
|
return HeaderTypeRequest
|
2020-08-17 11:30:09 +00:00
|
|
|
case acl.HeaderType_OBJECT:
|
2020-08-17 09:22:51 +00:00
|
|
|
return HeaderTypeObject
|
2021-09-14 10:51:20 +00:00
|
|
|
case acl.HeaderType_SERVICE:
|
|
|
|
return HeaderTypeService
|
2020-08-17 09:22:51 +00:00
|
|
|
default:
|
|
|
|
return HeaderTypeUnknown
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-17 14:47:43 +00:00
|
|
|
// MatchTypeToGRPCField converts unified match type enum into grpc enum.
|
2020-08-17 11:30:09 +00:00
|
|
|
func MatchTypeToGRPCField(t MatchType) acl.MatchType {
|
2020-08-17 09:22:51 +00:00
|
|
|
switch t {
|
|
|
|
case MatchTypeStringEqual:
|
2020-08-17 11:30:09 +00:00
|
|
|
return acl.MatchType_STRING_EQUAL
|
2020-08-17 09:22:51 +00:00
|
|
|
case MatchTypeStringNotEqual:
|
2020-08-17 11:30:09 +00:00
|
|
|
return acl.MatchType_STRING_NOT_EQUAL
|
2020-08-17 09:22:51 +00:00
|
|
|
default:
|
2020-08-17 11:30:09 +00:00
|
|
|
return acl.MatchType_MATCH_TYPE_UNSPECIFIED
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-17 14:47:43 +00:00
|
|
|
// MatchTypeFromGRPCField converts grpc enum into unified match type enum.
|
2020-08-17 11:30:09 +00:00
|
|
|
func MatchTypeFromGRPCField(t acl.MatchType) MatchType {
|
2020-08-17 09:22:51 +00:00
|
|
|
switch t {
|
2020-08-17 11:30:09 +00:00
|
|
|
case acl.MatchType_STRING_EQUAL:
|
2020-08-17 09:22:51 +00:00
|
|
|
return MatchTypeStringEqual
|
2020-08-17 11:30:09 +00:00
|
|
|
case acl.MatchType_STRING_NOT_EQUAL:
|
2020-08-17 09:22:51 +00:00
|
|
|
return MatchTypeStringNotEqual
|
|
|
|
default:
|
|
|
|
return MatchTypeUnknown
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (f *HeaderFilter) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *acl.EACLRecord_Filter
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if f != nil {
|
|
|
|
m = new(acl.EACLRecord_Filter)
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetKey(f.key)
|
|
|
|
m.SetValue(f.value)
|
|
|
|
m.SetHeader(HeaderTypeToGRPCField(f.hdrType))
|
|
|
|
m.SetMatchType(MatchTypeToGRPCField(f.matchType))
|
|
|
|
}
|
2020-08-17 09:22:51 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (f *HeaderFilter) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*acl.EACLRecord_Filter)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
f.key = v.GetKey()
|
|
|
|
f.value = v.GetValue()
|
|
|
|
f.hdrType = HeaderTypeFromGRPCField(v.GetHeaderType())
|
|
|
|
f.matchType = MatchTypeFromGRPCField(v.GetMatchType())
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2022-03-01 13:32:54 +00:00
|
|
|
func HeaderFiltersToGRPC(fs []HeaderFilter) (res []*acl.EACLRecord_Filter) {
|
2021-03-12 12:57:23 +00:00
|
|
|
if fs != nil {
|
|
|
|
res = make([]*acl.EACLRecord_Filter, 0, len(fs))
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
for i := range fs {
|
|
|
|
res = append(res, fs[i].ToGRPCMessage().(*acl.EACLRecord_Filter))
|
|
|
|
}
|
|
|
|
}
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
|
|
|
|
2022-03-01 13:32:54 +00:00
|
|
|
func HeaderFiltersFromGRPC(fs []*acl.EACLRecord_Filter) (res []HeaderFilter, err error) {
|
2021-03-12 12:57:23 +00:00
|
|
|
if fs != nil {
|
2022-03-01 13:32:54 +00:00
|
|
|
res = make([]HeaderFilter, len(fs))
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
for i := range fs {
|
|
|
|
if fs[i] != nil {
|
2022-03-01 13:32:54 +00:00
|
|
|
err = res[i].FromGRPCMessage(fs[i])
|
2021-03-12 12:57:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (t *Target) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *acl.EACLRecord_Target
|
|
|
|
|
|
|
|
if t != nil {
|
|
|
|
m = new(acl.EACLRecord_Target)
|
|
|
|
|
|
|
|
m.SetRole(RoleToGRPCField(t.role))
|
|
|
|
m.SetKeys(t.keys)
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return m
|
|
|
|
}
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (t *Target) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*acl.EACLRecord_Target)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
|
|
|
}
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
t.role = RoleFromGRPCField(v.GetRole())
|
|
|
|
t.keys = v.GetKeys()
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
|
|
|
|
2022-03-01 13:32:54 +00:00
|
|
|
func TargetsToGRPC(ts []Target) (res []*acl.EACLRecord_Target) {
|
2021-03-12 12:57:23 +00:00
|
|
|
if ts != nil {
|
|
|
|
res = make([]*acl.EACLRecord_Target, 0, len(ts))
|
|
|
|
|
|
|
|
for i := range ts {
|
|
|
|
res = append(res, ts[i].ToGRPCMessage().(*acl.EACLRecord_Target))
|
|
|
|
}
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-01 13:32:54 +00:00
|
|
|
func TargetsFromGRPC(fs []*acl.EACLRecord_Target) (res []Target, err error) {
|
2021-03-12 12:57:23 +00:00
|
|
|
if fs != nil {
|
2022-03-01 13:32:54 +00:00
|
|
|
res = make([]Target, len(fs))
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
for i := range fs {
|
|
|
|
if fs[i] != nil {
|
2022-03-01 13:32:54 +00:00
|
|
|
err = res[i].FromGRPCMessage(fs[i])
|
2021-03-12 12:57:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Record) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *acl.EACLRecord
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if r != nil {
|
|
|
|
m = new(acl.EACLRecord)
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetOperation(OperationToGRPCField(r.op))
|
|
|
|
m.SetAction(ActionToGRPCField(r.action))
|
|
|
|
m.SetFilters(HeaderFiltersToGRPC(r.filters))
|
|
|
|
m.SetTargets(TargetsToGRPC(r.targets))
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (r *Record) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*acl.EACLRecord)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
|
|
|
|
|
|
|
r.filters, err = HeaderFiltersFromGRPC(v.GetFilters())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
r.targets, err = TargetsFromGRPC(v.GetTargets())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
r.op = OperationFromGRPCField(v.GetOperation())
|
|
|
|
r.action = ActionFromGRPCField(v.GetAction())
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2022-03-01 13:32:54 +00:00
|
|
|
func RecordsToGRPC(ts []Record) (res []*acl.EACLRecord) {
|
2021-03-12 12:57:23 +00:00
|
|
|
if ts != nil {
|
|
|
|
res = make([]*acl.EACLRecord, 0, len(ts))
|
|
|
|
|
|
|
|
for i := range ts {
|
|
|
|
res = append(res, ts[i].ToGRPCMessage().(*acl.EACLRecord))
|
|
|
|
}
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return
|
|
|
|
}
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2022-03-01 13:32:54 +00:00
|
|
|
func RecordsFromGRPC(fs []*acl.EACLRecord) (res []Record, err error) {
|
2021-03-12 12:57:23 +00:00
|
|
|
if fs != nil {
|
2022-03-01 13:32:54 +00:00
|
|
|
res = make([]Record, len(fs))
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
for i := range fs {
|
|
|
|
if fs[i] != nil {
|
2022-03-01 13:32:54 +00:00
|
|
|
err = res[i].FromGRPCMessage(fs[i])
|
2021-03-12 12:57:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return
|
|
|
|
}
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (t *Table) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *acl.EACLTable
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if t != nil {
|
|
|
|
m = new(acl.EACLTable)
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetVersion(t.version.ToGRPCMessage().(*refsGRPC.Version))
|
|
|
|
m.SetContainerId(t.cid.ToGRPCMessage().(*refsGRPC.ContainerID))
|
|
|
|
m.SetRecords(RecordsToGRPC(t.records))
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (t *Table) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*acl.EACLTable)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
cid := v.GetContainerId()
|
|
|
|
if cid == nil {
|
|
|
|
t.cid = nil
|
|
|
|
} else {
|
|
|
|
if t.cid == nil {
|
|
|
|
t.cid = new(refs.ContainerID)
|
|
|
|
}
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = t.cid.FromGRPCMessage(cid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
version := v.GetVersion()
|
|
|
|
if version == nil {
|
|
|
|
t.version = nil
|
|
|
|
} else {
|
|
|
|
if t.version == nil {
|
|
|
|
t.version = new(refs.Version)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = t.version.FromGRPCMessage(version)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
t.records, err = RecordsFromGRPC(v.GetRecords())
|
2020-08-17 09:22:51 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return err
|
2020-08-17 09:22:51 +00:00
|
|
|
}
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (l *TokenLifetime) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *acl.BearerToken_Body_TokenLifetime
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if l != nil {
|
|
|
|
m = new(acl.BearerToken_Body_TokenLifetime)
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetExp(l.exp)
|
|
|
|
m.SetIat(l.iat)
|
|
|
|
m.SetNbf(l.nbf)
|
|
|
|
}
|
2020-08-20 10:07:35 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (l *TokenLifetime) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*acl.BearerToken_Body_TokenLifetime)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-20 10:07:35 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
l.exp = v.GetExp()
|
|
|
|
l.iat = v.GetIat()
|
|
|
|
l.nbf = v.GetNbf()
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2020-08-20 10:07:35 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (bt *BearerTokenBody) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *acl.BearerToken_Body
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if bt != nil {
|
|
|
|
m = new(acl.BearerToken_Body)
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetOwnerId(bt.ownerID.ToGRPCMessage().(*refsGRPC.OwnerID))
|
|
|
|
m.SetLifetime(bt.lifetime.ToGRPCMessage().(*acl.BearerToken_Body_TokenLifetime))
|
|
|
|
m.SetEaclTable(bt.eacl.ToGRPCMessage().(*acl.EACLTable))
|
2023-02-21 08:23:08 +00:00
|
|
|
m.SetImpersonate(bt.impersonate)
|
2021-03-12 12:57:23 +00:00
|
|
|
}
|
2020-08-20 10:07:35 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (bt *BearerTokenBody) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*acl.BearerToken_Body)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-20 10:07:35 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
ownerID := v.GetOwnerId()
|
|
|
|
if ownerID == nil {
|
|
|
|
bt.ownerID = nil
|
|
|
|
} else {
|
|
|
|
if bt.ownerID == nil {
|
|
|
|
bt.ownerID = new(refs.OwnerID)
|
|
|
|
}
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = bt.ownerID.FromGRPCMessage(ownerID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
lifetime := v.GetLifetime()
|
|
|
|
if lifetime == nil {
|
|
|
|
bt.lifetime = nil
|
|
|
|
} else {
|
|
|
|
if bt.lifetime == nil {
|
|
|
|
bt.lifetime = new(TokenLifetime)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = bt.lifetime.FromGRPCMessage(lifetime)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
eacl := v.GetEaclTable()
|
|
|
|
if eacl == nil {
|
|
|
|
bt.eacl = nil
|
|
|
|
} else {
|
|
|
|
if bt.eacl == nil {
|
|
|
|
bt.eacl = new(Table)
|
|
|
|
}
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = bt.eacl.FromGRPCMessage(eacl)
|
2020-08-20 10:07:35 +00:00
|
|
|
}
|
|
|
|
|
2023-02-21 08:23:08 +00:00
|
|
|
bt.impersonate = v.GetAllowImpersonate()
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bt *BearerToken) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *acl.BearerToken
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if bt != nil {
|
|
|
|
m = new(acl.BearerToken)
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetBody(bt.body.ToGRPCMessage().(*acl.BearerToken_Body))
|
|
|
|
m.SetSignature(bt.sig.ToGRPCMessage().(*refsGRPC.Signature))
|
|
|
|
}
|
2020-08-20 10:07:35 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (bt *BearerToken) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*acl.BearerToken)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-20 10:07:35 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
|
|
|
|
|
|
|
body := v.GetBody()
|
|
|
|
if body == nil {
|
|
|
|
bt.body = nil
|
|
|
|
} else {
|
|
|
|
if bt.body == nil {
|
|
|
|
bt.body = new(BearerTokenBody)
|
|
|
|
}
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = bt.body.FromGRPCMessage(body)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sig := v.GetSignature()
|
|
|
|
if sig == nil {
|
|
|
|
bt.sig = nil
|
|
|
|
} else {
|
|
|
|
if bt.sig == nil {
|
|
|
|
bt.sig = new(refs.Signature)
|
|
|
|
}
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = bt.sig.FromGRPCMessage(sig)
|
|
|
|
}
|
2020-08-20 10:07:35 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return err
|
2020-08-20 10:07:35 +00:00
|
|
|
}
|