github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/scheme/scheme.go (about) 1 package scheme 2 3 import ( 4 "context" 5 6 "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Scheme" 7 ) 8 9 type Client interface { 10 Database() string 11 12 DescribePath(ctx context.Context, path string) (e Entry, err error) 13 MakeDirectory(ctx context.Context, path string) (err error) 14 ListDirectory(ctx context.Context, path string) (d Directory, err error) 15 RemoveDirectory(ctx context.Context, path string) (err error) 16 ModifyPermissions(ctx context.Context, path string, opts ...PermissionsOption) (err error) 17 } 18 19 type EntryType uint 20 21 type Directory struct { 22 Entry 23 Children []Entry 24 } 25 26 const ( 27 EntryTypeUnknown EntryType = iota 28 EntryDirectory 29 EntryTable 30 EntryPersQueueGroup 31 EntryDatabase 32 EntryRtmrVolume 33 EntryBlockStoreVolume 34 EntryCoordinationNode 35 EntryTopic 36 EntryColumnStore 37 EntryColumnTable 38 ) 39 40 func (t EntryType) String() string { 41 switch t { 42 default: 43 return "Unknown" 44 case EntryDirectory: 45 return "Directory" 46 case EntryTable: 47 return "Table" 48 case EntryPersQueueGroup: 49 return "PersQueueGroup" 50 case EntryDatabase: 51 return "Database" 52 case EntryRtmrVolume: 53 return "RtmrVolume" 54 case EntryBlockStoreVolume: 55 return "BlockStoreVolume" 56 case EntryCoordinationNode: 57 return "CoordinationNode" 58 case EntryTopic: 59 return "Topic" 60 case EntryColumnStore: 61 return "ColumnStore" 62 case EntryColumnTable: 63 return "ColumnTable" 64 } 65 } 66 67 type Entry struct { 68 Name string 69 Owner string 70 Type EntryType 71 Permissions []Permissions 72 EffectivePermissions []Permissions 73 } 74 75 func (e *Entry) IsDirectory() bool { 76 return e.Type == EntryDirectory 77 } 78 79 func (e *Entry) IsTable() bool { 80 return e.Type == EntryTable 81 } 82 83 func (e *Entry) IsColumnTable() bool { 84 return e.Type == EntryColumnTable 85 } 86 87 func (e *Entry) IsPersQueueGroup() bool { 88 return e.Type == EntryPersQueueGroup 89 } 90 91 func (e *Entry) IsDatabase() bool { 92 return e.Type == EntryDatabase 93 } 94 95 func (e *Entry) IsRtmrVolume() bool { 96 return e.Type == EntryRtmrVolume 97 } 98 99 func (e *Entry) IsBlockStoreVolume() bool { 100 return e.Type == EntryBlockStoreVolume 101 } 102 103 func (e *Entry) IsCoordinationNode() bool { 104 return e.Type == EntryCoordinationNode 105 } 106 107 func (e *Entry) IsTopic() bool { 108 return e.Type == EntryTopic 109 } 110 111 func (e *Entry) From(y *Ydb_Scheme.Entry) { 112 *e = Entry{ 113 Name: y.GetName(), 114 Owner: y.GetOwner(), 115 Type: entryType(y.GetType()), 116 Permissions: makePermissions(y.GetPermissions()), 117 EffectivePermissions: makePermissions(y.GetEffectivePermissions()), 118 } 119 } 120 121 func entryType(t Ydb_Scheme.Entry_Type) EntryType { 122 switch t { 123 case Ydb_Scheme.Entry_DIRECTORY: 124 return EntryDirectory 125 case Ydb_Scheme.Entry_TABLE: 126 return EntryTable 127 case Ydb_Scheme.Entry_PERS_QUEUE_GROUP: 128 return EntryPersQueueGroup 129 case Ydb_Scheme.Entry_DATABASE: 130 return EntryDatabase 131 case Ydb_Scheme.Entry_RTMR_VOLUME: 132 return EntryRtmrVolume 133 case Ydb_Scheme.Entry_BLOCK_STORE_VOLUME: 134 return EntryBlockStoreVolume 135 case Ydb_Scheme.Entry_COORDINATION_NODE: 136 return EntryCoordinationNode 137 case Ydb_Scheme.Entry_TOPIC: 138 return EntryTopic 139 case Ydb_Scheme.Entry_COLUMN_STORE: 140 return EntryColumnStore 141 case Ydb_Scheme.Entry_COLUMN_TABLE: 142 return EntryColumnTable 143 default: 144 return EntryTypeUnknown 145 } 146 } 147 148 func makePermissions(src []*Ydb_Scheme.Permissions) (dst []Permissions) { 149 for _, p := range src { 150 dst = append(dst, from(p)) 151 } 152 153 return dst 154 } 155 156 func from(y *Ydb_Scheme.Permissions) (p Permissions) { 157 return Permissions{ 158 Subject: y.GetSubject(), 159 PermissionNames: y.GetPermissionNames(), 160 } 161 } 162 163 type Permissions struct { 164 Subject string 165 PermissionNames []string 166 } 167 168 func (p Permissions) To(y *Ydb_Scheme.Permissions) { 169 y.Subject = p.Subject 170 y.PermissionNames = p.PermissionNames 171 } 172 173 func InnerConvertEntry(y *Ydb_Scheme.Entry) *Entry { 174 res := &Entry{} 175 res.From(y) 176 177 return res 178 }