-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
lookup_service.go
63 lines (56 loc) · 1.48 KB
/
lookup_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package kv
import (
"context"
"github.com/influxdata/influxdb/v2"
)
var _ influxdb.LookupService = (*Service)(nil)
// Name returns the name for the resource and ID.
func (s *Service) Name(ctx context.Context, resource influxdb.ResourceType, id influxdb.ID) (string, error) {
if err := resource.Valid(); err != nil {
return "", err
}
if ok := id.Valid(); !ok {
return "", influxdb.ErrInvalidID
}
switch resource {
case influxdb.TasksResourceType: // 5 // TODO(goller): unify task storage here so we can lookup names
case influxdb.AuthorizationsResourceType: // 0 TODO(goller): authorizations should also have optional names
case influxdb.BucketsResourceType: // 1
r, err := s.FindBucketByID(ctx, id)
if err != nil {
return "", err
}
return r.Name, nil
case influxdb.DashboardsResourceType: // 2
r, err := s.FindDashboardByID(ctx, id)
if err != nil {
return "", err
}
return r.Name, nil
case influxdb.OrgsResourceType: // 3
r, err := s.FindOrganizationByID(ctx, id)
if err != nil {
return "", err
}
return r.Name, nil
case influxdb.SourcesResourceType: // 4
r, err := s.FindSourceByID(ctx, id)
if err != nil {
return "", err
}
return r.Name, nil
case influxdb.TelegrafsResourceType: // 6
r, err := s.FindTelegrafConfigByID(ctx, id)
if err != nil {
return "", err
}
return r.Name, nil
case influxdb.UsersResourceType: // 7
r, err := s.FindUserByID(ctx, id)
if err != nil {
return "", err
}
return r.Name, nil
}
return "", nil
}