@valon-technologies/gestalt 0.0.1-alpha.33 → 0.0.1-alpha.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -5
- package/package.json +1 -1
- package/src/agent-access.ts +7 -4
- package/src/agent-conversions.ts +0 -37
- package/src/agent.ts +14 -20
- package/src/api.ts +17 -13
- package/src/authorization.ts +619 -1436
- package/src/index.ts +45 -229
- package/src/internal/gen/v1/agent_pb.ts +55 -84
- package/src/internal/gen/v1/app_pb.ts +4 -19
- package/src/internal/gen/v1/authorization_pb.ts +407 -781
- package/src/internal/gen/v1/runtime_provider_pb.ts +1 -0
- package/src/internal/gen/v1/workflow_pb.ts +678 -737
- package/src/provider-kind.ts +6 -6
- package/src/provider.ts +1 -1
- package/src/runtime.ts +15 -23
- package/src/workflow-access.ts +340 -385
- package/src/workflow.ts +1201 -2443
package/src/authorization.ts
CHANGED
|
@@ -1,670 +1,342 @@
|
|
|
1
1
|
import { create } from "@bufbuild/protobuf";
|
|
2
|
-
import { EmptySchema } from "@bufbuild/protobuf/wkt";
|
|
3
2
|
import {
|
|
4
3
|
Code,
|
|
5
4
|
ConnectError,
|
|
6
|
-
createClient,
|
|
7
|
-
type Client,
|
|
8
5
|
type ServiceImpl,
|
|
9
6
|
} from "@connectrpc/connect";
|
|
10
7
|
|
|
11
8
|
import {
|
|
12
|
-
|
|
13
|
-
AccessEvaluationRequestSchema,
|
|
14
|
-
AccessEvaluationsRequestSchema,
|
|
15
|
-
AccessEvaluationsResponseSchema,
|
|
16
|
-
ActionSearchRequestSchema,
|
|
17
|
-
ActionSearchResponseSchema,
|
|
18
|
-
ActionSchema,
|
|
19
|
-
AuthorizationMetadataSchema,
|
|
9
|
+
AddRelationshipResponseSchema,
|
|
20
10
|
AuthorizationModelRefSchema,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
RelationshipKeySchema,
|
|
11
|
+
AuthorizationModelResourceTypeSchema,
|
|
12
|
+
CheckAccessManyResponseSchema,
|
|
13
|
+
CheckAccessResponseSchema,
|
|
14
|
+
DefaultAccessPolicy as ProtoDefaultAccessPolicy,
|
|
15
|
+
DeleteRelationshipResponseSchema,
|
|
16
|
+
GetActiveModelRefResponseSchema,
|
|
17
|
+
ListActiveModelResourceTypesResponseSchema,
|
|
18
|
+
ListRelationshipsResponseSchema,
|
|
19
|
+
ModelActionSchema,
|
|
20
|
+
ModelAllowedTargetSchema,
|
|
21
|
+
ModelRelationSchema,
|
|
33
22
|
RelationshipSchema,
|
|
34
23
|
RelationshipTargetSchema,
|
|
24
|
+
RelationshipTargetType as ProtoRelationshipTargetType,
|
|
25
|
+
RelationshipTupleSchema,
|
|
35
26
|
ResourceSchema,
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
SetActiveModelResponseSchema,
|
|
28
|
+
SetAuthorizationStateResponseSchema,
|
|
29
|
+
SourceLayer as ProtoSourceLayer,
|
|
38
30
|
SubjectSchema,
|
|
39
|
-
SubjectSearchRequestSchema,
|
|
40
|
-
SubjectSearchResponseSchema,
|
|
41
31
|
SubjectSetSchema,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
type
|
|
45
|
-
type AccessEvaluationRequest as ProtoAccessEvaluationRequest,
|
|
46
|
-
type AccessEvaluationsRequest as ProtoAccessEvaluationsRequest,
|
|
47
|
-
type AccessEvaluationsResponse as ProtoAccessEvaluationsResponse,
|
|
48
|
-
type Action as ProtoAction,
|
|
49
|
-
type ActionSearchRequest as ProtoActionSearchRequest,
|
|
50
|
-
type ActionSearchResponse as ProtoActionSearchResponse,
|
|
51
|
-
type AuthorizationMetadata as ProtoAuthorizationMetadata,
|
|
32
|
+
SubjectSetTypeSchema,
|
|
33
|
+
AuthorizationProvider as AuthorizationProviderService,
|
|
34
|
+
type AddRelationshipRequest as ProtoAddRelationshipRequest,
|
|
52
35
|
type AuthorizationModel as ProtoAuthorizationModel,
|
|
53
|
-
type AuthorizationModelAction as ProtoAuthorizationModelAction,
|
|
54
|
-
type AuthorizationModelAllowedTarget as ProtoAuthorizationModelAllowedTarget,
|
|
55
|
-
type AuthorizationModelComputedUserset as ProtoAuthorizationModelComputedUserset,
|
|
56
|
-
type AuthorizationModelRef as ProtoAuthorizationModelRef,
|
|
57
|
-
type AuthorizationModelRelation as ProtoAuthorizationModelRelation,
|
|
58
36
|
type AuthorizationModelResourceType as ProtoAuthorizationModelResourceType,
|
|
59
|
-
type
|
|
60
|
-
type
|
|
61
|
-
type
|
|
62
|
-
type
|
|
63
|
-
type
|
|
64
|
-
type
|
|
65
|
-
type ExpandNode as ProtoExpandNode,
|
|
66
|
-
type ExpandRequest as ProtoExpandRequest,
|
|
67
|
-
type ExpandResponse as ProtoExpandResponse,
|
|
68
|
-
type GetActiveModelResponse as ProtoGetActiveModelResponse,
|
|
69
|
-
type ListModelsRequest as ProtoListModelsRequest,
|
|
70
|
-
type ListModelsResponse as ProtoListModelsResponse,
|
|
71
|
-
type ReadRelationshipsRequest as ProtoReadRelationshipsRequest,
|
|
72
|
-
type ReadRelationshipsResponse as ProtoReadRelationshipsResponse,
|
|
37
|
+
type CheckAccessManyRequest as ProtoCheckAccessManyRequest,
|
|
38
|
+
type CheckAccessRequest as ProtoCheckAccessRequest,
|
|
39
|
+
type DeleteRelationshipRequest as ProtoDeleteRelationshipRequest,
|
|
40
|
+
type ListActiveModelResourceTypesRequest as ProtoListActiveModelResourceTypesRequest,
|
|
41
|
+
type ListRelationshipsRequest as ProtoListRelationshipsRequest,
|
|
42
|
+
type ModelAllowedTarget as ProtoModelAllowedTarget,
|
|
73
43
|
type Relationship as ProtoRelationship,
|
|
74
|
-
type
|
|
44
|
+
type RelationshipFilter as ProtoRelationshipFilter,
|
|
75
45
|
type RelationshipTarget as ProtoRelationshipTarget,
|
|
76
|
-
type
|
|
77
|
-
type
|
|
78
|
-
type
|
|
79
|
-
type Subject as ProtoSubject,
|
|
80
|
-
type SubjectSearchRequest as ProtoSubjectSearchRequest,
|
|
81
|
-
type SubjectSearchResponse as ProtoSubjectSearchResponse,
|
|
46
|
+
type RelationshipTuple as ProtoRelationshipTuple,
|
|
47
|
+
type SetActiveModelRequest as ProtoSetActiveModelRequest,
|
|
48
|
+
type SetAuthorizationStateRequest as ProtoSetAuthorizationStateRequest,
|
|
82
49
|
type SubjectSet as ProtoSubjectSet,
|
|
83
|
-
type WriteModelRequest as ProtoWriteModelRequest,
|
|
84
|
-
type WriteRelationshipsRequest as ProtoWriteRelationshipsRequest,
|
|
85
50
|
} from "./internal/gen/v1/authorization_pb.ts";
|
|
51
|
+
import { errorMessage, type MaybePromise } from "./api.ts";
|
|
52
|
+
import { ProviderBase, type ProviderBaseOptions } from "./provider.ts";
|
|
86
53
|
import {
|
|
87
|
-
|
|
54
|
+
jsonObjectFromStruct,
|
|
55
|
+
structFromObject,
|
|
88
56
|
timestampFromDate,
|
|
89
57
|
type JsonObjectInput,
|
|
90
58
|
} from "./protocol.ts";
|
|
91
|
-
import {
|
|
92
|
-
optionalObjectFromStruct,
|
|
93
|
-
optionalStruct,
|
|
94
|
-
} from "./protocol-internal.ts";
|
|
95
|
-
import type { MaybePromise } from "./api.ts";
|
|
96
|
-
import { ProviderBase, type ProviderBaseOptions } from "./provider.ts";
|
|
97
|
-
import {
|
|
98
|
-
createHostServiceGrpcTransport,
|
|
99
|
-
hostServiceMetadataInterceptors,
|
|
100
|
-
parseHostServiceTarget,
|
|
101
|
-
ENV_HOST_SERVICE_SOCKET,
|
|
102
|
-
ENV_HOST_SERVICE_TOKEN,
|
|
103
|
-
} from "./host-service.ts";
|
|
104
|
-
|
|
105
|
-
type AuthorizationProviderServiceImpl = Partial<
|
|
106
|
-
ServiceImpl<typeof AuthorizationProviderService>
|
|
107
|
-
>;
|
|
108
59
|
|
|
109
|
-
|
|
110
|
-
|
|
60
|
+
export const RelationshipTargetType = {
|
|
61
|
+
UNSPECIFIED: ProtoRelationshipTargetType.UNSPECIFIED,
|
|
62
|
+
SUBJECT: ProtoRelationshipTargetType.SUBJECT,
|
|
63
|
+
RESOURCE: ProtoRelationshipTargetType.RESOURCE,
|
|
64
|
+
SUBJECT_SET: ProtoRelationshipTargetType.SUBJECT_SET,
|
|
65
|
+
} as const;
|
|
66
|
+
export type RelationshipTargetType =
|
|
67
|
+
(typeof RelationshipTargetType)[keyof typeof RelationshipTargetType];
|
|
68
|
+
|
|
69
|
+
export const SourceLayer = {
|
|
70
|
+
UNSPECIFIED: ProtoSourceLayer.UNSPECIFIED,
|
|
71
|
+
STATIC_CONFIG: ProtoSourceLayer.STATIC_CONFIG,
|
|
72
|
+
RUNTIME: ProtoSourceLayer.RUNTIME,
|
|
73
|
+
} as const;
|
|
74
|
+
export type SourceLayer = (typeof SourceLayer)[keyof typeof SourceLayer];
|
|
75
|
+
|
|
76
|
+
export const DefaultAccessPolicy = {
|
|
77
|
+
DENY: ProtoDefaultAccessPolicy.DENY,
|
|
78
|
+
ALLOW: ProtoDefaultAccessPolicy.ALLOW,
|
|
79
|
+
} as const;
|
|
80
|
+
export type DefaultAccessPolicy =
|
|
81
|
+
(typeof DefaultAccessPolicy)[keyof typeof DefaultAccessPolicy];
|
|
111
82
|
|
|
112
83
|
export interface AuthorizationSubject {
|
|
113
|
-
type
|
|
114
|
-
id
|
|
84
|
+
type?: string | undefined;
|
|
85
|
+
id?: string | undefined;
|
|
115
86
|
properties?: JsonObjectInput | undefined;
|
|
116
87
|
}
|
|
117
88
|
|
|
118
|
-
export interface
|
|
119
|
-
|
|
120
|
-
id: string;
|
|
89
|
+
export interface AuthorizationAction {
|
|
90
|
+
name?: string | undefined;
|
|
121
91
|
properties?: JsonObjectInput | undefined;
|
|
122
92
|
}
|
|
123
93
|
|
|
124
|
-
export interface
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export type AuthorizationRelationshipTargetKind =
|
|
130
|
-
| { case: "subject"; value: AuthorizationSubject }
|
|
131
|
-
| { case: "resource"; value: AuthorizationResource }
|
|
132
|
-
| { case: "subjectSet"; value: AuthorizationSubjectSet }
|
|
133
|
-
| { case: undefined; value?: undefined };
|
|
134
|
-
|
|
135
|
-
export interface AuthorizationRelationshipTarget {
|
|
136
|
-
kind: AuthorizationRelationshipTargetKind;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export interface AuthorizationAction {
|
|
140
|
-
name: string;
|
|
94
|
+
export interface AuthorizationResource {
|
|
95
|
+
type?: string | undefined;
|
|
96
|
+
id?: string | undefined;
|
|
141
97
|
properties?: JsonObjectInput | undefined;
|
|
142
98
|
}
|
|
143
99
|
|
|
144
|
-
export interface
|
|
100
|
+
export interface CheckAccessRequest {
|
|
145
101
|
subject?: AuthorizationSubject | undefined;
|
|
146
102
|
action?: AuthorizationAction | undefined;
|
|
147
103
|
resource?: AuthorizationResource | undefined;
|
|
148
|
-
context?: JsonObjectInput | undefined;
|
|
149
104
|
}
|
|
150
105
|
|
|
151
|
-
export interface
|
|
106
|
+
export interface CheckAccessResponse {
|
|
152
107
|
allowed?: boolean | undefined;
|
|
153
|
-
context?: JsonObjectInput | undefined;
|
|
154
108
|
modelId?: string | undefined;
|
|
155
109
|
}
|
|
156
110
|
|
|
157
|
-
export interface
|
|
158
|
-
requests
|
|
111
|
+
export interface CheckAccessManyRequest {
|
|
112
|
+
requests?: readonly CheckAccessRequest[] | undefined;
|
|
159
113
|
}
|
|
160
114
|
|
|
161
|
-
export interface
|
|
162
|
-
decisions
|
|
115
|
+
export interface CheckAccessManyResponse {
|
|
116
|
+
decisions?: readonly CheckAccessResponse[] | undefined;
|
|
163
117
|
}
|
|
164
118
|
|
|
165
|
-
export interface
|
|
166
|
-
|
|
167
|
-
|
|
119
|
+
export interface RelationshipFilter {
|
|
120
|
+
target?: RelationshipTarget | undefined;
|
|
121
|
+
relation?: string | undefined;
|
|
122
|
+
resource?: AuthorizationResource | undefined;
|
|
123
|
+
targetType?: RelationshipTargetType | undefined;
|
|
124
|
+
targetEntityType?: string | undefined;
|
|
168
125
|
resourceType?: string | undefined;
|
|
169
|
-
|
|
170
|
-
pageSize?: number | undefined;
|
|
171
|
-
pageToken?: string | undefined;
|
|
126
|
+
sourceLayer?: SourceLayer | undefined;
|
|
172
127
|
}
|
|
173
128
|
|
|
174
|
-
export interface
|
|
175
|
-
|
|
176
|
-
nextPageToken?: string | undefined;
|
|
177
|
-
modelId?: string | undefined;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export interface AuthorizationSearchSubjectsInput {
|
|
181
|
-
resource?: AuthorizationResource | undefined;
|
|
182
|
-
action?: AuthorizationAction | undefined;
|
|
183
|
-
subjectType?: string | undefined;
|
|
184
|
-
context?: JsonObjectInput | undefined;
|
|
129
|
+
export interface ListRelationshipsRequest {
|
|
130
|
+
filter?: RelationshipFilter | undefined;
|
|
185
131
|
pageSize?: number | undefined;
|
|
186
132
|
pageToken?: string | undefined;
|
|
187
133
|
}
|
|
188
134
|
|
|
189
|
-
export interface
|
|
190
|
-
|
|
135
|
+
export interface ListRelationshipsResponse {
|
|
136
|
+
relationships?: readonly Relationship[] | undefined;
|
|
191
137
|
nextPageToken?: string | undefined;
|
|
192
|
-
modelId?: string | undefined;
|
|
193
138
|
}
|
|
194
139
|
|
|
195
|
-
export interface
|
|
196
|
-
|
|
197
|
-
action?: AuthorizationAction | undefined;
|
|
198
|
-
context?: JsonObjectInput | undefined;
|
|
199
|
-
pageSize?: number | undefined;
|
|
200
|
-
pageToken?: string | undefined;
|
|
140
|
+
export interface AddRelationshipRequest {
|
|
141
|
+
relationship?: Relationship | undefined;
|
|
201
142
|
}
|
|
202
143
|
|
|
203
|
-
export interface
|
|
204
|
-
|
|
205
|
-
nextPageToken?: string | undefined;
|
|
206
|
-
modelId?: string | undefined;
|
|
207
|
-
truncated?: boolean | undefined;
|
|
144
|
+
export interface AddRelationshipResponse {
|
|
145
|
+
relationship?: Relationship | undefined;
|
|
208
146
|
}
|
|
209
147
|
|
|
210
|
-
export interface
|
|
211
|
-
|
|
212
|
-
resource?: AuthorizationResource | undefined;
|
|
213
|
-
context?: JsonObjectInput | undefined;
|
|
214
|
-
pageSize?: number | undefined;
|
|
215
|
-
pageToken?: string | undefined;
|
|
148
|
+
export interface DeleteRelationshipRequest {
|
|
149
|
+
relationshipTuple?: RelationshipTuple | undefined;
|
|
216
150
|
}
|
|
217
151
|
|
|
218
|
-
export interface
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
152
|
+
export interface DeleteRelationshipResponse {}
|
|
153
|
+
|
|
154
|
+
export interface SetAuthorizationStateRequest {
|
|
155
|
+
model?: AuthorizationModel | undefined;
|
|
156
|
+
relationships?: readonly Relationship[] | undefined;
|
|
222
157
|
}
|
|
223
158
|
|
|
224
|
-
export interface
|
|
225
|
-
|
|
226
|
-
activeModelId?: string | undefined;
|
|
159
|
+
export interface SetAuthorizationStateResponse {
|
|
160
|
+
activeModel?: AuthorizationModelRef | undefined;
|
|
227
161
|
}
|
|
228
162
|
|
|
229
|
-
export interface
|
|
230
|
-
|
|
231
|
-
relation: string;
|
|
232
|
-
resource?: AuthorizationResource | undefined;
|
|
163
|
+
export interface Relationship {
|
|
164
|
+
tuple?: RelationshipTuple | undefined;
|
|
233
165
|
properties?: JsonObjectInput | undefined;
|
|
234
|
-
|
|
166
|
+
sourceLayer?: SourceLayer | undefined;
|
|
235
167
|
}
|
|
236
168
|
|
|
237
|
-
export interface
|
|
238
|
-
|
|
239
|
-
relation
|
|
169
|
+
export interface RelationshipTuple {
|
|
170
|
+
target?: RelationshipTarget | undefined;
|
|
171
|
+
relation?: string | undefined;
|
|
240
172
|
resource?: AuthorizationResource | undefined;
|
|
241
|
-
target?: AuthorizationRelationshipTarget | undefined;
|
|
242
173
|
}
|
|
243
174
|
|
|
244
|
-
export interface
|
|
175
|
+
export interface RelationshipTarget {
|
|
245
176
|
subject?: AuthorizationSubject | undefined;
|
|
246
|
-
relation?: string | undefined;
|
|
247
177
|
resource?: AuthorizationResource | undefined;
|
|
248
|
-
|
|
249
|
-
pageToken?: string | undefined;
|
|
250
|
-
modelId?: string | undefined;
|
|
251
|
-
target?: AuthorizationRelationshipTarget | undefined;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
export interface AuthorizationReadRelationships {
|
|
255
|
-
relationships: readonly AuthorizationRelationship[];
|
|
256
|
-
nextPageToken?: string | undefined;
|
|
257
|
-
modelId?: string | undefined;
|
|
178
|
+
subjectSet?: SubjectSet | undefined;
|
|
258
179
|
}
|
|
259
180
|
|
|
260
|
-
export interface
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
modelId?: string | undefined;
|
|
181
|
+
export interface SubjectSet {
|
|
182
|
+
resource?: AuthorizationResource | undefined;
|
|
183
|
+
relation?: string | undefined;
|
|
264
184
|
}
|
|
265
185
|
|
|
266
186
|
export interface AuthorizationModel {
|
|
267
|
-
|
|
187
|
+
id?: string | undefined;
|
|
188
|
+
version?: string | undefined;
|
|
268
189
|
resourceTypes?: readonly AuthorizationModelResourceType[] | undefined;
|
|
269
190
|
}
|
|
270
191
|
|
|
271
192
|
export interface AuthorizationModelResourceType {
|
|
272
|
-
name
|
|
273
|
-
relations?: readonly
|
|
274
|
-
actions?: readonly
|
|
193
|
+
name?: string | undefined;
|
|
194
|
+
relations?: readonly ModelRelation[] | undefined;
|
|
195
|
+
actions?: readonly ModelAction[] | undefined;
|
|
196
|
+
sourceLayer?: SourceLayer | undefined;
|
|
197
|
+
defaultAccessPolicy?: DefaultAccessPolicy | undefined;
|
|
275
198
|
}
|
|
276
199
|
|
|
277
|
-
export interface
|
|
278
|
-
name
|
|
279
|
-
|
|
280
|
-
allowedTargets?: readonly AuthorizationModelAllowedTarget[] | undefined;
|
|
281
|
-
rewrite?: AuthorizationModelRewrite | undefined;
|
|
200
|
+
export interface ModelRelation {
|
|
201
|
+
name?: string | undefined;
|
|
202
|
+
allowedTargets?: readonly ModelAllowedTarget[] | undefined;
|
|
282
203
|
}
|
|
283
204
|
|
|
284
|
-
export interface
|
|
285
|
-
name
|
|
205
|
+
export interface ModelAction {
|
|
206
|
+
name?: string | undefined;
|
|
286
207
|
relations?: readonly string[] | undefined;
|
|
287
|
-
rewrite?: AuthorizationModelRewrite | undefined;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
export type AuthorizationModelAllowedTargetKind =
|
|
291
|
-
| { case: "subjectType"; value: string }
|
|
292
|
-
| { case: "resourceType"; value: string }
|
|
293
|
-
| { case: "subjectSet"; value: AuthorizationModelSubjectSetTarget }
|
|
294
|
-
| { case: undefined; value?: undefined };
|
|
295
|
-
|
|
296
|
-
export interface AuthorizationModelAllowedTarget {
|
|
297
|
-
kind: AuthorizationModelAllowedTargetKind;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
export interface AuthorizationModelSubjectSetTarget {
|
|
301
|
-
resourceType: string;
|
|
302
|
-
relation: string;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
export type AuthorizationModelRewriteKind =
|
|
306
|
-
| { case: "this"; value: AuthorizationModelRewriteThis }
|
|
307
|
-
| { case: "computedUserset"; value: AuthorizationModelComputedUserset }
|
|
308
|
-
| { case: "tupleToUserset"; value: AuthorizationModelTupleToUserset }
|
|
309
|
-
| { case: "union"; value: AuthorizationModelRewriteUnion }
|
|
310
|
-
| { case: undefined; value?: undefined };
|
|
311
|
-
|
|
312
|
-
export interface AuthorizationModelRewrite {
|
|
313
|
-
kind: AuthorizationModelRewriteKind;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
export interface AuthorizationModelRewriteThis {}
|
|
317
|
-
|
|
318
|
-
export interface AuthorizationModelComputedUserset {
|
|
319
|
-
relation: string;
|
|
320
208
|
}
|
|
321
209
|
|
|
322
|
-
export interface
|
|
323
|
-
|
|
324
|
-
|
|
210
|
+
export interface ModelAllowedTarget {
|
|
211
|
+
subjectType?: string | undefined;
|
|
212
|
+
resourceType?: string | undefined;
|
|
213
|
+
subjectSetType?: SubjectSetType | undefined;
|
|
325
214
|
}
|
|
326
215
|
|
|
327
|
-
export interface
|
|
328
|
-
|
|
216
|
+
export interface SubjectSetType {
|
|
217
|
+
resourceType?: string | undefined;
|
|
218
|
+
relation?: string | undefined;
|
|
329
219
|
}
|
|
330
220
|
|
|
331
221
|
export interface AuthorizationModelRef {
|
|
332
|
-
id
|
|
333
|
-
version
|
|
222
|
+
id?: string | undefined;
|
|
223
|
+
version?: string | undefined;
|
|
334
224
|
createdAt?: Date | undefined;
|
|
335
225
|
}
|
|
336
226
|
|
|
337
|
-
export interface
|
|
338
|
-
|
|
339
|
-
relation?: string | undefined;
|
|
340
|
-
context?: JsonObjectInput | undefined;
|
|
341
|
-
maxDepth?: number | undefined;
|
|
342
|
-
modelId?: string | undefined;
|
|
227
|
+
export interface GetActiveModelRefResponse {
|
|
228
|
+
model?: AuthorizationModelRef | undefined;
|
|
343
229
|
}
|
|
344
230
|
|
|
345
|
-
export interface
|
|
346
|
-
|
|
347
|
-
relation?: string | undefined;
|
|
348
|
-
children?: readonly AuthorizationExpandNode[] | undefined;
|
|
231
|
+
export interface SetActiveModelRequest {
|
|
232
|
+
model?: AuthorizationModel | undefined;
|
|
349
233
|
}
|
|
350
234
|
|
|
351
|
-
export interface
|
|
352
|
-
|
|
353
|
-
truncated?: boolean | undefined;
|
|
354
|
-
cycleDetected?: boolean | undefined;
|
|
355
|
-
maxDepthReached?: boolean | undefined;
|
|
356
|
-
modelId?: string | undefined;
|
|
235
|
+
export interface SetActiveModelResponse {
|
|
236
|
+
model?: AuthorizationModelRef | undefined;
|
|
357
237
|
}
|
|
358
238
|
|
|
359
|
-
export interface
|
|
360
|
-
|
|
239
|
+
export interface AuthorizationModelResourceTypeFilter {
|
|
240
|
+
name?: string | undefined;
|
|
241
|
+
sourceLayer?: SourceLayer | undefined;
|
|
361
242
|
}
|
|
362
243
|
|
|
363
|
-
export interface
|
|
244
|
+
export interface ListActiveModelResourceTypesRequest {
|
|
245
|
+
filter?: AuthorizationModelResourceTypeFilter | undefined;
|
|
364
246
|
pageSize?: number | undefined;
|
|
365
247
|
pageToken?: string | undefined;
|
|
366
248
|
}
|
|
367
249
|
|
|
368
|
-
export interface
|
|
369
|
-
|
|
250
|
+
export interface ListActiveModelResourceTypesResponse {
|
|
251
|
+
resourceTypes?: readonly AuthorizationModelResourceType[] | undefined;
|
|
370
252
|
nextPageToken?: string | undefined;
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
export interface AuthorizationWriteModelInput {
|
|
374
|
-
model?: AuthorizationModel | undefined;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
const sharedAuthorizationTransport: {
|
|
378
|
-
target: string;
|
|
379
|
-
token: string;
|
|
380
|
-
client: AuthorizationImpl | undefined;
|
|
381
|
-
} = {
|
|
382
|
-
target: "",
|
|
383
|
-
token: "",
|
|
384
|
-
client: undefined,
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* Fakeable contract for authorization calls.
|
|
389
|
-
*/
|
|
390
|
-
export interface Authorization {
|
|
391
|
-
evaluate(request: AuthorizationEvaluateInput): Promise<AuthorizationDecision>;
|
|
392
|
-
evaluateMany(
|
|
393
|
-
request: AuthorizationEvaluateManyInput,
|
|
394
|
-
): Promise<AuthorizationEvaluationsResponse>;
|
|
395
|
-
searchResources(
|
|
396
|
-
request: AuthorizationSearchResourcesInput,
|
|
397
|
-
): Promise<AuthorizationResourceSearch>;
|
|
398
|
-
searchSubjects(
|
|
399
|
-
request: AuthorizationSearchSubjectsInput,
|
|
400
|
-
): Promise<AuthorizationSubjectSearch>;
|
|
401
|
-
effectiveSearchResources(
|
|
402
|
-
request: AuthorizationSearchResourcesInput,
|
|
403
|
-
): Promise<AuthorizationResourceSearch>;
|
|
404
|
-
effectiveSearchSubjects(
|
|
405
|
-
request: AuthorizationEffectiveSearchSubjectsInput,
|
|
406
|
-
): Promise<AuthorizationEffectiveSubjectSearch>;
|
|
407
|
-
searchActions(
|
|
408
|
-
request: AuthorizationSearchActionsInput,
|
|
409
|
-
): Promise<AuthorizationActionSearch>;
|
|
410
|
-
expand(request: AuthorizationExpandInput): Promise<AuthorizationExpand>;
|
|
411
|
-
readRelationships(
|
|
412
|
-
request: AuthorizationReadRelationshipsInput,
|
|
413
|
-
): Promise<AuthorizationReadRelationships>;
|
|
414
|
-
writeRelationships(
|
|
415
|
-
request: AuthorizationWriteRelationshipsInput,
|
|
416
|
-
): Promise<void>;
|
|
417
|
-
getMetadata(): Promise<AuthorizationMetadata>;
|
|
418
|
-
getActiveModel(): Promise<AuthorizationGetActiveModel>;
|
|
419
|
-
listModels(
|
|
420
|
-
request?: AuthorizationListModelsInput,
|
|
421
|
-
): Promise<AuthorizationListModels>;
|
|
422
|
-
writeModel(
|
|
423
|
-
request: AuthorizationWriteModelInput,
|
|
424
|
-
): Promise<AuthorizationModelRef>;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
/**
|
|
428
|
-
* Client for the configured authorization provider.
|
|
429
|
-
*
|
|
430
|
-
* The client accepts plain SDK request objects and keeps transport message
|
|
431
|
-
* construction inside the SDK.
|
|
432
|
-
*/
|
|
433
|
-
class AuthorizationImpl implements Authorization {
|
|
434
|
-
private readonly client: Client<typeof AuthorizationProviderService>;
|
|
435
|
-
|
|
436
|
-
constructor(
|
|
437
|
-
socketTarget?: string,
|
|
438
|
-
relayToken = process.env[ENV_HOST_SERVICE_TOKEN]?.trim() ?? "",
|
|
439
|
-
) {
|
|
440
|
-
const resolvedTarget = resolveAuthorizationSocketTarget(socketTarget);
|
|
441
|
-
const transport = createHostServiceGrpcTransport(
|
|
442
|
-
parseHostServiceTarget("authorization", resolvedTarget),
|
|
443
|
-
hostServiceMetadataInterceptors(relayToken, ""),
|
|
444
|
-
);
|
|
445
|
-
this.client = createClient(AuthorizationProviderService, transport);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
async evaluate(
|
|
449
|
-
request: AuthorizationEvaluateInput,
|
|
450
|
-
): Promise<AuthorizationDecision> {
|
|
451
|
-
return authorizationDecisionFromProto(
|
|
452
|
-
await this.client.evaluate(authorizationEvaluateInputToProto(request)),
|
|
453
|
-
);
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
async evaluateMany(
|
|
457
|
-
request: AuthorizationEvaluateManyInput,
|
|
458
|
-
): Promise<AuthorizationEvaluationsResponse> {
|
|
459
|
-
return authorizationEvaluationsResponseFromProto(
|
|
460
|
-
await this.client.evaluateMany(authorizationEvaluateManyInputToProto(request)),
|
|
461
|
-
);
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
async searchResources(
|
|
465
|
-
request: AuthorizationSearchResourcesInput,
|
|
466
|
-
): Promise<AuthorizationResourceSearch> {
|
|
467
|
-
return authorizationResourceSearchFromProto(
|
|
468
|
-
await this.client.searchResources(authorizationSearchResourcesInputToProto(request)),
|
|
469
|
-
);
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
async searchSubjects(
|
|
473
|
-
request: AuthorizationSearchSubjectsInput,
|
|
474
|
-
): Promise<AuthorizationSubjectSearch> {
|
|
475
|
-
return authorizationSubjectSearchFromProto(
|
|
476
|
-
await this.client.searchSubjects(authorizationSearchSubjectsInputToProto(request)),
|
|
477
|
-
);
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
async effectiveSearchResources(
|
|
481
|
-
request: AuthorizationSearchResourcesInput,
|
|
482
|
-
): Promise<AuthorizationResourceSearch> {
|
|
483
|
-
return authorizationResourceSearchFromProto(
|
|
484
|
-
await this.client.effectiveSearchResources(authorizationSearchResourcesInputToProto(request)),
|
|
485
|
-
);
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
async effectiveSearchSubjects(
|
|
489
|
-
request: AuthorizationEffectiveSearchSubjectsInput,
|
|
490
|
-
): Promise<AuthorizationEffectiveSubjectSearch> {
|
|
491
|
-
return authorizationEffectiveSubjectSearchFromProto(
|
|
492
|
-
await this.client.effectiveSearchSubjects(authorizationEffectiveSearchSubjectsInputToProto(request)),
|
|
493
|
-
);
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
async searchActions(
|
|
497
|
-
request: AuthorizationSearchActionsInput,
|
|
498
|
-
): Promise<AuthorizationActionSearch> {
|
|
499
|
-
return authorizationActionSearchFromProto(
|
|
500
|
-
await this.client.searchActions(authorizationSearchActionsInputToProto(request)),
|
|
501
|
-
);
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
async expand(
|
|
505
|
-
request: AuthorizationExpandInput,
|
|
506
|
-
): Promise<AuthorizationExpand> {
|
|
507
|
-
return authorizationExpandFromProto(
|
|
508
|
-
await this.client.expand(authorizationExpandInputToProto(request)),
|
|
509
|
-
);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
async readRelationships(
|
|
513
|
-
request: AuthorizationReadRelationshipsInput,
|
|
514
|
-
): Promise<AuthorizationReadRelationships> {
|
|
515
|
-
return authorizationReadRelationshipsFromProto(
|
|
516
|
-
await this.client.readRelationships(authorizationReadRelationshipsInputToProto(request)),
|
|
517
|
-
);
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
/** Writes and deletes authorization relationships. */
|
|
521
|
-
async writeRelationships(
|
|
522
|
-
request: AuthorizationWriteRelationshipsInput,
|
|
523
|
-
): Promise<void> {
|
|
524
|
-
await this.client.writeRelationships(authorizationWriteRelationshipsInputToProto(request));
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
async getMetadata(): Promise<AuthorizationMetadata> {
|
|
528
|
-
return authorizationMetadataFromProto(await this.client.getMetadata({}));
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
async getActiveModel(): Promise<AuthorizationGetActiveModel> {
|
|
532
|
-
return authorizationGetActiveModelFromProto(await this.client.getActiveModel({}));
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
async listModels(
|
|
536
|
-
request: AuthorizationListModelsInput = {},
|
|
537
|
-
): Promise<AuthorizationListModels> {
|
|
538
|
-
return authorizationListModelsFromProto(
|
|
539
|
-
await this.client.listModels(authorizationListModelsInputToProto(request)),
|
|
540
|
-
);
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
async writeModel(
|
|
544
|
-
request: AuthorizationWriteModelInput,
|
|
545
|
-
): Promise<AuthorizationModelRef> {
|
|
546
|
-
return authorizationModelRefFromProtoRequired(
|
|
547
|
-
await this.client.writeModel(authorizationWriteModelInputToProto(request)),
|
|
548
|
-
);
|
|
549
|
-
}
|
|
253
|
+
modelId?: string | undefined;
|
|
550
254
|
}
|
|
551
255
|
|
|
552
256
|
export interface AuthorizationProviderOptions extends ProviderBaseOptions {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
) => MaybePromise<AuthorizationExpand>;
|
|
577
|
-
getMetadata: () => MaybePromise<AuthorizationMetadata>;
|
|
578
|
-
readRelationships: (
|
|
579
|
-
request: AuthorizationReadRelationshipsInput,
|
|
580
|
-
) => MaybePromise<AuthorizationReadRelationships>;
|
|
581
|
-
writeRelationships: (
|
|
582
|
-
request: AuthorizationWriteRelationshipsInput,
|
|
583
|
-
) => MaybePromise<void>;
|
|
584
|
-
getActiveModel: () => MaybePromise<AuthorizationGetActiveModel>;
|
|
585
|
-
listModels: (
|
|
586
|
-
request: AuthorizationListModelsInput,
|
|
587
|
-
) => MaybePromise<AuthorizationListModels>;
|
|
588
|
-
writeModel: (
|
|
589
|
-
request: AuthorizationWriteModelInput,
|
|
590
|
-
) => MaybePromise<AuthorizationModelRef>;
|
|
257
|
+
checkAccess: (request: CheckAccessRequest) => MaybePromise<CheckAccessResponse>;
|
|
258
|
+
checkAccessMany: (
|
|
259
|
+
request: CheckAccessManyRequest,
|
|
260
|
+
) => MaybePromise<CheckAccessManyResponse>;
|
|
261
|
+
listRelationships: (
|
|
262
|
+
request: ListRelationshipsRequest,
|
|
263
|
+
) => MaybePromise<ListRelationshipsResponse>;
|
|
264
|
+
addRelationship: (
|
|
265
|
+
request: AddRelationshipRequest,
|
|
266
|
+
) => MaybePromise<AddRelationshipResponse>;
|
|
267
|
+
deleteRelationship: (
|
|
268
|
+
request: DeleteRelationshipRequest,
|
|
269
|
+
) => MaybePromise<DeleteRelationshipResponse | void>;
|
|
270
|
+
setAuthorizationState: (
|
|
271
|
+
request: SetAuthorizationStateRequest,
|
|
272
|
+
) => MaybePromise<SetAuthorizationStateResponse>;
|
|
273
|
+
getActiveModelRef: () => MaybePromise<GetActiveModelRefResponse>;
|
|
274
|
+
setActiveModel: (
|
|
275
|
+
request: SetActiveModelRequest,
|
|
276
|
+
) => MaybePromise<SetActiveModelResponse>;
|
|
277
|
+
listActiveModelResourceTypes: (
|
|
278
|
+
request: ListActiveModelResourceTypesRequest,
|
|
279
|
+
) => MaybePromise<ListActiveModelResourceTypesResponse>;
|
|
591
280
|
}
|
|
592
281
|
|
|
593
282
|
export class AuthorizationProvider extends ProviderBase {
|
|
594
283
|
readonly kind = "authorization" as const;
|
|
595
284
|
|
|
596
|
-
private readonly
|
|
285
|
+
private readonly handlers: AuthorizationProviderOptions;
|
|
597
286
|
|
|
598
287
|
constructor(options: AuthorizationProviderOptions) {
|
|
599
288
|
super(options);
|
|
600
|
-
this.
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
async evaluate(request: AuthorizationEvaluateInput) {
|
|
604
|
-
return await this.options.evaluate(request);
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
async evaluateMany(request: AuthorizationEvaluateManyInput) {
|
|
608
|
-
return await this.options.evaluateMany(request);
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
async searchResources(request: AuthorizationSearchResourcesInput) {
|
|
612
|
-
return await this.options.searchResources(request);
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
async searchSubjects(request: AuthorizationSearchSubjectsInput) {
|
|
616
|
-
return await this.options.searchSubjects(request);
|
|
289
|
+
this.handlers = options;
|
|
617
290
|
}
|
|
618
291
|
|
|
619
|
-
|
|
620
|
-
return (
|
|
621
|
-
this.options.effectiveSearchResources !== undefined &&
|
|
622
|
-
this.options.effectiveSearchSubjects !== undefined
|
|
623
|
-
);
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
async effectiveSearchResources(request: AuthorizationSearchResourcesInput) {
|
|
627
|
-
return await this.options.effectiveSearchResources?.(request);
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
async effectiveSearchSubjects(request: AuthorizationEffectiveSearchSubjectsInput) {
|
|
631
|
-
return await this.options.effectiveSearchSubjects?.(request);
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
async searchActions(request: AuthorizationSearchActionsInput) {
|
|
635
|
-
return await this.options.searchActions(request);
|
|
292
|
+
checkAccess(request: CheckAccessRequest): Promise<CheckAccessResponse> {
|
|
293
|
+
return Promise.resolve(this.handlers.checkAccess(request));
|
|
636
294
|
}
|
|
637
295
|
|
|
638
|
-
|
|
639
|
-
|
|
296
|
+
checkAccessMany(
|
|
297
|
+
request: CheckAccessManyRequest,
|
|
298
|
+
): Promise<CheckAccessManyResponse> {
|
|
299
|
+
return Promise.resolve(this.handlers.checkAccessMany(request));
|
|
640
300
|
}
|
|
641
301
|
|
|
642
|
-
|
|
643
|
-
|
|
302
|
+
listRelationships(
|
|
303
|
+
request: ListRelationshipsRequest,
|
|
304
|
+
): Promise<ListRelationshipsResponse> {
|
|
305
|
+
return Promise.resolve(this.handlers.listRelationships(request));
|
|
644
306
|
}
|
|
645
307
|
|
|
646
|
-
|
|
647
|
-
|
|
308
|
+
addRelationship(
|
|
309
|
+
request: AddRelationshipRequest,
|
|
310
|
+
): Promise<AddRelationshipResponse> {
|
|
311
|
+
return Promise.resolve(this.handlers.addRelationship(request));
|
|
648
312
|
}
|
|
649
313
|
|
|
650
|
-
|
|
651
|
-
|
|
314
|
+
deleteRelationship(
|
|
315
|
+
request: DeleteRelationshipRequest,
|
|
316
|
+
): Promise<DeleteRelationshipResponse | void> {
|
|
317
|
+
return Promise.resolve(this.handlers.deleteRelationship(request));
|
|
652
318
|
}
|
|
653
319
|
|
|
654
|
-
|
|
655
|
-
|
|
320
|
+
setAuthorizationState(
|
|
321
|
+
request: SetAuthorizationStateRequest,
|
|
322
|
+
): Promise<SetAuthorizationStateResponse> {
|
|
323
|
+
return Promise.resolve(this.handlers.setAuthorizationState(request));
|
|
656
324
|
}
|
|
657
325
|
|
|
658
|
-
|
|
659
|
-
return
|
|
326
|
+
getActiveModelRef(): Promise<GetActiveModelRefResponse> {
|
|
327
|
+
return Promise.resolve(this.handlers.getActiveModelRef());
|
|
660
328
|
}
|
|
661
329
|
|
|
662
|
-
|
|
663
|
-
|
|
330
|
+
setActiveModel(
|
|
331
|
+
request: SetActiveModelRequest,
|
|
332
|
+
): Promise<SetActiveModelResponse> {
|
|
333
|
+
return Promise.resolve(this.handlers.setActiveModel(request));
|
|
664
334
|
}
|
|
665
335
|
|
|
666
|
-
|
|
667
|
-
|
|
336
|
+
listActiveModelResourceTypes(
|
|
337
|
+
request: ListActiveModelResourceTypesRequest,
|
|
338
|
+
): Promise<ListActiveModelResourceTypesResponse> {
|
|
339
|
+
return Promise.resolve(this.handlers.listActiveModelResourceTypes(request));
|
|
668
340
|
}
|
|
669
341
|
}
|
|
670
342
|
|
|
@@ -683,1086 +355,597 @@ export function isAuthorizationProvider(
|
|
|
683
355
|
value !== null &&
|
|
684
356
|
"kind" in value &&
|
|
685
357
|
String((value as { kind?: unknown }).kind ?? "") === "authorization" &&
|
|
686
|
-
"
|
|
687
|
-
"
|
|
688
|
-
"
|
|
689
|
-
"
|
|
690
|
-
"
|
|
691
|
-
"
|
|
692
|
-
"
|
|
693
|
-
"
|
|
694
|
-
"
|
|
695
|
-
"listModels" in value &&
|
|
696
|
-
"writeModel" in value)
|
|
358
|
+
"checkAccess" in value &&
|
|
359
|
+
"checkAccessMany" in value &&
|
|
360
|
+
"listRelationships" in value &&
|
|
361
|
+
"addRelationship" in value &&
|
|
362
|
+
"deleteRelationship" in value &&
|
|
363
|
+
"setAuthorizationState" in value &&
|
|
364
|
+
"getActiveModelRef" in value &&
|
|
365
|
+
"setActiveModel" in value &&
|
|
366
|
+
"listActiveModelResourceTypes" in value)
|
|
697
367
|
);
|
|
698
368
|
}
|
|
699
369
|
|
|
700
370
|
export function createAuthorizationProviderService(
|
|
701
371
|
provider: AuthorizationProvider,
|
|
702
|
-
):
|
|
372
|
+
): Partial<ServiceImpl<typeof AuthorizationProviderService>> {
|
|
703
373
|
return {
|
|
704
|
-
async
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
await provider.
|
|
708
|
-
"evaluate",
|
|
709
|
-
),
|
|
710
|
-
);
|
|
711
|
-
},
|
|
712
|
-
async evaluateMany(request) {
|
|
713
|
-
return authorizationEvaluationsResponseToProto(
|
|
714
|
-
requiredAuthorizationResponse(
|
|
715
|
-
await provider.evaluateMany(authorizationEvaluateManyInputFromProto(request)),
|
|
716
|
-
"evaluate many",
|
|
717
|
-
),
|
|
718
|
-
);
|
|
719
|
-
},
|
|
720
|
-
async searchResources(request) {
|
|
721
|
-
return authorizationResourceSearchToProto(
|
|
722
|
-
requiredAuthorizationResponse(
|
|
723
|
-
await provider.searchResources(authorizationSearchResourcesInputFromProto(request)),
|
|
724
|
-
"search resources",
|
|
725
|
-
),
|
|
726
|
-
);
|
|
727
|
-
},
|
|
728
|
-
async searchSubjects(request) {
|
|
729
|
-
return authorizationSubjectSearchToProto(
|
|
730
|
-
requiredAuthorizationResponse(
|
|
731
|
-
await provider.searchSubjects(authorizationSearchSubjectsInputFromProto(request)),
|
|
732
|
-
"search subjects",
|
|
733
|
-
),
|
|
734
|
-
);
|
|
735
|
-
},
|
|
736
|
-
async effectiveSearchResources(request) {
|
|
737
|
-
if (!provider.supportsEffectiveSearch()) {
|
|
738
|
-
throw new ConnectError(
|
|
739
|
-
"authorization provider does not support effective search",
|
|
740
|
-
Code.Unimplemented,
|
|
374
|
+
async checkAccess(request) {
|
|
375
|
+
try {
|
|
376
|
+
return checkAccessResponseToProto(
|
|
377
|
+
await provider.checkAccess(checkAccessRequestFromProto(request)),
|
|
741
378
|
);
|
|
379
|
+
} catch (error) {
|
|
380
|
+
throw authorizationRuntimeError("check access", error);
|
|
742
381
|
}
|
|
743
|
-
return authorizationResourceSearchToProto(
|
|
744
|
-
requiredAuthorizationResponse(
|
|
745
|
-
await provider.effectiveSearchResources(authorizationSearchResourcesInputFromProto(request)),
|
|
746
|
-
"effective search resources",
|
|
747
|
-
),
|
|
748
|
-
);
|
|
749
382
|
},
|
|
750
|
-
async
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
Code.Unimplemented,
|
|
383
|
+
async checkAccessMany(request) {
|
|
384
|
+
try {
|
|
385
|
+
return checkAccessManyResponseToProto(
|
|
386
|
+
await provider.checkAccessMany(checkAccessManyRequestFromProto(request)),
|
|
755
387
|
);
|
|
388
|
+
} catch (error) {
|
|
389
|
+
throw authorizationRuntimeError("check access many", error);
|
|
756
390
|
}
|
|
757
|
-
return authorizationEffectiveSubjectSearchToProto(
|
|
758
|
-
requiredAuthorizationResponse(
|
|
759
|
-
await provider.effectiveSearchSubjects(authorizationEffectiveSearchSubjectsInputFromProto(request)),
|
|
760
|
-
"effective search subjects",
|
|
761
|
-
),
|
|
762
|
-
);
|
|
763
391
|
},
|
|
764
|
-
async
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
await provider.
|
|
768
|
-
"search actions",
|
|
769
|
-
),
|
|
770
|
-
);
|
|
771
|
-
},
|
|
772
|
-
async expand(request) {
|
|
773
|
-
if (!provider.supportsExpand()) {
|
|
774
|
-
throw new ConnectError(
|
|
775
|
-
"authorization provider does not support expansion",
|
|
776
|
-
Code.Unimplemented,
|
|
392
|
+
async listRelationships(request) {
|
|
393
|
+
try {
|
|
394
|
+
return listRelationshipsResponseToProto(
|
|
395
|
+
await provider.listRelationships(listRelationshipsRequestFromProto(request)),
|
|
777
396
|
);
|
|
397
|
+
} catch (error) {
|
|
398
|
+
throw authorizationRuntimeError("list relationships", error);
|
|
778
399
|
}
|
|
779
|
-
return authorizationExpandToProto(
|
|
780
|
-
requiredAuthorizationResponse(
|
|
781
|
-
await provider.expand(authorizationExpandInputFromProto(request)),
|
|
782
|
-
"expand",
|
|
783
|
-
),
|
|
784
|
-
);
|
|
785
400
|
},
|
|
786
|
-
async
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
}
|
|
794
|
-
if (provider.supportsExpand()) {
|
|
795
|
-
pushCapability(metadata.capabilities, "expand");
|
|
401
|
+
async addRelationship(request) {
|
|
402
|
+
try {
|
|
403
|
+
return addRelationshipResponseToProto(
|
|
404
|
+
await provider.addRelationship(addRelationshipRequestFromProto(request)),
|
|
405
|
+
);
|
|
406
|
+
} catch (error) {
|
|
407
|
+
throw authorizationRuntimeError("add relationship", error);
|
|
796
408
|
}
|
|
797
|
-
return metadata;
|
|
798
|
-
},
|
|
799
|
-
async readRelationships(request) {
|
|
800
|
-
return authorizationReadRelationshipsToProto(
|
|
801
|
-
requiredAuthorizationResponse(
|
|
802
|
-
await provider.readRelationships(authorizationReadRelationshipsInputFromProto(request)),
|
|
803
|
-
"read relationships",
|
|
804
|
-
),
|
|
805
|
-
);
|
|
806
409
|
},
|
|
807
|
-
async
|
|
808
|
-
|
|
809
|
-
|
|
410
|
+
async deleteRelationship(request) {
|
|
411
|
+
try {
|
|
412
|
+
await provider.deleteRelationship(deleteRelationshipRequestFromProto(request));
|
|
413
|
+
return create(DeleteRelationshipResponseSchema);
|
|
414
|
+
} catch (error) {
|
|
415
|
+
throw authorizationRuntimeError("delete relationship", error);
|
|
416
|
+
}
|
|
810
417
|
},
|
|
811
|
-
async
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
await provider.
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
418
|
+
async setAuthorizationState(request) {
|
|
419
|
+
try {
|
|
420
|
+
return setAuthorizationStateResponseToProto(
|
|
421
|
+
await provider.setAuthorizationState(
|
|
422
|
+
setAuthorizationStateRequestFromProto(request),
|
|
423
|
+
),
|
|
424
|
+
);
|
|
425
|
+
} catch (error) {
|
|
426
|
+
throw authorizationRuntimeError("set authorization state", error);
|
|
427
|
+
}
|
|
818
428
|
},
|
|
819
|
-
async
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
);
|
|
429
|
+
async getActiveModelRef() {
|
|
430
|
+
try {
|
|
431
|
+
return getActiveModelRefResponseToProto(await provider.getActiveModelRef());
|
|
432
|
+
} catch (error) {
|
|
433
|
+
throw authorizationRuntimeError("get active model ref", error);
|
|
434
|
+
}
|
|
826
435
|
},
|
|
827
|
-
async
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
await provider.
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
436
|
+
async setActiveModel(request) {
|
|
437
|
+
try {
|
|
438
|
+
return setActiveModelResponseToProto(
|
|
439
|
+
await provider.setActiveModel(setActiveModelRequestFromProto(request)),
|
|
440
|
+
);
|
|
441
|
+
} catch (error) {
|
|
442
|
+
throw authorizationRuntimeError("set active model", error);
|
|
443
|
+
}
|
|
834
444
|
},
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
)
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
Code.Internal,
|
|
846
|
-
);
|
|
847
|
-
}
|
|
848
|
-
return value;
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
/**
|
|
852
|
-
* Returns a shared authorization capability for authored providers.
|
|
853
|
-
*/
|
|
854
|
-
export function Authorization(): Authorization {
|
|
855
|
-
const target = resolveAuthorizationSocketTarget();
|
|
856
|
-
const token = process.env[ENV_HOST_SERVICE_TOKEN]?.trim() ?? "";
|
|
857
|
-
if (
|
|
858
|
-
sharedAuthorizationTransport.client &&
|
|
859
|
-
sharedAuthorizationTransport.target === target &&
|
|
860
|
-
sharedAuthorizationTransport.token === token
|
|
861
|
-
) {
|
|
862
|
-
return sharedAuthorizationTransport.client;
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
const client = new AuthorizationImpl(target, token);
|
|
866
|
-
sharedAuthorizationTransport.target = target;
|
|
867
|
-
sharedAuthorizationTransport.token = token;
|
|
868
|
-
sharedAuthorizationTransport.client = client;
|
|
869
|
-
return client;
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
/** Creates an authorization subject reference. */
|
|
873
|
-
export function authorizationSubject(
|
|
874
|
-
type: string,
|
|
875
|
-
id: string,
|
|
876
|
-
properties?: JsonObjectInput,
|
|
877
|
-
): AuthorizationSubject {
|
|
878
|
-
return properties === undefined ? { type, id } : { type, id, properties };
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
/** Creates an authorization resource reference. */
|
|
882
|
-
export function authorizationResource(
|
|
883
|
-
type: string,
|
|
884
|
-
id: string,
|
|
885
|
-
properties?: JsonObjectInput,
|
|
886
|
-
): AuthorizationResource {
|
|
887
|
-
return properties === undefined ? { type, id } : { type, id, properties };
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
/** Creates an authorization subject-set reference. */
|
|
891
|
-
export function authorizationSubjectSet(
|
|
892
|
-
resource: AuthorizationResource,
|
|
893
|
-
relation: string,
|
|
894
|
-
): AuthorizationSubjectSet {
|
|
895
|
-
return { resource, relation };
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
/** Creates a relationship target from a subject. */
|
|
899
|
-
export function authorizationSubjectTarget(
|
|
900
|
-
subject: AuthorizationSubject,
|
|
901
|
-
): AuthorizationRelationshipTarget {
|
|
902
|
-
return { kind: { case: "subject", value: subject } };
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
/** Creates a relationship target from a resource. */
|
|
906
|
-
export function authorizationResourceTarget(
|
|
907
|
-
resource: AuthorizationResource,
|
|
908
|
-
): AuthorizationRelationshipTarget {
|
|
909
|
-
return { kind: { case: "resource", value: resource } };
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
/** Creates a relationship target from a subject set. */
|
|
913
|
-
export function authorizationSubjectSetTarget(
|
|
914
|
-
resource: AuthorizationResource,
|
|
915
|
-
relation: string,
|
|
916
|
-
): AuthorizationRelationshipTarget {
|
|
917
|
-
return {
|
|
918
|
-
kind: {
|
|
919
|
-
case: "subjectSet",
|
|
920
|
-
value: authorizationSubjectSet(resource, relation),
|
|
445
|
+
async listActiveModelResourceTypes(request) {
|
|
446
|
+
try {
|
|
447
|
+
return listActiveModelResourceTypesResponseToProto(
|
|
448
|
+
await provider.listActiveModelResourceTypes(
|
|
449
|
+
listActiveModelResourceTypesRequestFromProto(request),
|
|
450
|
+
),
|
|
451
|
+
);
|
|
452
|
+
} catch (error) {
|
|
453
|
+
throw authorizationRuntimeError("list active model resource types", error);
|
|
454
|
+
}
|
|
921
455
|
},
|
|
922
456
|
};
|
|
923
457
|
}
|
|
924
458
|
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
properties?: JsonObjectInput,
|
|
929
|
-
): AuthorizationAction {
|
|
930
|
-
return properties === undefined ? { name } : { name, properties };
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
/** Creates a relationship tuple for authorization writes. */
|
|
934
|
-
export function authorizationRelationship(
|
|
935
|
-
subject: AuthorizationSubject,
|
|
936
|
-
relation: string,
|
|
937
|
-
resource: AuthorizationResource,
|
|
938
|
-
properties?: JsonObjectInput,
|
|
939
|
-
): AuthorizationRelationship {
|
|
940
|
-
return properties === undefined
|
|
941
|
-
? { subject, relation, resource }
|
|
942
|
-
: { subject, relation, resource, properties };
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
/** Creates a generalized relationship tuple for authorization writes. */
|
|
946
|
-
export function authorizationRelationshipWithTarget(
|
|
947
|
-
target: AuthorizationRelationshipTarget,
|
|
948
|
-
relation: string,
|
|
949
|
-
resource: AuthorizationResource,
|
|
950
|
-
properties?: JsonObjectInput,
|
|
951
|
-
): AuthorizationRelationship {
|
|
952
|
-
return properties === undefined
|
|
953
|
-
? { target, relation, resource }
|
|
954
|
-
: { target, relation, resource, properties };
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
/** Creates a relationship key for authorization deletes. */
|
|
958
|
-
export function authorizationRelationshipKey(
|
|
959
|
-
subject: AuthorizationSubject,
|
|
960
|
-
relation: string,
|
|
961
|
-
resource: AuthorizationResource,
|
|
962
|
-
): AuthorizationRelationshipKey {
|
|
963
|
-
return { subject, relation, resource };
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
/** Creates a generalized relationship key for authorization deletes. */
|
|
967
|
-
export function authorizationRelationshipKeyWithTarget(
|
|
968
|
-
target: AuthorizationRelationshipTarget,
|
|
969
|
-
relation: string,
|
|
970
|
-
resource: AuthorizationResource,
|
|
971
|
-
): AuthorizationRelationshipKey {
|
|
972
|
-
return { target, relation, resource };
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
function authorizationEvaluateInputToProto(input: AuthorizationEvaluateInput) {
|
|
976
|
-
return create(AccessEvaluationRequestSchema, {
|
|
977
|
-
subject: input.subject === undefined ? undefined : authorizationSubjectToProto(input.subject),
|
|
978
|
-
action: input.action === undefined ? undefined : authorizationActionToProto(input.action),
|
|
979
|
-
resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
|
|
980
|
-
context: optionalStruct(input.context),
|
|
981
|
-
});
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
function authorizationEvaluateInputFromProto(
|
|
985
|
-
input: ProtoAccessEvaluationRequest,
|
|
986
|
-
): AuthorizationEvaluateInput {
|
|
987
|
-
return {
|
|
988
|
-
subject: authorizationSubjectFromProto(input.subject),
|
|
989
|
-
action: authorizationActionFromProto(input.action),
|
|
990
|
-
resource: authorizationResourceFromProto(input.resource),
|
|
991
|
-
context: optionalObjectFromStruct(input.context),
|
|
992
|
-
};
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
function authorizationEvaluateManyInputToProto(input: AuthorizationEvaluateManyInput) {
|
|
996
|
-
return create(AccessEvaluationsRequestSchema, {
|
|
997
|
-
requests: input.requests?.map(authorizationEvaluateInputToProto) ?? [],
|
|
998
|
-
});
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
function authorizationEvaluateManyInputFromProto(
|
|
1002
|
-
input: ProtoAccessEvaluationsRequest,
|
|
1003
|
-
): AuthorizationEvaluateManyInput {
|
|
1004
|
-
return { requests: input.requests.map(authorizationEvaluateInputFromProto) };
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
function authorizationSearchResourcesInputToProto(input: AuthorizationSearchResourcesInput) {
|
|
1008
|
-
return create(ResourceSearchRequestSchema, {
|
|
1009
|
-
subject: input.subject === undefined ? undefined : authorizationSubjectToProto(input.subject),
|
|
1010
|
-
action: input.action === undefined ? undefined : authorizationActionToProto(input.action),
|
|
1011
|
-
resourceType: input.resourceType ?? "",
|
|
1012
|
-
context: optionalStruct(input.context),
|
|
1013
|
-
pageSize: input.pageSize ?? 0,
|
|
1014
|
-
pageToken: input.pageToken ?? "",
|
|
1015
|
-
});
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
function authorizationSearchResourcesInputFromProto(
|
|
1019
|
-
input: ProtoResourceSearchRequest,
|
|
1020
|
-
): AuthorizationSearchResourcesInput {
|
|
459
|
+
function checkAccessRequestFromProto(
|
|
460
|
+
value: ProtoCheckAccessRequest,
|
|
461
|
+
): CheckAccessRequest {
|
|
1021
462
|
return {
|
|
1022
|
-
subject:
|
|
1023
|
-
action:
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
463
|
+
subject: subjectFromProto(value.subject),
|
|
464
|
+
action: value.action
|
|
465
|
+
? {
|
|
466
|
+
name: value.action.name,
|
|
467
|
+
properties: jsonObjectFromStruct(value.action.properties),
|
|
468
|
+
}
|
|
469
|
+
: undefined,
|
|
470
|
+
resource: resourceFromProto(value.resource),
|
|
1028
471
|
};
|
|
1029
472
|
}
|
|
1030
473
|
|
|
1031
|
-
function
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
474
|
+
function checkAccessResponseToProto(value: CheckAccessResponse | undefined) {
|
|
475
|
+
if (!value) {
|
|
476
|
+
throw new ConnectError(
|
|
477
|
+
"authorization provider returned nil response",
|
|
478
|
+
Code.Internal,
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
return create(CheckAccessResponseSchema, {
|
|
482
|
+
allowed: value.allowed ?? false,
|
|
483
|
+
modelId: value.modelId ?? "",
|
|
1039
484
|
});
|
|
1040
485
|
}
|
|
1041
486
|
|
|
1042
|
-
function
|
|
1043
|
-
|
|
1044
|
-
):
|
|
487
|
+
function checkAccessManyRequestFromProto(
|
|
488
|
+
value: ProtoCheckAccessManyRequest,
|
|
489
|
+
): CheckAccessManyRequest {
|
|
1045
490
|
return {
|
|
1046
|
-
|
|
1047
|
-
action: authorizationActionFromProto(input.action),
|
|
1048
|
-
subjectType: input.subjectType,
|
|
1049
|
-
context: optionalObjectFromStruct(input.context),
|
|
1050
|
-
pageSize: input.pageSize,
|
|
1051
|
-
pageToken: input.pageToken,
|
|
491
|
+
requests: value.requests.map(checkAccessRequestFromProto),
|
|
1052
492
|
};
|
|
1053
493
|
}
|
|
1054
494
|
|
|
1055
|
-
function
|
|
1056
|
-
|
|
495
|
+
function checkAccessManyResponseToProto(
|
|
496
|
+
value: CheckAccessManyResponse | undefined,
|
|
1057
497
|
) {
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
function authorizationEffectiveSearchSubjectsInputFromProto(
|
|
1068
|
-
input: ProtoEffectiveSubjectSearchRequest,
|
|
1069
|
-
): AuthorizationEffectiveSearchSubjectsInput {
|
|
1070
|
-
return {
|
|
1071
|
-
resource: authorizationResourceFromProto(input.resource),
|
|
1072
|
-
action: authorizationActionFromProto(input.action),
|
|
1073
|
-
context: optionalObjectFromStruct(input.context),
|
|
1074
|
-
pageSize: input.pageSize,
|
|
1075
|
-
pageToken: input.pageToken,
|
|
1076
|
-
};
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
function authorizationSearchActionsInputToProto(input: AuthorizationSearchActionsInput) {
|
|
1080
|
-
return create(ActionSearchRequestSchema, {
|
|
1081
|
-
subject: input.subject === undefined ? undefined : authorizationSubjectToProto(input.subject),
|
|
1082
|
-
resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
|
|
1083
|
-
context: optionalStruct(input.context),
|
|
1084
|
-
pageSize: input.pageSize ?? 0,
|
|
1085
|
-
pageToken: input.pageToken ?? "",
|
|
1086
|
-
});
|
|
1087
|
-
}
|
|
1088
|
-
|
|
1089
|
-
function authorizationSearchActionsInputFromProto(
|
|
1090
|
-
input: ProtoActionSearchRequest,
|
|
1091
|
-
): AuthorizationSearchActionsInput {
|
|
1092
|
-
return {
|
|
1093
|
-
subject: authorizationSubjectFromProto(input.subject),
|
|
1094
|
-
resource: authorizationResourceFromProto(input.resource),
|
|
1095
|
-
context: optionalObjectFromStruct(input.context),
|
|
1096
|
-
pageSize: input.pageSize,
|
|
1097
|
-
pageToken: input.pageToken,
|
|
1098
|
-
};
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
function authorizationExpandInputToProto(input: AuthorizationExpandInput) {
|
|
1102
|
-
return create(ExpandRequestSchema, {
|
|
1103
|
-
resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
|
|
1104
|
-
relation: input.relation ?? "",
|
|
1105
|
-
context: optionalStruct(input.context),
|
|
1106
|
-
maxDepth: input.maxDepth ?? 0,
|
|
1107
|
-
modelId: input.modelId ?? "",
|
|
1108
|
-
});
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1111
|
-
function authorizationExpandInputFromProto(input: ProtoExpandRequest): AuthorizationExpandInput {
|
|
1112
|
-
return {
|
|
1113
|
-
resource: authorizationResourceFromProto(input.resource),
|
|
1114
|
-
relation: input.relation,
|
|
1115
|
-
context: optionalObjectFromStruct(input.context),
|
|
1116
|
-
maxDepth: input.maxDepth,
|
|
1117
|
-
modelId: input.modelId,
|
|
1118
|
-
};
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
function authorizationReadRelationshipsInputToProto(input: AuthorizationReadRelationshipsInput) {
|
|
1122
|
-
return create(ReadRelationshipsRequestSchema, {
|
|
1123
|
-
subject: input.subject === undefined ? undefined : authorizationSubjectToProto(input.subject),
|
|
1124
|
-
relation: input.relation ?? "",
|
|
1125
|
-
resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
|
|
1126
|
-
pageSize: input.pageSize ?? 0,
|
|
1127
|
-
pageToken: input.pageToken ?? "",
|
|
1128
|
-
modelId: input.modelId ?? "",
|
|
1129
|
-
target: input.target === undefined ? undefined : authorizationRelationshipTargetToProto(input.target),
|
|
1130
|
-
});
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
function authorizationReadRelationshipsInputFromProto(
|
|
1134
|
-
input: ProtoReadRelationshipsRequest,
|
|
1135
|
-
): AuthorizationReadRelationshipsInput {
|
|
1136
|
-
return {
|
|
1137
|
-
subject: authorizationSubjectFromProto(input.subject),
|
|
1138
|
-
relation: input.relation,
|
|
1139
|
-
resource: authorizationResourceFromProto(input.resource),
|
|
1140
|
-
pageSize: input.pageSize,
|
|
1141
|
-
pageToken: input.pageToken,
|
|
1142
|
-
modelId: input.modelId,
|
|
1143
|
-
target: authorizationRelationshipTargetFromProto(input.target),
|
|
1144
|
-
};
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
function authorizationWriteRelationshipsInputToProto(input: AuthorizationWriteRelationshipsInput) {
|
|
1148
|
-
return create(WriteRelationshipsRequestSchema, {
|
|
1149
|
-
writes: input.writes?.map(authorizationRelationshipToProto) ?? [],
|
|
1150
|
-
deletes: input.deletes?.map(authorizationRelationshipKeyToProto) ?? [],
|
|
1151
|
-
modelId: input.modelId ?? "",
|
|
1152
|
-
});
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1155
|
-
function authorizationWriteRelationshipsInputFromProto(
|
|
1156
|
-
input: ProtoWriteRelationshipsRequest,
|
|
1157
|
-
): AuthorizationWriteRelationshipsInput {
|
|
1158
|
-
return {
|
|
1159
|
-
writes: input.writes.map(authorizationRelationshipFromProto),
|
|
1160
|
-
deletes: input.deletes.map(authorizationRelationshipKeyFromProto),
|
|
1161
|
-
modelId: input.modelId,
|
|
1162
|
-
};
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
function authorizationListModelsInputToProto(input: AuthorizationListModelsInput) {
|
|
1166
|
-
return create(ListModelsRequestSchema, {
|
|
1167
|
-
pageSize: input.pageSize ?? 0,
|
|
1168
|
-
pageToken: input.pageToken ?? "",
|
|
498
|
+
if (!value) {
|
|
499
|
+
throw new ConnectError(
|
|
500
|
+
"authorization provider returned nil response",
|
|
501
|
+
Code.Internal,
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
return create(CheckAccessManyResponseSchema, {
|
|
505
|
+
decisions: (value.decisions ?? []).map(checkAccessResponseToProto),
|
|
1169
506
|
});
|
|
1170
507
|
}
|
|
1171
508
|
|
|
1172
|
-
function
|
|
509
|
+
function listRelationshipsRequestFromProto(
|
|
510
|
+
value: ProtoListRelationshipsRequest,
|
|
511
|
+
): ListRelationshipsRequest {
|
|
1173
512
|
return {
|
|
1174
|
-
|
|
1175
|
-
|
|
513
|
+
filter: relationshipFilterFromProto(value.filter),
|
|
514
|
+
pageSize: value.pageSize,
|
|
515
|
+
pageToken: value.pageToken,
|
|
1176
516
|
};
|
|
1177
517
|
}
|
|
1178
518
|
|
|
1179
|
-
function
|
|
1180
|
-
|
|
1181
|
-
|
|
519
|
+
function listRelationshipsResponseToProto(
|
|
520
|
+
value: ListRelationshipsResponse | undefined,
|
|
521
|
+
) {
|
|
522
|
+
if (!value) {
|
|
523
|
+
throw new ConnectError(
|
|
524
|
+
"authorization provider returned nil response",
|
|
525
|
+
Code.Internal,
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
return create(ListRelationshipsResponseSchema, {
|
|
529
|
+
relationships: (value.relationships ?? []).map(relationshipToProtoRequired),
|
|
530
|
+
nextPageToken: value.nextPageToken ?? "",
|
|
1182
531
|
});
|
|
1183
532
|
}
|
|
1184
533
|
|
|
1185
|
-
function
|
|
534
|
+
function addRelationshipRequestFromProto(
|
|
535
|
+
value: ProtoAddRelationshipRequest,
|
|
536
|
+
): AddRelationshipRequest {
|
|
1186
537
|
return {
|
|
1187
|
-
|
|
538
|
+
relationship: relationshipFromProto(value.relationship),
|
|
1188
539
|
};
|
|
1189
540
|
}
|
|
1190
541
|
|
|
1191
|
-
function
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
542
|
+
function addRelationshipResponseToProto(
|
|
543
|
+
value: AddRelationshipResponse | undefined,
|
|
544
|
+
) {
|
|
545
|
+
if (!value) {
|
|
546
|
+
throw new ConnectError(
|
|
547
|
+
"authorization provider returned nil response",
|
|
548
|
+
Code.Internal,
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
return create(AddRelationshipResponseSchema, {
|
|
552
|
+
relationship: value.relationship
|
|
553
|
+
? relationshipToProto(value.relationship)
|
|
554
|
+
: undefined,
|
|
1196
555
|
});
|
|
1197
556
|
}
|
|
1198
557
|
|
|
1199
|
-
function
|
|
558
|
+
function deleteRelationshipRequestFromProto(
|
|
559
|
+
value: ProtoDeleteRelationshipRequest,
|
|
560
|
+
): DeleteRelationshipRequest {
|
|
1200
561
|
return {
|
|
1201
|
-
|
|
1202
|
-
context: optionalObjectFromStruct(input.context),
|
|
1203
|
-
modelId: input.modelId,
|
|
562
|
+
relationshipTuple: relationshipTupleFromProto(value.relationshipTuple),
|
|
1204
563
|
};
|
|
1205
564
|
}
|
|
1206
565
|
|
|
1207
|
-
function
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
});
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
function authorizationEvaluationsResponseFromProto(
|
|
1214
|
-
input: ProtoAccessEvaluationsResponse,
|
|
1215
|
-
): AuthorizationEvaluationsResponse {
|
|
1216
|
-
return { decisions: input.decisions.map(authorizationDecisionFromProto) };
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
|
-
function authorizationResourceSearchToProto(input: AuthorizationResourceSearch) {
|
|
1220
|
-
return create(ResourceSearchResponseSchema, {
|
|
1221
|
-
resources: input.resources?.map(authorizationResourceToProto) ?? [],
|
|
1222
|
-
nextPageToken: input.nextPageToken ?? "",
|
|
1223
|
-
modelId: input.modelId ?? "",
|
|
1224
|
-
});
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
function authorizationResourceSearchFromProto(input: ProtoResourceSearchResponse): AuthorizationResourceSearch {
|
|
566
|
+
function setAuthorizationStateRequestFromProto(
|
|
567
|
+
value: ProtoSetAuthorizationStateRequest,
|
|
568
|
+
): SetAuthorizationStateRequest {
|
|
1228
569
|
return {
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
modelId: input.modelId,
|
|
570
|
+
model: authorizationModelFromProto(value.model),
|
|
571
|
+
relationships: value.relationships.map(relationshipFromProtoRequired),
|
|
1232
572
|
};
|
|
1233
573
|
}
|
|
1234
574
|
|
|
1235
|
-
function
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
575
|
+
function setAuthorizationStateResponseToProto(
|
|
576
|
+
value: SetAuthorizationStateResponse | undefined,
|
|
577
|
+
) {
|
|
578
|
+
if (!value) {
|
|
579
|
+
throw new ConnectError(
|
|
580
|
+
"authorization provider returned nil response",
|
|
581
|
+
Code.Internal,
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
return create(SetAuthorizationStateResponseSchema, {
|
|
585
|
+
activeModel: value.activeModel
|
|
586
|
+
? authorizationModelRefToProto(value.activeModel)
|
|
587
|
+
: undefined,
|
|
1240
588
|
});
|
|
1241
589
|
}
|
|
1242
590
|
|
|
1243
|
-
function
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
return create(
|
|
1253
|
-
|
|
1254
|
-
nextPageToken: input.nextPageToken ?? "",
|
|
1255
|
-
modelId: input.modelId ?? "",
|
|
1256
|
-
truncated: input.truncated ?? false,
|
|
591
|
+
function getActiveModelRefResponseToProto(
|
|
592
|
+
value: GetActiveModelRefResponse | undefined,
|
|
593
|
+
) {
|
|
594
|
+
if (!value) {
|
|
595
|
+
throw new ConnectError(
|
|
596
|
+
"authorization provider returned nil response",
|
|
597
|
+
Code.Internal,
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
return create(GetActiveModelRefResponseSchema, {
|
|
601
|
+
model: value.model ? authorizationModelRefToProto(value.model) : undefined,
|
|
1257
602
|
});
|
|
1258
603
|
}
|
|
1259
604
|
|
|
1260
|
-
function
|
|
1261
|
-
|
|
1262
|
-
):
|
|
605
|
+
function setActiveModelRequestFromProto(
|
|
606
|
+
value: ProtoSetActiveModelRequest,
|
|
607
|
+
): SetActiveModelRequest {
|
|
1263
608
|
return {
|
|
1264
|
-
|
|
1265
|
-
nextPageToken: input.nextPageToken,
|
|
1266
|
-
modelId: input.modelId,
|
|
1267
|
-
truncated: input.truncated,
|
|
609
|
+
model: authorizationModelFromProto(value.model),
|
|
1268
610
|
};
|
|
1269
611
|
}
|
|
1270
612
|
|
|
1271
|
-
function
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
613
|
+
function setActiveModelResponseToProto(value: SetActiveModelResponse | undefined) {
|
|
614
|
+
if (!value) {
|
|
615
|
+
throw new ConnectError(
|
|
616
|
+
"authorization provider returned nil response",
|
|
617
|
+
Code.Internal,
|
|
618
|
+
);
|
|
619
|
+
}
|
|
620
|
+
return create(SetActiveModelResponseSchema, {
|
|
621
|
+
model: value.model ? authorizationModelRefToProto(value.model) : undefined,
|
|
1276
622
|
});
|
|
1277
623
|
}
|
|
1278
624
|
|
|
1279
|
-
function
|
|
625
|
+
function listActiveModelResourceTypesRequestFromProto(
|
|
626
|
+
value: ProtoListActiveModelResourceTypesRequest,
|
|
627
|
+
): ListActiveModelResourceTypesRequest {
|
|
1280
628
|
return {
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
629
|
+
filter: value.filter
|
|
630
|
+
? {
|
|
631
|
+
name: value.filter.name,
|
|
632
|
+
sourceLayer: value.filter.sourceLayer,
|
|
633
|
+
}
|
|
634
|
+
: undefined,
|
|
635
|
+
pageSize: value.pageSize,
|
|
636
|
+
pageToken: value.pageToken,
|
|
1284
637
|
};
|
|
1285
638
|
}
|
|
1286
639
|
|
|
1287
|
-
function
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
640
|
+
function listActiveModelResourceTypesResponseToProto(
|
|
641
|
+
value: ListActiveModelResourceTypesResponse | undefined,
|
|
642
|
+
) {
|
|
643
|
+
if (!value) {
|
|
644
|
+
throw new ConnectError(
|
|
645
|
+
"authorization provider returned nil response",
|
|
646
|
+
Code.Internal,
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
return create(ListActiveModelResourceTypesResponseSchema, {
|
|
650
|
+
resourceTypes: (value.resourceTypes ?? []).map(
|
|
651
|
+
authorizationModelResourceTypeToProto,
|
|
652
|
+
),
|
|
653
|
+
nextPageToken: value.nextPageToken ?? "",
|
|
654
|
+
modelId: value.modelId ?? "",
|
|
1291
655
|
});
|
|
1292
656
|
}
|
|
1293
657
|
|
|
1294
|
-
function
|
|
658
|
+
function subjectFromProto(value: ProtoCheckAccessRequest["subject"]): AuthorizationSubject | undefined {
|
|
659
|
+
if (!value) {
|
|
660
|
+
return undefined;
|
|
661
|
+
}
|
|
1295
662
|
return {
|
|
1296
|
-
|
|
1297
|
-
|
|
663
|
+
type: value.type,
|
|
664
|
+
id: value.id,
|
|
665
|
+
properties: jsonObjectFromStruct(value.properties),
|
|
1298
666
|
};
|
|
1299
667
|
}
|
|
1300
668
|
|
|
1301
|
-
function
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
669
|
+
function subjectToProto(value: AuthorizationSubject | undefined) {
|
|
670
|
+
if (!value) {
|
|
671
|
+
return undefined;
|
|
672
|
+
}
|
|
673
|
+
return create(SubjectSchema, {
|
|
674
|
+
type: value.type ?? "",
|
|
675
|
+
id: value.id ?? "",
|
|
676
|
+
properties: value.properties === undefined
|
|
677
|
+
? undefined
|
|
678
|
+
: structFromObject(value.properties),
|
|
1306
679
|
});
|
|
1307
680
|
}
|
|
1308
681
|
|
|
1309
|
-
function
|
|
1310
|
-
|
|
1311
|
-
|
|
682
|
+
function resourceFromProto(value: ProtoRelationshipFilter["resource"]): AuthorizationResource | undefined {
|
|
683
|
+
if (!value) {
|
|
684
|
+
return undefined;
|
|
685
|
+
}
|
|
1312
686
|
return {
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
687
|
+
type: value.type,
|
|
688
|
+
id: value.id,
|
|
689
|
+
properties: jsonObjectFromStruct(value.properties),
|
|
1316
690
|
};
|
|
1317
691
|
}
|
|
1318
692
|
|
|
1319
|
-
function
|
|
1320
|
-
|
|
1321
|
-
|
|
693
|
+
function resourceToProto(value: AuthorizationResource | undefined) {
|
|
694
|
+
if (!value) {
|
|
695
|
+
return undefined;
|
|
696
|
+
}
|
|
697
|
+
return create(ResourceSchema, {
|
|
698
|
+
type: value.type ?? "",
|
|
699
|
+
id: value.id ?? "",
|
|
700
|
+
properties: value.properties === undefined
|
|
701
|
+
? undefined
|
|
702
|
+
: structFromObject(value.properties),
|
|
1322
703
|
});
|
|
1323
704
|
}
|
|
1324
705
|
|
|
1325
|
-
function
|
|
706
|
+
function relationshipFilterFromProto(
|
|
707
|
+
value: ProtoRelationshipFilter | undefined,
|
|
708
|
+
): RelationshipFilter | undefined {
|
|
709
|
+
if (!value) {
|
|
710
|
+
return undefined;
|
|
711
|
+
}
|
|
1326
712
|
return {
|
|
1327
|
-
|
|
713
|
+
target: relationshipTargetFromProto(value.target),
|
|
714
|
+
relation: value.relation,
|
|
715
|
+
resource: resourceFromProto(value.resource),
|
|
716
|
+
targetType: value.targetType,
|
|
717
|
+
targetEntityType: value.targetEntityType,
|
|
718
|
+
resourceType: value.resourceType,
|
|
719
|
+
sourceLayer: value.sourceLayer,
|
|
1328
720
|
};
|
|
1329
721
|
}
|
|
1330
722
|
|
|
1331
|
-
function
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
|
-
function authorizationListModelsFromProto(input: ProtoListModelsResponse): AuthorizationListModels {
|
|
723
|
+
function relationshipFromProto(
|
|
724
|
+
value: ProtoRelationship | undefined,
|
|
725
|
+
): Relationship | undefined {
|
|
726
|
+
if (!value) {
|
|
727
|
+
return undefined;
|
|
728
|
+
}
|
|
1339
729
|
return {
|
|
1340
|
-
|
|
1341
|
-
|
|
730
|
+
tuple: relationshipTupleFromProto(value.tuple),
|
|
731
|
+
properties: jsonObjectFromStruct(value.properties),
|
|
732
|
+
sourceLayer: value.sourceLayer,
|
|
1342
733
|
};
|
|
1343
734
|
}
|
|
1344
735
|
|
|
1345
|
-
function
|
|
1346
|
-
return
|
|
1347
|
-
type: input.type,
|
|
1348
|
-
id: input.id,
|
|
1349
|
-
properties: optionalStruct(input.properties),
|
|
1350
|
-
});
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
function authorizationSubjectFromProto(input?: ProtoSubject | undefined): AuthorizationSubject | undefined {
|
|
1354
|
-
return input === undefined ? undefined : authorizationSubjectFromProtoRequired(input);
|
|
736
|
+
function relationshipFromProtoRequired(value: ProtoRelationship): Relationship {
|
|
737
|
+
return relationshipFromProto(value)!;
|
|
1355
738
|
}
|
|
1356
739
|
|
|
1357
|
-
function
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
type: input.type,
|
|
1368
|
-
id: input.id,
|
|
1369
|
-
properties: optionalStruct(input.properties),
|
|
740
|
+
function relationshipToProto(value: Relationship | undefined) {
|
|
741
|
+
if (!value) {
|
|
742
|
+
return undefined;
|
|
743
|
+
}
|
|
744
|
+
return create(RelationshipSchema, {
|
|
745
|
+
tuple: relationshipTupleToProto(value.tuple),
|
|
746
|
+
properties: value.properties === undefined
|
|
747
|
+
? undefined
|
|
748
|
+
: structFromObject(value.properties),
|
|
749
|
+
sourceLayer: value.sourceLayer ?? SourceLayer.UNSPECIFIED,
|
|
1370
750
|
});
|
|
1371
751
|
}
|
|
1372
752
|
|
|
1373
|
-
function
|
|
1374
|
-
return
|
|
753
|
+
function relationshipToProtoRequired(value: Relationship) {
|
|
754
|
+
return relationshipToProto(value)!;
|
|
1375
755
|
}
|
|
1376
756
|
|
|
1377
|
-
function
|
|
757
|
+
function relationshipTupleFromProto(
|
|
758
|
+
value: ProtoRelationshipTuple | undefined,
|
|
759
|
+
): RelationshipTuple | undefined {
|
|
760
|
+
if (!value) {
|
|
761
|
+
return undefined;
|
|
762
|
+
}
|
|
1378
763
|
return {
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
764
|
+
target: relationshipTargetFromProto(value.target),
|
|
765
|
+
relation: value.relation,
|
|
766
|
+
resource: resourceFromProto(value.resource),
|
|
1382
767
|
};
|
|
1383
768
|
}
|
|
1384
769
|
|
|
1385
|
-
function
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
770
|
+
function relationshipTupleToProto(value: RelationshipTuple | undefined) {
|
|
771
|
+
if (!value) {
|
|
772
|
+
return undefined;
|
|
773
|
+
}
|
|
774
|
+
return create(RelationshipTupleSchema, {
|
|
775
|
+
target: relationshipTargetToProto(value.target),
|
|
776
|
+
relation: value.relation ?? "",
|
|
777
|
+
resource: resourceToProto(value.resource),
|
|
1389
778
|
});
|
|
1390
779
|
}
|
|
1391
780
|
|
|
1392
|
-
function
|
|
1393
|
-
|
|
781
|
+
function relationshipTargetFromProto(
|
|
782
|
+
value: ProtoRelationshipTarget | undefined,
|
|
783
|
+
): RelationshipTarget | undefined {
|
|
784
|
+
if (!value) {
|
|
1394
785
|
return undefined;
|
|
1395
786
|
}
|
|
1396
|
-
|
|
1397
|
-
resource: authorizationResourceFromProto(input.resource),
|
|
1398
|
-
relation: input.relation,
|
|
1399
|
-
};
|
|
1400
|
-
}
|
|
1401
|
-
|
|
1402
|
-
function authorizationRelationshipTargetToProto(input: AuthorizationRelationshipTarget) {
|
|
1403
|
-
switch (input.kind.case) {
|
|
787
|
+
switch (value.kind.case) {
|
|
1404
788
|
case "subject":
|
|
1405
|
-
return
|
|
1406
|
-
kind: { case: "subject", value: authorizationSubjectToProto(input.kind.value) },
|
|
1407
|
-
});
|
|
789
|
+
return { subject: subjectFromProto(value.kind.value) };
|
|
1408
790
|
case "resource":
|
|
1409
|
-
return
|
|
1410
|
-
kind: { case: "resource", value: authorizationResourceToProto(input.kind.value) },
|
|
1411
|
-
});
|
|
791
|
+
return { resource: resourceFromProto(value.kind.value) };
|
|
1412
792
|
case "subjectSet":
|
|
1413
|
-
return
|
|
1414
|
-
kind: { case: "subjectSet", value: authorizationSubjectSetToProto(input.kind.value) },
|
|
1415
|
-
});
|
|
793
|
+
return { subjectSet: subjectSetFromProto(value.kind.value) };
|
|
1416
794
|
default:
|
|
1417
|
-
return
|
|
795
|
+
return {};
|
|
1418
796
|
}
|
|
1419
797
|
}
|
|
1420
798
|
|
|
1421
|
-
function
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
return input === undefined ? undefined : authorizationRelationshipTargetFromProtoRequired(input);
|
|
1425
|
-
}
|
|
1426
|
-
|
|
1427
|
-
function authorizationRelationshipTargetFromProtoRequired(
|
|
1428
|
-
input: ProtoRelationshipTarget,
|
|
1429
|
-
): AuthorizationRelationshipTarget {
|
|
1430
|
-
switch (input.kind.case) {
|
|
1431
|
-
case "subject":
|
|
1432
|
-
return { kind: { case: "subject", value: authorizationSubjectFromProtoRequired(input.kind.value) } };
|
|
1433
|
-
case "resource":
|
|
1434
|
-
return { kind: { case: "resource", value: authorizationResourceFromProtoRequired(input.kind.value) } };
|
|
1435
|
-
case "subjectSet":
|
|
1436
|
-
return { kind: { case: "subjectSet", value: authorizationSubjectSetFromProto(input.kind.value)! } };
|
|
1437
|
-
default:
|
|
1438
|
-
return { kind: { case: undefined } };
|
|
799
|
+
function relationshipTargetToProto(value: RelationshipTarget | undefined) {
|
|
800
|
+
if (!value) {
|
|
801
|
+
return undefined;
|
|
1439
802
|
}
|
|
803
|
+
if (value.subject) {
|
|
804
|
+
return create(RelationshipTargetSchema, {
|
|
805
|
+
kind: { case: "subject", value: subjectToProto(value.subject)! },
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
if (value.resource) {
|
|
809
|
+
return create(RelationshipTargetSchema, {
|
|
810
|
+
kind: { case: "resource", value: resourceToProto(value.resource)! },
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
if (value.subjectSet) {
|
|
814
|
+
return create(RelationshipTargetSchema, {
|
|
815
|
+
kind: { case: "subjectSet", value: subjectSetToProto(value.subjectSet) },
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
return create(RelationshipTargetSchema);
|
|
1440
819
|
}
|
|
1441
820
|
|
|
1442
|
-
function
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
});
|
|
1447
|
-
}
|
|
1448
|
-
|
|
1449
|
-
function authorizationActionFromProto(input?: ProtoAction | undefined): AuthorizationAction | undefined {
|
|
1450
|
-
return input === undefined ? undefined : authorizationActionFromProtoRequired(input);
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
|
-
function authorizationActionFromProtoRequired(input: ProtoAction): AuthorizationAction {
|
|
1454
|
-
return {
|
|
1455
|
-
name: input.name,
|
|
1456
|
-
properties: optionalObjectFromStruct(input.properties),
|
|
1457
|
-
};
|
|
1458
|
-
}
|
|
1459
|
-
|
|
1460
|
-
function authorizationRelationshipToProto(input: AuthorizationRelationship) {
|
|
1461
|
-
return create(RelationshipSchema, {
|
|
1462
|
-
subject: input.subject === undefined ? undefined : authorizationSubjectToProto(input.subject),
|
|
1463
|
-
relation: input.relation,
|
|
1464
|
-
resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
|
|
1465
|
-
properties: optionalStruct(input.properties),
|
|
1466
|
-
target: input.target === undefined ? undefined : authorizationRelationshipTargetToProto(input.target),
|
|
1467
|
-
});
|
|
1468
|
-
}
|
|
1469
|
-
|
|
1470
|
-
function authorizationRelationshipFromProto(input: ProtoRelationship): AuthorizationRelationship {
|
|
821
|
+
function subjectSetFromProto(value: ProtoSubjectSet | undefined): SubjectSet | undefined {
|
|
822
|
+
if (!value) {
|
|
823
|
+
return undefined;
|
|
824
|
+
}
|
|
1471
825
|
return {
|
|
1472
|
-
|
|
1473
|
-
relation:
|
|
1474
|
-
resource: authorizationResourceFromProto(input.resource),
|
|
1475
|
-
properties: optionalObjectFromStruct(input.properties),
|
|
1476
|
-
target: authorizationRelationshipTargetFromProto(input.target),
|
|
826
|
+
resource: resourceFromProto(value.resource),
|
|
827
|
+
relation: value.relation,
|
|
1477
828
|
};
|
|
1478
829
|
}
|
|
1479
830
|
|
|
1480
|
-
function
|
|
1481
|
-
return create(
|
|
1482
|
-
|
|
1483
|
-
relation:
|
|
1484
|
-
resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
|
|
1485
|
-
target: input.target === undefined ? undefined : authorizationRelationshipTargetToProto(input.target),
|
|
831
|
+
function subjectSetToProto(value: SubjectSet) {
|
|
832
|
+
return create(SubjectSetSchema, {
|
|
833
|
+
resource: resourceToProto(value.resource),
|
|
834
|
+
relation: value.relation ?? "",
|
|
1486
835
|
});
|
|
1487
836
|
}
|
|
1488
837
|
|
|
1489
|
-
function
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
resource: authorizationResourceFromProto(input.resource),
|
|
1494
|
-
target: authorizationRelationshipTargetFromProto(input.target),
|
|
1495
|
-
};
|
|
1496
|
-
}
|
|
1497
|
-
|
|
1498
|
-
function authorizationModelToProto(input: AuthorizationModel) {
|
|
1499
|
-
return {
|
|
1500
|
-
version: input.version ?? 0,
|
|
1501
|
-
resourceTypes: input.resourceTypes?.map(authorizationModelResourceTypeToProto) ?? [],
|
|
1502
|
-
};
|
|
1503
|
-
}
|
|
1504
|
-
|
|
1505
|
-
function authorizationModelFromProto(input?: ProtoAuthorizationModel | undefined): AuthorizationModel | undefined {
|
|
1506
|
-
if (input === undefined) {
|
|
838
|
+
function authorizationModelFromProto(
|
|
839
|
+
value: ProtoAuthorizationModel | undefined,
|
|
840
|
+
): AuthorizationModel | undefined {
|
|
841
|
+
if (!value) {
|
|
1507
842
|
return undefined;
|
|
1508
843
|
}
|
|
1509
844
|
return {
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
}
|
|
1514
|
-
|
|
1515
|
-
function authorizationModelResourceTypeToProto(input: AuthorizationModelResourceType) {
|
|
1516
|
-
return {
|
|
1517
|
-
name: input.name,
|
|
1518
|
-
relations: input.relations?.map(authorizationModelRelationToProto) ?? [],
|
|
1519
|
-
actions: input.actions?.map(authorizationModelActionToProto) ?? [],
|
|
845
|
+
id: value.id,
|
|
846
|
+
version: value.version,
|
|
847
|
+
resourceTypes: value.resourceTypes.map(authorizationModelResourceTypeFromProto),
|
|
1520
848
|
};
|
|
1521
849
|
}
|
|
1522
850
|
|
|
1523
851
|
function authorizationModelResourceTypeFromProto(
|
|
1524
|
-
|
|
852
|
+
value: ProtoAuthorizationModelResourceType,
|
|
1525
853
|
): AuthorizationModelResourceType {
|
|
1526
854
|
return {
|
|
1527
|
-
name:
|
|
1528
|
-
relations:
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
}
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
rewrite: input.rewrite === undefined ? undefined : authorizationModelRewriteToProto(input.rewrite),
|
|
1539
|
-
};
|
|
1540
|
-
}
|
|
1541
|
-
|
|
1542
|
-
function authorizationModelRelationFromProto(
|
|
1543
|
-
input: ProtoAuthorizationModelRelation,
|
|
1544
|
-
): AuthorizationModelRelation {
|
|
1545
|
-
return {
|
|
1546
|
-
name: input.name,
|
|
1547
|
-
subjectTypes: [...input.subjectTypes],
|
|
1548
|
-
allowedTargets: input.allowedTargets.map(authorizationModelAllowedTargetFromProto),
|
|
1549
|
-
rewrite: authorizationModelRewriteFromProto(input.rewrite),
|
|
1550
|
-
};
|
|
1551
|
-
}
|
|
1552
|
-
|
|
1553
|
-
function authorizationModelActionToProto(input: AuthorizationModelAction) {
|
|
1554
|
-
return {
|
|
1555
|
-
name: input.name,
|
|
1556
|
-
relations: [...(input.relations ?? [])],
|
|
1557
|
-
rewrite: input.rewrite === undefined ? undefined : authorizationModelRewriteToProto(input.rewrite),
|
|
1558
|
-
};
|
|
1559
|
-
}
|
|
1560
|
-
|
|
1561
|
-
function authorizationModelActionFromProto(input: ProtoAuthorizationModelAction): AuthorizationModelAction {
|
|
1562
|
-
return {
|
|
1563
|
-
name: input.name,
|
|
1564
|
-
relations: [...input.relations],
|
|
1565
|
-
rewrite: authorizationModelRewriteFromProto(input.rewrite),
|
|
855
|
+
name: value.name,
|
|
856
|
+
relations: value.relations.map((relation) => ({
|
|
857
|
+
name: relation.name,
|
|
858
|
+
allowedTargets: relation.allowedTargets.map(modelAllowedTargetFromProto),
|
|
859
|
+
})),
|
|
860
|
+
actions: value.actions.map((action) => ({
|
|
861
|
+
name: action.name,
|
|
862
|
+
relations: [...action.relations],
|
|
863
|
+
})),
|
|
864
|
+
sourceLayer: value.sourceLayer,
|
|
865
|
+
defaultAccessPolicy: value.defaultAccessPolicy,
|
|
1566
866
|
};
|
|
1567
867
|
}
|
|
1568
868
|
|
|
1569
|
-
function
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
869
|
+
function authorizationModelResourceTypeToProto(
|
|
870
|
+
value: AuthorizationModelResourceType,
|
|
871
|
+
) {
|
|
872
|
+
return create(AuthorizationModelResourceTypeSchema, {
|
|
873
|
+
name: value.name ?? "",
|
|
874
|
+
relations: (value.relations ?? []).map((relation) =>
|
|
875
|
+
create(ModelRelationSchema, {
|
|
876
|
+
name: relation.name ?? "",
|
|
877
|
+
allowedTargets: (relation.allowedTargets ?? []).map(
|
|
878
|
+
modelAllowedTargetToProto,
|
|
879
|
+
),
|
|
880
|
+
})
|
|
881
|
+
),
|
|
882
|
+
actions: (value.actions ?? []).map((action) =>
|
|
883
|
+
create(ModelActionSchema, {
|
|
884
|
+
name: action.name ?? "",
|
|
885
|
+
relations: [...(action.relations ?? [])],
|
|
886
|
+
})
|
|
887
|
+
),
|
|
888
|
+
sourceLayer: value.sourceLayer ?? SourceLayer.UNSPECIFIED,
|
|
889
|
+
defaultAccessPolicy: value.defaultAccessPolicy ?? DefaultAccessPolicy.DENY,
|
|
890
|
+
});
|
|
1588
891
|
}
|
|
1589
892
|
|
|
1590
|
-
function
|
|
1591
|
-
|
|
1592
|
-
):
|
|
1593
|
-
switch (
|
|
893
|
+
function modelAllowedTargetFromProto(
|
|
894
|
+
value: ProtoModelAllowedTarget,
|
|
895
|
+
): ModelAllowedTarget {
|
|
896
|
+
switch (value.kind.case) {
|
|
1594
897
|
case "subjectType":
|
|
1595
|
-
return {
|
|
898
|
+
return { subjectType: value.kind.value };
|
|
1596
899
|
case "resourceType":
|
|
1597
|
-
return {
|
|
1598
|
-
case "
|
|
900
|
+
return { resourceType: value.kind.value };
|
|
901
|
+
case "subjectSetType":
|
|
1599
902
|
return {
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
903
|
+
subjectSetType: {
|
|
904
|
+
resourceType: value.kind.value.resourceType,
|
|
905
|
+
relation: value.kind.value.relation,
|
|
1603
906
|
},
|
|
1604
907
|
};
|
|
1605
908
|
default:
|
|
1606
|
-
return {
|
|
909
|
+
return {};
|
|
1607
910
|
}
|
|
1608
911
|
}
|
|
1609
912
|
|
|
1610
|
-
function
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
relation: input.relation,
|
|
1616
|
-
};
|
|
1617
|
-
}
|
|
1618
|
-
|
|
1619
|
-
function authorizationModelRewriteToProto(input: AuthorizationModelRewrite): ProtoAuthorizationModelRewrite {
|
|
1620
|
-
switch (input.kind.case) {
|
|
1621
|
-
case "this":
|
|
1622
|
-
return { kind: { case: "this", value: {} } } as ProtoAuthorizationModelRewrite;
|
|
1623
|
-
case "computedUserset":
|
|
1624
|
-
return {
|
|
1625
|
-
kind: {
|
|
1626
|
-
case: "computedUserset",
|
|
1627
|
-
value: { relation: input.kind.value.relation },
|
|
1628
|
-
},
|
|
1629
|
-
} as ProtoAuthorizationModelRewrite;
|
|
1630
|
-
case "tupleToUserset":
|
|
1631
|
-
return {
|
|
1632
|
-
kind: {
|
|
1633
|
-
case: "tupleToUserset",
|
|
1634
|
-
value: {
|
|
1635
|
-
tuplesetRelation: input.kind.value.tuplesetRelation,
|
|
1636
|
-
computedRelation: input.kind.value.computedRelation,
|
|
1637
|
-
},
|
|
1638
|
-
},
|
|
1639
|
-
} as ProtoAuthorizationModelRewrite;
|
|
1640
|
-
case "union":
|
|
1641
|
-
return {
|
|
1642
|
-
kind: {
|
|
1643
|
-
case: "union",
|
|
1644
|
-
value: {
|
|
1645
|
-
children: input.kind.value.children?.map(authorizationModelRewriteToProto) ?? [],
|
|
1646
|
-
},
|
|
1647
|
-
},
|
|
1648
|
-
} as ProtoAuthorizationModelRewrite;
|
|
1649
|
-
default:
|
|
1650
|
-
return { kind: { case: undefined } } as ProtoAuthorizationModelRewrite;
|
|
913
|
+
function modelAllowedTargetToProto(value: ModelAllowedTarget) {
|
|
914
|
+
if (value.subjectType !== undefined) {
|
|
915
|
+
return create(ModelAllowedTargetSchema, {
|
|
916
|
+
kind: { case: "subjectType", value: value.subjectType },
|
|
917
|
+
});
|
|
1651
918
|
}
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
): AuthorizationModelRewrite | undefined {
|
|
1657
|
-
if (input === undefined) {
|
|
1658
|
-
return undefined;
|
|
919
|
+
if (value.resourceType !== undefined) {
|
|
920
|
+
return create(ModelAllowedTargetSchema, {
|
|
921
|
+
kind: { case: "resourceType", value: value.resourceType },
|
|
922
|
+
});
|
|
1659
923
|
}
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
return { kind: { case: undefined } };
|
|
924
|
+
if (value.subjectSetType !== undefined) {
|
|
925
|
+
return create(ModelAllowedTargetSchema, {
|
|
926
|
+
kind: {
|
|
927
|
+
case: "subjectSetType",
|
|
928
|
+
value: create(SubjectSetTypeSchema, {
|
|
929
|
+
resourceType: value.subjectSetType.resourceType ?? "",
|
|
930
|
+
relation: value.subjectSetType.relation ?? "",
|
|
931
|
+
}),
|
|
932
|
+
},
|
|
933
|
+
});
|
|
1671
934
|
}
|
|
935
|
+
return create(ModelAllowedTargetSchema);
|
|
1672
936
|
}
|
|
1673
937
|
|
|
1674
|
-
function
|
|
1675
|
-
input: ProtoAuthorizationModelComputedUserset,
|
|
1676
|
-
): AuthorizationModelComputedUserset {
|
|
1677
|
-
return { relation: input.relation };
|
|
1678
|
-
}
|
|
1679
|
-
|
|
1680
|
-
function authorizationTupleToUsersetFromProto(
|
|
1681
|
-
input: ProtoAuthorizationModelTupleToUserset,
|
|
1682
|
-
): AuthorizationModelTupleToUserset {
|
|
1683
|
-
return {
|
|
1684
|
-
tuplesetRelation: input.tuplesetRelation,
|
|
1685
|
-
computedRelation: input.computedRelation,
|
|
1686
|
-
};
|
|
1687
|
-
}
|
|
1688
|
-
|
|
1689
|
-
function authorizationRewriteUnionFromProto(
|
|
1690
|
-
input: ProtoAuthorizationModelRewriteUnion,
|
|
1691
|
-
): AuthorizationModelRewriteUnion {
|
|
1692
|
-
return { children: input.children.map((child) => authorizationModelRewriteFromProto(child)!) };
|
|
1693
|
-
}
|
|
1694
|
-
|
|
1695
|
-
function authorizationModelRefToProto(input: AuthorizationModelRef) {
|
|
938
|
+
function authorizationModelRefToProto(value: AuthorizationModelRef) {
|
|
1696
939
|
return create(AuthorizationModelRefSchema, {
|
|
1697
|
-
id:
|
|
1698
|
-
version:
|
|
1699
|
-
createdAt:
|
|
1700
|
-
});
|
|
1701
|
-
}
|
|
1702
|
-
|
|
1703
|
-
function authorizationModelRefFromProto(input?: ProtoAuthorizationModelRef | undefined): AuthorizationModelRef | undefined {
|
|
1704
|
-
return input === undefined ? undefined : authorizationModelRefFromProtoRequired(input);
|
|
1705
|
-
}
|
|
1706
|
-
|
|
1707
|
-
function authorizationModelRefFromProtoRequired(input: ProtoAuthorizationModelRef): AuthorizationModelRef {
|
|
1708
|
-
return {
|
|
1709
|
-
id: input.id,
|
|
1710
|
-
version: input.version,
|
|
1711
|
-
createdAt: input.createdAt === undefined ? undefined : dateFromTimestamp(input.createdAt),
|
|
1712
|
-
};
|
|
1713
|
-
}
|
|
1714
|
-
|
|
1715
|
-
function authorizationExpandToProto(input: AuthorizationExpand) {
|
|
1716
|
-
return create(ExpandResponseSchema, {
|
|
1717
|
-
root: input.root === undefined ? undefined : authorizationExpandNodeToProto(input.root),
|
|
1718
|
-
truncated: input.truncated ?? false,
|
|
1719
|
-
cycleDetected: input.cycleDetected ?? false,
|
|
1720
|
-
maxDepthReached: input.maxDepthReached ?? false,
|
|
1721
|
-
modelId: input.modelId ?? "",
|
|
1722
|
-
});
|
|
1723
|
-
}
|
|
1724
|
-
|
|
1725
|
-
function authorizationExpandFromProto(input: ProtoExpandResponse): AuthorizationExpand {
|
|
1726
|
-
return {
|
|
1727
|
-
root: authorizationExpandNodeFromProto(input.root),
|
|
1728
|
-
truncated: input.truncated,
|
|
1729
|
-
cycleDetected: input.cycleDetected,
|
|
1730
|
-
maxDepthReached: input.maxDepthReached,
|
|
1731
|
-
modelId: input.modelId,
|
|
1732
|
-
};
|
|
1733
|
-
}
|
|
1734
|
-
|
|
1735
|
-
function authorizationExpandNodeToProto(input: AuthorizationExpandNode): ProtoExpandNode {
|
|
1736
|
-
return create(ExpandNodeSchema, {
|
|
1737
|
-
target: input.target === undefined ? undefined : authorizationRelationshipTargetToProto(input.target),
|
|
1738
|
-
relation: input.relation ?? "",
|
|
1739
|
-
children: input.children?.map(authorizationExpandNodeToProto) ?? [],
|
|
940
|
+
id: value.id ?? "",
|
|
941
|
+
version: value.version ?? "",
|
|
942
|
+
createdAt: value.createdAt ? timestampFromDate(value.createdAt) : undefined,
|
|
1740
943
|
});
|
|
1741
944
|
}
|
|
1742
945
|
|
|
1743
|
-
function
|
|
1744
|
-
if (
|
|
1745
|
-
return
|
|
1746
|
-
}
|
|
1747
|
-
return {
|
|
1748
|
-
target: authorizationRelationshipTargetFromProto(input.target),
|
|
1749
|
-
relation: input.relation,
|
|
1750
|
-
children: input.children.map((child) => authorizationExpandNodeFromProto(child)!),
|
|
1751
|
-
};
|
|
1752
|
-
}
|
|
1753
|
-
|
|
1754
|
-
function resolveAuthorizationSocketTarget(
|
|
1755
|
-
socketPath = process.env[ENV_HOST_SERVICE_SOCKET],
|
|
1756
|
-
): string {
|
|
1757
|
-
const trimmed = socketPath?.trim() ?? "";
|
|
1758
|
-
if (!trimmed) {
|
|
1759
|
-
throw new Error(`authorization: ${ENV_HOST_SERVICE_SOCKET} is not set`);
|
|
1760
|
-
}
|
|
1761
|
-
return trimmed;
|
|
1762
|
-
}
|
|
1763
|
-
|
|
1764
|
-
function pushCapability(capabilities: string[], capability: string): void {
|
|
1765
|
-
if (!capabilities.includes(capability)) {
|
|
1766
|
-
capabilities.push(capability);
|
|
946
|
+
function authorizationRuntimeError(label: string, error: unknown): ConnectError {
|
|
947
|
+
if (error instanceof ConnectError) {
|
|
948
|
+
return error;
|
|
1767
949
|
}
|
|
950
|
+
return new ConnectError(`${label}: ${errorMessage(error)}`, Code.Unknown);
|
|
1768
951
|
}
|