github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/grpcwrapper/rawscheme/entry.go (about) 1 package rawscheme 2 3 import ( 4 "errors" 5 6 "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Scheme" 7 8 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" 9 ) 10 11 var ( 12 errUnexpectedNilForSchemePermissions = xerrors.Wrap(errors.New("ydb: unexpected nil for scheme permissions")) 13 errUnexpectedNilForSchemeEntry = xerrors.Wrap(errors.New("ydb: unexpected nil for scheme entry")) 14 ) 15 16 type Entry struct { 17 Name string 18 Owner string 19 Type EntryType 20 EffectivePermissions []Permissions 21 Permissions []Permissions 22 SizeBytes uint64 23 } 24 25 func (e *Entry) FromProto(proto *Ydb_Scheme.Entry) error { 26 if proto == nil { 27 return xerrors.WithStackTrace(errUnexpectedNilForSchemeEntry) 28 } 29 e.Name = proto.GetName() 30 e.Owner = proto.GetOwner() 31 e.Type = EntryType(proto.GetType()) 32 33 e.EffectivePermissions = make([]Permissions, len(proto.GetEffectivePermissions())) 34 for i := range proto.GetEffectivePermissions() { 35 if err := e.EffectivePermissions[i].FromProto(proto.GetEffectivePermissions()[i]); err != nil { 36 return err 37 } 38 } 39 40 e.Permissions = make([]Permissions, len(proto.GetPermissions())) 41 for i := range proto.GetPermissions() { 42 if err := e.Permissions[i].FromProto(proto.GetPermissions()[i]); err != nil { 43 return err 44 } 45 } 46 47 e.SizeBytes = proto.GetSizeBytes() 48 49 return nil 50 } 51 52 type EntryType int 53 54 const ( 55 EntryTypeUnspecified = EntryType(Ydb_Scheme.Entry_TYPE_UNSPECIFIED) 56 EntryTypeDirectory = EntryType(Ydb_Scheme.Entry_DIRECTORY) 57 EntryTypeTable = EntryType(Ydb_Scheme.Entry_TABLE) 58 EntryTypePersQueueGroup = EntryType(Ydb_Scheme.Entry_PERS_QUEUE_GROUP) 59 EntryTypeDatabase = EntryType(Ydb_Scheme.Entry_DATABASE) 60 EntryTypeRtmrVolume = EntryType(Ydb_Scheme.Entry_RTMR_VOLUME) 61 EntryTypeBlockStoreVolume = EntryType(Ydb_Scheme.Entry_BLOCK_STORE_VOLUME) 62 EntryTypeCoordinationNode = EntryType(Ydb_Scheme.Entry_COORDINATION_NODE) 63 EntryTypeSequence = EntryType(Ydb_Scheme.Entry_SEQUENCE) 64 EntryTypeReplication = EntryType(Ydb_Scheme.Entry_REPLICATION) 65 EntryTypeTopic = EntryType(Ydb_Scheme.Entry_TOPIC) 66 ) 67 68 type Permissions struct { 69 Subject string 70 PermissionNames []string 71 } 72 73 func (p *Permissions) FromProto(proto *Ydb_Scheme.Permissions) error { 74 if proto == nil { 75 return xerrors.WithStackTrace(errUnexpectedNilForSchemePermissions) 76 } 77 p.Subject = proto.GetSubject() 78 p.PermissionNames = proto.GetPermissionNames() 79 80 return nil 81 }