@@ -7,12 +7,12 @@ import (
7
7
"github.com/influxdata/influxdb/v2"
8
8
)
9
9
10
- // OrgIDResolver is a type which combines multiple resource services
10
+ // Resolver is a type which combines multiple resource services
11
11
// in order to resolve the resources associated org ID.
12
12
// Ideally you do not need to use this type, it is mostly a stop-gap
13
13
// while we migrate responsibilities off of *kv.Service.
14
14
// Consider it deprecated.
15
- type OrgIDResolver struct {
15
+ type Resolver struct {
16
16
AuthorizationFinder interface {
17
17
FindAuthorizationByID (context.Context , influxdb.ID ) (* influxdb.Authorization , error )
18
18
}
@@ -52,7 +52,7 @@ type OrgIDResolver struct {
52
52
}
53
53
54
54
// FindResourceOrganizationID is used to find the organization that a resource belongs to five the id of a resource and a resource type.
55
- func (o * OrgIDResolver ) FindResourceOrganizationID (ctx context.Context , rt influxdb.ResourceType , id influxdb.ID ) (influxdb.ID , error ) {
55
+ func (o * Resolver ) FindResourceOrganizationID (ctx context.Context , rt influxdb.ResourceType , id influxdb.ID ) (influxdb.ID , error ) {
56
56
switch rt {
57
57
case influxdb .AuthorizationsResourceType :
58
58
if o .AuthorizationFinder == nil {
@@ -192,3 +192,137 @@ func (o *OrgIDResolver) FindResourceOrganizationID(ctx context.Context, rt influ
192
192
Msg : fmt .Sprintf ("unsupported resource type %s" , rt ),
193
193
}
194
194
}
195
+
196
+ // FindResourceName is used to find the name of the resource associated with the provided type and id.
197
+ func (o * Resolver ) FindResourceName (ctx context.Context , rt influxdb.ResourceType , id influxdb.ID ) (string , error ) {
198
+ switch rt {
199
+ case influxdb .AuthorizationsResourceType :
200
+ // keeping this consistent with the original kv implementation
201
+ return "" , nil
202
+ case influxdb .BucketsResourceType :
203
+ if o .BucketFinder == nil {
204
+ break
205
+ }
206
+
207
+ r , err := o .BucketFinder .FindBucketByID (ctx , id )
208
+ if err != nil {
209
+ return "" , err
210
+ }
211
+
212
+ return r .Name , nil
213
+ case influxdb .OrgsResourceType :
214
+ if o .OrganizationFinder == nil {
215
+ break
216
+ }
217
+
218
+ r , err := o .OrganizationFinder .FindOrganizationByID (ctx , id )
219
+ if err != nil {
220
+ return "" , err
221
+ }
222
+
223
+ return r .Name , nil
224
+ case influxdb .DashboardsResourceType :
225
+ if o .DashboardFinder == nil {
226
+ break
227
+ }
228
+
229
+ r , err := o .DashboardFinder .FindDashboardByID (ctx , id )
230
+ if err != nil {
231
+ return "" , err
232
+ }
233
+
234
+ return r .Name , nil
235
+ case influxdb .SourcesResourceType :
236
+ if o .SourceFinder == nil {
237
+ break
238
+ }
239
+
240
+ r , err := o .SourceFinder .FindSourceByID (ctx , id )
241
+ if err != nil {
242
+ return "" , err
243
+ }
244
+
245
+ return r .Name , nil
246
+ case influxdb .TasksResourceType :
247
+ if o .TaskFinder == nil {
248
+ break
249
+ }
250
+
251
+ r , err := o .TaskFinder .FindTaskByID (ctx , id )
252
+ if err != nil {
253
+ return "" , err
254
+ }
255
+
256
+ return r .Name , nil
257
+ case influxdb .TelegrafsResourceType :
258
+ if o .TelegrafConfigFinder == nil {
259
+ break
260
+ }
261
+
262
+ r , err := o .TelegrafConfigFinder .FindTelegrafConfigByID (ctx , id )
263
+ if err != nil {
264
+ return "" , err
265
+ }
266
+
267
+ return r .Name , nil
268
+ case influxdb .VariablesResourceType :
269
+ if o .VariableFinder == nil {
270
+ break
271
+ }
272
+
273
+ r , err := o .VariableFinder .FindVariableByID (ctx , id )
274
+ if err != nil {
275
+ return "" , nil
276
+ }
277
+
278
+ return r .Name , nil
279
+ case influxdb .ScraperResourceType :
280
+ if o .TargetFinder == nil {
281
+ break
282
+ }
283
+
284
+ r , err := o .TargetFinder .GetTargetByID (ctx , id )
285
+ if err != nil {
286
+ return "" , err
287
+ }
288
+
289
+ return r .Name , nil
290
+ case influxdb .ChecksResourceType :
291
+ if o .CheckFinder == nil {
292
+ break
293
+ }
294
+
295
+ r , err := o .CheckFinder .FindCheckByID (ctx , id )
296
+ if err != nil {
297
+ return "" , err
298
+ }
299
+
300
+ return r .GetName (), nil
301
+ case influxdb .NotificationEndpointResourceType :
302
+ if o .NotificationEndpointFinder == nil {
303
+ break
304
+ }
305
+
306
+ r , err := o .NotificationEndpointFinder .FindNotificationEndpointByID (ctx , id )
307
+ if err != nil {
308
+ return "" , err
309
+ }
310
+
311
+ return r .GetName (), nil
312
+ case influxdb .NotificationRuleResourceType :
313
+ if o .NotificationRuleFinder == nil {
314
+ break
315
+ }
316
+
317
+ r , err := o .NotificationRuleFinder .FindNotificationRuleByID (ctx , id )
318
+ if err != nil {
319
+ return "" , err
320
+ }
321
+
322
+ return r .GetName (), nil
323
+ }
324
+
325
+ // default behaviour (in-line with original implementation) is to just return
326
+ // an empty name
327
+ return "" , nil
328
+ }
0 commit comments