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 62
/
attributes.go
211 lines (194 loc) · 7.16 KB
/
attributes.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package adminservice
import (
"context"
"time"
"github.com/flyteorg/flyteadmin/pkg/audit"
"github.com/flyteorg/flyteadmin/pkg/rpc/adminservice/util"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (m *AdminService) UpdateWorkflowAttributes(ctx context.Context, request *admin.WorkflowAttributesUpdateRequest) (
*admin.WorkflowAttributesUpdateResponse, 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.WorkflowAttributesUpdateResponse
var err error
m.Metrics.workflowAttributesEndpointMetrics.update.Time(func() {
response, err = m.ResourceManager.UpdateWorkflowAttributes(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"UpdateWorkflowAttributes",
map[string]string{
audit.Project: request.Attributes.Project,
audit.Domain: request.Attributes.Domain,
audit.Name: request.Attributes.Workflow,
},
audit.ReadWrite,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.workflowAttributesEndpointMetrics.update)
}
return response, nil
}
func (m *AdminService) GetWorkflowAttributes(ctx context.Context, request *admin.WorkflowAttributesGetRequest) (
*admin.WorkflowAttributesGetResponse, 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.WorkflowAttributesGetResponse
var err error
m.Metrics.workflowAttributesEndpointMetrics.get.Time(func() {
response, err = m.ResourceManager.GetWorkflowAttributes(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"GetWorkflowAttributes",
map[string]string{
audit.Project: request.Project,
audit.Domain: request.Domain,
audit.Name: request.Workflow,
},
audit.ReadOnly,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.workflowAttributesEndpointMetrics.get)
}
return response, nil
}
func (m *AdminService) DeleteWorkflowAttributes(ctx context.Context, request *admin.WorkflowAttributesDeleteRequest) (
*admin.WorkflowAttributesDeleteResponse, 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.WorkflowAttributesDeleteResponse
var err error
m.Metrics.workflowAttributesEndpointMetrics.delete.Time(func() {
response, err = m.ResourceManager.DeleteWorkflowAttributes(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"DeleteWorkflowAttributes",
map[string]string{
audit.Project: request.Project,
audit.Domain: request.Domain,
audit.Name: request.Workflow,
},
audit.ReadWrite,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.workflowAttributesEndpointMetrics.delete)
}
return response, nil
}
func (m *AdminService) UpdateProjectDomainAttributes(ctx context.Context, request *admin.ProjectDomainAttributesUpdateRequest) (
*admin.ProjectDomainAttributesUpdateResponse, 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.ProjectDomainAttributesUpdateResponse
var err error
m.Metrics.projectDomainAttributesEndpointMetrics.update.Time(func() {
response, err = m.ResourceManager.UpdateProjectDomainAttributes(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"UpdateProjectDomainAttributes",
map[string]string{
audit.Project: request.Attributes.Project,
audit.Domain: request.Attributes.Domain,
},
audit.ReadWrite,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.projectDomainAttributesEndpointMetrics.update)
}
return response, nil
}
func (m *AdminService) GetProjectDomainAttributes(ctx context.Context, request *admin.ProjectDomainAttributesGetRequest) (
*admin.ProjectDomainAttributesGetResponse, 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.ProjectDomainAttributesGetResponse
var err error
m.Metrics.workflowAttributesEndpointMetrics.get.Time(func() {
response, err = m.ResourceManager.GetProjectDomainAttributes(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"GetProjectDomainAttributes",
map[string]string{
audit.Project: request.Project,
audit.Domain: request.Domain,
},
audit.ReadOnly,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.workflowAttributesEndpointMetrics.get)
}
return response, nil
}
func (m *AdminService) DeleteProjectDomainAttributes(ctx context.Context, request *admin.ProjectDomainAttributesDeleteRequest) (
*admin.ProjectDomainAttributesDeleteResponse, 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.ProjectDomainAttributesDeleteResponse
var err error
m.Metrics.workflowAttributesEndpointMetrics.delete.Time(func() {
response, err = m.ResourceManager.DeleteProjectDomainAttributes(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"DeleteProjectDomainAttributes",
map[string]string{
audit.Project: request.Project,
audit.Domain: request.Domain,
},
audit.ReadWrite,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.workflowAttributesEndpointMetrics.delete)
}
return response, nil
}
func (m *AdminService) ListMatchableAttributes(ctx context.Context, request *admin.ListMatchableAttributesRequest) (
*admin.ListMatchableAttributesResponse, 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.ListMatchableAttributesResponse
var err error
m.Metrics.matchableAttributesEndpointMetrics.list.Time(func() {
response, err = m.ResourceManager.ListAll(ctx, *request)
})
audit.NewLogBuilder().WithAuthenticatedCtx(ctx).WithRequest(
"ListMatchableAttributes",
map[string]string{
audit.ResourceType: request.ResourceType.String(),
},
audit.ReadOnly,
requestedAt,
).WithResponse(time.Now(), err).Log(ctx)
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.matchableAttributesEndpointMetrics.list)
}
return response, nil
}