This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
named_entity.go
95 lines (85 loc) · 3.12 KB
/
named_entity.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package adminservice
import (
"context"
"time"
"github.com/lyft/flyteadmin/pkg/audit"
"github.com/lyft/flyteadmin/pkg/rpc/adminservice/util"
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/admin"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (m *AdminService) GetNamedEntity(ctx context.Context, request *admin.NamedEntityGetRequest) (*admin.NamedEntity, error) {
defer m.interceptPanic(ctx, request)
requestedAt := time.Now()
if request == nil {
return nil, status.Errorf(codes.InvalidArgument, "Incorrect request, nil requests not allowed")
}
var response *admin.NamedEntity
var err error
m.Metrics.namedEntityEndpointMetrics.get.Time(func() {
response, err = m.NamedEntityManager.GetNamedEntity(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"GetNamedEntity",
audit.ParametersFromNamedEntityIdentifierAndResource(request.Id, request.ResourceType),
audit.ReadOnly,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.namedEntityEndpointMetrics.get)
}
m.Metrics.namedEntityEndpointMetrics.get.Success()
return response, nil
}
func (m *AdminService) UpdateNamedEntity(ctx context.Context, request *admin.NamedEntityUpdateRequest) (
*admin.NamedEntityUpdateResponse, error) {
defer m.interceptPanic(ctx, request)
requestedAt := time.Now()
if request == nil {
return nil, status.Errorf(codes.InvalidArgument, "Incorrect request, nil requests not allowed")
}
var response *admin.NamedEntityUpdateResponse
var err error
m.Metrics.namedEntityEndpointMetrics.update.Time(func() {
response, err = m.NamedEntityManager.UpdateNamedEntity(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"UpdateNamedEntity",
audit.ParametersFromNamedEntityIdentifierAndResource(request.Id, request.ResourceType),
audit.ReadWrite,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.namedEntityEndpointMetrics.update)
}
m.Metrics.namedEntityEndpointMetrics.update.Success()
return response, nil
}
func (m *AdminService) ListNamedEntities(ctx context.Context, request *admin.NamedEntityListRequest) (
*admin.NamedEntityList, error) {
defer m.interceptPanic(ctx, request)
requestedAt := time.Now()
if request == nil {
return nil, status.Errorf(codes.InvalidArgument, "Incorrect request, nil requests not allowed")
}
var response *admin.NamedEntityList
var err error
m.Metrics.namedEntityEndpointMetrics.list.Time(func() {
response, err = m.NamedEntityManager.ListNamedEntities(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"ListNamedEntities",
map[string]string{
audit.Project: request.Project,
audit.Domain: request.Domain,
audit.ResourceType: request.ResourceType.String(),
},
audit.ReadOnly,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.namedEntityEndpointMetrics.list)
}
m.Metrics.namedEntityEndpointMetrics.list.Success()
return response, nil
}