@valon-technologies/gestalt 0.0.1-alpha.33 → 0.0.1-alpha.35
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 +675 -1400
- package/src/index.ts +47 -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,5 +1,4 @@
|
|
|
1
1
|
import { create } from "@bufbuild/protobuf";
|
|
2
|
-
import { EmptySchema } from "@bufbuild/protobuf/wkt";
|
|
3
2
|
import {
|
|
4
3
|
Code,
|
|
5
4
|
ConnectError,
|
|
@@ -9,662 +8,393 @@ import {
|
|
|
9
8
|
} from "@connectrpc/connect";
|
|
10
9
|
|
|
11
10
|
import {
|
|
12
|
-
|
|
13
|
-
AccessEvaluationRequestSchema,
|
|
14
|
-
AccessEvaluationsRequestSchema,
|
|
15
|
-
AccessEvaluationsResponseSchema,
|
|
16
|
-
ActionSearchRequestSchema,
|
|
17
|
-
ActionSearchResponseSchema,
|
|
18
|
-
ActionSchema,
|
|
19
|
-
AuthorizationMetadataSchema,
|
|
11
|
+
AddRelationshipResponseSchema,
|
|
20
12
|
AuthorizationModelRefSchema,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
13
|
+
AuthorizationModelResourceTypeSchema,
|
|
14
|
+
CheckAccessManyResponseSchema,
|
|
15
|
+
CheckAccessResponseSchema,
|
|
16
|
+
DefaultAccessPolicy as ProtoDefaultAccessPolicy,
|
|
17
|
+
DeleteRelationshipResponseSchema,
|
|
18
|
+
GetActiveModelRefResponseSchema,
|
|
19
|
+
ListRelationshipsRequestSchema,
|
|
20
|
+
ListActiveModelResourceTypesResponseSchema,
|
|
21
|
+
ListRelationshipsResponseSchema,
|
|
22
|
+
ModelActionSchema,
|
|
23
|
+
ModelAllowedTargetSchema,
|
|
24
|
+
ModelRelationSchema,
|
|
33
25
|
RelationshipSchema,
|
|
34
26
|
RelationshipTargetSchema,
|
|
27
|
+
RelationshipTargetType as ProtoRelationshipTargetType,
|
|
28
|
+
RelationshipTupleSchema,
|
|
35
29
|
ResourceSchema,
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
SetActiveModelResponseSchema,
|
|
31
|
+
SetAuthorizationStateResponseSchema,
|
|
32
|
+
SourceLayer as ProtoSourceLayer,
|
|
38
33
|
SubjectSchema,
|
|
39
|
-
SubjectSearchRequestSchema,
|
|
40
|
-
SubjectSearchResponseSchema,
|
|
41
34
|
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,
|
|
35
|
+
SubjectSetTypeSchema,
|
|
36
|
+
AuthorizationProvider as AuthorizationProviderService,
|
|
37
|
+
type AddRelationshipRequest as ProtoAddRelationshipRequest,
|
|
52
38
|
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
39
|
type AuthorizationModelResourceType as ProtoAuthorizationModelResourceType,
|
|
59
|
-
type
|
|
60
|
-
type
|
|
61
|
-
type
|
|
62
|
-
type
|
|
63
|
-
type
|
|
64
|
-
type
|
|
65
|
-
type
|
|
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,
|
|
40
|
+
type CheckAccessManyRequest as ProtoCheckAccessManyRequest,
|
|
41
|
+
type CheckAccessRequest as ProtoCheckAccessRequest,
|
|
42
|
+
type DeleteRelationshipRequest as ProtoDeleteRelationshipRequest,
|
|
43
|
+
type ListActiveModelResourceTypesRequest as ProtoListActiveModelResourceTypesRequest,
|
|
44
|
+
type ListRelationshipsRequest as ProtoListRelationshipsRequest,
|
|
45
|
+
type ListRelationshipsResponse as ProtoListRelationshipsResponse,
|
|
46
|
+
type ModelAllowedTarget as ProtoModelAllowedTarget,
|
|
73
47
|
type Relationship as ProtoRelationship,
|
|
74
|
-
type
|
|
48
|
+
type RelationshipFilter as ProtoRelationshipFilter,
|
|
75
49
|
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,
|
|
50
|
+
type RelationshipTuple as ProtoRelationshipTuple,
|
|
51
|
+
type SetActiveModelRequest as ProtoSetActiveModelRequest,
|
|
52
|
+
type SetAuthorizationStateRequest as ProtoSetAuthorizationStateRequest,
|
|
82
53
|
type SubjectSet as ProtoSubjectSet,
|
|
83
|
-
type WriteModelRequest as ProtoWriteModelRequest,
|
|
84
|
-
type WriteRelationshipsRequest as ProtoWriteRelationshipsRequest,
|
|
85
54
|
} from "./internal/gen/v1/authorization_pb.ts";
|
|
55
|
+
import { errorMessage, type MaybePromise } from "./api.ts";
|
|
56
|
+
import { ProviderBase, type ProviderBaseOptions } from "./provider.ts";
|
|
86
57
|
import {
|
|
87
|
-
|
|
58
|
+
jsonObjectFromStruct,
|
|
59
|
+
structFromObject,
|
|
88
60
|
timestampFromDate,
|
|
89
61
|
type JsonObjectInput,
|
|
90
62
|
} 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
63
|
import {
|
|
98
64
|
createHostServiceGrpcTransport,
|
|
99
65
|
hostServiceMetadataInterceptors,
|
|
100
66
|
parseHostServiceTarget,
|
|
101
|
-
|
|
102
|
-
ENV_HOST_SERVICE_TOKEN,
|
|
67
|
+
requireHostServiceTarget,
|
|
103
68
|
} from "./host-service.ts";
|
|
104
69
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
70
|
+
export const RelationshipTargetType = {
|
|
71
|
+
UNSPECIFIED: ProtoRelationshipTargetType.UNSPECIFIED,
|
|
72
|
+
SUBJECT: ProtoRelationshipTargetType.SUBJECT,
|
|
73
|
+
RESOURCE: ProtoRelationshipTargetType.RESOURCE,
|
|
74
|
+
SUBJECT_SET: ProtoRelationshipTargetType.SUBJECT_SET,
|
|
75
|
+
} as const;
|
|
76
|
+
export type RelationshipTargetType =
|
|
77
|
+
(typeof RelationshipTargetType)[keyof typeof RelationshipTargetType];
|
|
78
|
+
|
|
79
|
+
export const SourceLayer = {
|
|
80
|
+
UNSPECIFIED: ProtoSourceLayer.UNSPECIFIED,
|
|
81
|
+
STATIC_CONFIG: ProtoSourceLayer.STATIC_CONFIG,
|
|
82
|
+
RUNTIME: ProtoSourceLayer.RUNTIME,
|
|
83
|
+
} as const;
|
|
84
|
+
export type SourceLayer = (typeof SourceLayer)[keyof typeof SourceLayer];
|
|
85
|
+
|
|
86
|
+
export const DefaultAccessPolicy = {
|
|
87
|
+
DENY: ProtoDefaultAccessPolicy.DENY,
|
|
88
|
+
ALLOW: ProtoDefaultAccessPolicy.ALLOW,
|
|
89
|
+
} as const;
|
|
90
|
+
export type DefaultAccessPolicy =
|
|
91
|
+
(typeof DefaultAccessPolicy)[keyof typeof DefaultAccessPolicy];
|
|
111
92
|
|
|
112
93
|
export interface AuthorizationSubject {
|
|
113
|
-
type
|
|
114
|
-
id
|
|
94
|
+
type?: string | undefined;
|
|
95
|
+
id?: string | undefined;
|
|
115
96
|
properties?: JsonObjectInput | undefined;
|
|
116
97
|
}
|
|
117
98
|
|
|
118
|
-
export interface
|
|
119
|
-
|
|
120
|
-
id: string;
|
|
99
|
+
export interface AuthorizationAction {
|
|
100
|
+
name?: string | undefined;
|
|
121
101
|
properties?: JsonObjectInput | undefined;
|
|
122
102
|
}
|
|
123
103
|
|
|
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;
|
|
104
|
+
export interface AuthorizationResource {
|
|
105
|
+
type?: string | undefined;
|
|
106
|
+
id?: string | undefined;
|
|
141
107
|
properties?: JsonObjectInput | undefined;
|
|
142
108
|
}
|
|
143
109
|
|
|
144
|
-
export interface
|
|
110
|
+
export interface CheckAccessRequest {
|
|
145
111
|
subject?: AuthorizationSubject | undefined;
|
|
146
112
|
action?: AuthorizationAction | undefined;
|
|
147
113
|
resource?: AuthorizationResource | undefined;
|
|
148
|
-
context?: JsonObjectInput | undefined;
|
|
149
114
|
}
|
|
150
115
|
|
|
151
|
-
export interface
|
|
116
|
+
export interface CheckAccessResponse {
|
|
152
117
|
allowed?: boolean | undefined;
|
|
153
|
-
context?: JsonObjectInput | undefined;
|
|
154
118
|
modelId?: string | undefined;
|
|
155
119
|
}
|
|
156
120
|
|
|
157
|
-
export interface
|
|
158
|
-
requests
|
|
121
|
+
export interface CheckAccessManyRequest {
|
|
122
|
+
requests?: readonly CheckAccessRequest[] | undefined;
|
|
159
123
|
}
|
|
160
124
|
|
|
161
|
-
export interface
|
|
162
|
-
decisions
|
|
125
|
+
export interface CheckAccessManyResponse {
|
|
126
|
+
decisions?: readonly CheckAccessResponse[] | undefined;
|
|
163
127
|
}
|
|
164
128
|
|
|
165
|
-
export interface
|
|
166
|
-
|
|
167
|
-
|
|
129
|
+
export interface RelationshipFilter {
|
|
130
|
+
target?: RelationshipTarget | undefined;
|
|
131
|
+
relation?: string | undefined;
|
|
132
|
+
resource?: AuthorizationResource | undefined;
|
|
133
|
+
targetType?: RelationshipTargetType | undefined;
|
|
134
|
+
targetEntityType?: string | undefined;
|
|
168
135
|
resourceType?: string | undefined;
|
|
169
|
-
|
|
170
|
-
pageSize?: number | undefined;
|
|
171
|
-
pageToken?: string | undefined;
|
|
136
|
+
sourceLayer?: SourceLayer | undefined;
|
|
172
137
|
}
|
|
173
138
|
|
|
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;
|
|
139
|
+
export interface ListRelationshipsRequest {
|
|
140
|
+
filter?: RelationshipFilter | undefined;
|
|
185
141
|
pageSize?: number | undefined;
|
|
186
142
|
pageToken?: string | undefined;
|
|
187
143
|
}
|
|
188
144
|
|
|
189
|
-
export interface
|
|
190
|
-
|
|
145
|
+
export interface ListRelationshipsResponse {
|
|
146
|
+
relationships?: readonly Relationship[] | undefined;
|
|
191
147
|
nextPageToken?: string | undefined;
|
|
192
|
-
modelId?: string | undefined;
|
|
193
148
|
}
|
|
194
149
|
|
|
195
|
-
export interface
|
|
196
|
-
|
|
197
|
-
action?: AuthorizationAction | undefined;
|
|
198
|
-
context?: JsonObjectInput | undefined;
|
|
199
|
-
pageSize?: number | undefined;
|
|
200
|
-
pageToken?: string | undefined;
|
|
150
|
+
export interface AddRelationshipRequest {
|
|
151
|
+
relationship?: Relationship | undefined;
|
|
201
152
|
}
|
|
202
153
|
|
|
203
|
-
export interface
|
|
204
|
-
|
|
205
|
-
nextPageToken?: string | undefined;
|
|
206
|
-
modelId?: string | undefined;
|
|
207
|
-
truncated?: boolean | undefined;
|
|
154
|
+
export interface AddRelationshipResponse {
|
|
155
|
+
relationship?: Relationship | undefined;
|
|
208
156
|
}
|
|
209
157
|
|
|
210
|
-
export interface
|
|
211
|
-
|
|
212
|
-
resource?: AuthorizationResource | undefined;
|
|
213
|
-
context?: JsonObjectInput | undefined;
|
|
214
|
-
pageSize?: number | undefined;
|
|
215
|
-
pageToken?: string | undefined;
|
|
158
|
+
export interface DeleteRelationshipRequest {
|
|
159
|
+
relationshipTuple?: RelationshipTuple | undefined;
|
|
216
160
|
}
|
|
217
161
|
|
|
218
|
-
export interface
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
162
|
+
export interface DeleteRelationshipResponse {}
|
|
163
|
+
|
|
164
|
+
export interface SetAuthorizationStateRequest {
|
|
165
|
+
model?: AuthorizationModel | undefined;
|
|
166
|
+
relationships?: readonly Relationship[] | undefined;
|
|
222
167
|
}
|
|
223
168
|
|
|
224
|
-
export interface
|
|
225
|
-
|
|
226
|
-
activeModelId?: string | undefined;
|
|
169
|
+
export interface SetAuthorizationStateResponse {
|
|
170
|
+
activeModel?: AuthorizationModelRef | undefined;
|
|
227
171
|
}
|
|
228
172
|
|
|
229
|
-
export interface
|
|
230
|
-
|
|
231
|
-
relation: string;
|
|
232
|
-
resource?: AuthorizationResource | undefined;
|
|
173
|
+
export interface Relationship {
|
|
174
|
+
tuple?: RelationshipTuple | undefined;
|
|
233
175
|
properties?: JsonObjectInput | undefined;
|
|
234
|
-
|
|
176
|
+
sourceLayer?: SourceLayer | undefined;
|
|
235
177
|
}
|
|
236
178
|
|
|
237
|
-
export interface
|
|
238
|
-
|
|
239
|
-
relation
|
|
179
|
+
export interface RelationshipTuple {
|
|
180
|
+
target?: RelationshipTarget | undefined;
|
|
181
|
+
relation?: string | undefined;
|
|
240
182
|
resource?: AuthorizationResource | undefined;
|
|
241
|
-
target?: AuthorizationRelationshipTarget | undefined;
|
|
242
183
|
}
|
|
243
184
|
|
|
244
|
-
export interface
|
|
185
|
+
export interface RelationshipTarget {
|
|
245
186
|
subject?: AuthorizationSubject | undefined;
|
|
246
|
-
relation?: string | undefined;
|
|
247
187
|
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;
|
|
188
|
+
subjectSet?: SubjectSet | undefined;
|
|
258
189
|
}
|
|
259
190
|
|
|
260
|
-
export interface
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
modelId?: string | undefined;
|
|
191
|
+
export interface SubjectSet {
|
|
192
|
+
resource?: AuthorizationResource | undefined;
|
|
193
|
+
relation?: string | undefined;
|
|
264
194
|
}
|
|
265
195
|
|
|
266
196
|
export interface AuthorizationModel {
|
|
267
|
-
|
|
197
|
+
id?: string | undefined;
|
|
198
|
+
version?: string | undefined;
|
|
268
199
|
resourceTypes?: readonly AuthorizationModelResourceType[] | undefined;
|
|
269
200
|
}
|
|
270
201
|
|
|
271
202
|
export interface AuthorizationModelResourceType {
|
|
272
|
-
name
|
|
273
|
-
relations?: readonly
|
|
274
|
-
actions?: readonly
|
|
203
|
+
name?: string | undefined;
|
|
204
|
+
relations?: readonly ModelRelation[] | undefined;
|
|
205
|
+
actions?: readonly ModelAction[] | undefined;
|
|
206
|
+
sourceLayer?: SourceLayer | undefined;
|
|
207
|
+
defaultAccessPolicy?: DefaultAccessPolicy | undefined;
|
|
275
208
|
}
|
|
276
209
|
|
|
277
|
-
export interface
|
|
278
|
-
name
|
|
279
|
-
|
|
280
|
-
allowedTargets?: readonly AuthorizationModelAllowedTarget[] | undefined;
|
|
281
|
-
rewrite?: AuthorizationModelRewrite | undefined;
|
|
210
|
+
export interface ModelRelation {
|
|
211
|
+
name?: string | undefined;
|
|
212
|
+
allowedTargets?: readonly ModelAllowedTarget[] | undefined;
|
|
282
213
|
}
|
|
283
214
|
|
|
284
|
-
export interface
|
|
285
|
-
name
|
|
215
|
+
export interface ModelAction {
|
|
216
|
+
name?: string | undefined;
|
|
286
217
|
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
218
|
}
|
|
321
219
|
|
|
322
|
-
export interface
|
|
323
|
-
|
|
324
|
-
|
|
220
|
+
export interface ModelAllowedTarget {
|
|
221
|
+
subjectType?: string | undefined;
|
|
222
|
+
resourceType?: string | undefined;
|
|
223
|
+
subjectSetType?: SubjectSetType | undefined;
|
|
325
224
|
}
|
|
326
225
|
|
|
327
|
-
export interface
|
|
328
|
-
|
|
226
|
+
export interface SubjectSetType {
|
|
227
|
+
resourceType?: string | undefined;
|
|
228
|
+
relation?: string | undefined;
|
|
329
229
|
}
|
|
330
230
|
|
|
331
231
|
export interface AuthorizationModelRef {
|
|
332
|
-
id
|
|
333
|
-
version
|
|
232
|
+
id?: string | undefined;
|
|
233
|
+
version?: string | undefined;
|
|
334
234
|
createdAt?: Date | undefined;
|
|
335
235
|
}
|
|
336
236
|
|
|
337
|
-
export interface
|
|
338
|
-
|
|
339
|
-
relation?: string | undefined;
|
|
340
|
-
context?: JsonObjectInput | undefined;
|
|
341
|
-
maxDepth?: number | undefined;
|
|
342
|
-
modelId?: string | undefined;
|
|
237
|
+
export interface GetActiveModelRefResponse {
|
|
238
|
+
model?: AuthorizationModelRef | undefined;
|
|
343
239
|
}
|
|
344
240
|
|
|
345
|
-
export interface
|
|
346
|
-
|
|
347
|
-
relation?: string | undefined;
|
|
348
|
-
children?: readonly AuthorizationExpandNode[] | undefined;
|
|
241
|
+
export interface SetActiveModelRequest {
|
|
242
|
+
model?: AuthorizationModel | undefined;
|
|
349
243
|
}
|
|
350
244
|
|
|
351
|
-
export interface
|
|
352
|
-
|
|
353
|
-
truncated?: boolean | undefined;
|
|
354
|
-
cycleDetected?: boolean | undefined;
|
|
355
|
-
maxDepthReached?: boolean | undefined;
|
|
356
|
-
modelId?: string | undefined;
|
|
245
|
+
export interface SetActiveModelResponse {
|
|
246
|
+
model?: AuthorizationModelRef | undefined;
|
|
357
247
|
}
|
|
358
248
|
|
|
359
|
-
export interface
|
|
360
|
-
|
|
249
|
+
export interface AuthorizationModelResourceTypeFilter {
|
|
250
|
+
name?: string | undefined;
|
|
251
|
+
sourceLayer?: SourceLayer | undefined;
|
|
361
252
|
}
|
|
362
253
|
|
|
363
|
-
export interface
|
|
254
|
+
export interface ListActiveModelResourceTypesRequest {
|
|
255
|
+
filter?: AuthorizationModelResourceTypeFilter | undefined;
|
|
364
256
|
pageSize?: number | undefined;
|
|
365
257
|
pageToken?: string | undefined;
|
|
366
258
|
}
|
|
367
259
|
|
|
368
|
-
export interface
|
|
369
|
-
|
|
260
|
+
export interface ListActiveModelResourceTypesResponse {
|
|
261
|
+
resourceTypes?: readonly AuthorizationModelResourceType[] | undefined;
|
|
370
262
|
nextPageToken?: string | undefined;
|
|
263
|
+
modelId?: string | undefined;
|
|
371
264
|
}
|
|
372
265
|
|
|
373
|
-
export interface
|
|
374
|
-
|
|
266
|
+
export interface Authorization {
|
|
267
|
+
listRelationships(
|
|
268
|
+
request: ListRelationshipsRequest,
|
|
269
|
+
): Promise<ListRelationshipsResponse>;
|
|
375
270
|
}
|
|
376
271
|
|
|
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
272
|
class AuthorizationImpl implements Authorization {
|
|
434
273
|
private readonly client: Client<typeof AuthorizationProviderService>;
|
|
435
274
|
|
|
436
|
-
constructor(
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
const resolvedTarget = resolveAuthorizationSocketTarget(socketTarget);
|
|
275
|
+
constructor(target?: string, relayToken?: string) {
|
|
276
|
+
const host = target
|
|
277
|
+
? { target, token: relayToken?.trim() ?? "" }
|
|
278
|
+
: requireHostServiceTarget("authorization");
|
|
441
279
|
const transport = createHostServiceGrpcTransport(
|
|
442
|
-
parseHostServiceTarget("authorization",
|
|
443
|
-
hostServiceMetadataInterceptors(
|
|
280
|
+
parseHostServiceTarget("authorization", host.target),
|
|
281
|
+
hostServiceMetadataInterceptors(host.token, ""),
|
|
444
282
|
);
|
|
445
283
|
this.client = createClient(AuthorizationProviderService, transport);
|
|
446
284
|
}
|
|
447
285
|
|
|
448
|
-
async
|
|
449
|
-
request:
|
|
450
|
-
): Promise<
|
|
451
|
-
return
|
|
452
|
-
await this.client.
|
|
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)),
|
|
286
|
+
async listRelationships(
|
|
287
|
+
request: ListRelationshipsRequest,
|
|
288
|
+
): Promise<ListRelationshipsResponse> {
|
|
289
|
+
return listRelationshipsResponseFromProto(
|
|
290
|
+
await this.client.listRelationships(listRelationshipsRequestToProto(request)),
|
|
509
291
|
);
|
|
510
292
|
}
|
|
293
|
+
}
|
|
511
294
|
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
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
|
-
}
|
|
295
|
+
let sharedAuthorization:
|
|
296
|
+
| { target: string; token: string; client: Authorization }
|
|
297
|
+
| undefined;
|
|
534
298
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
299
|
+
export function Authorization(): Authorization {
|
|
300
|
+
const { target, token } = requireHostServiceTarget("authorization");
|
|
301
|
+
if (
|
|
302
|
+
sharedAuthorization &&
|
|
303
|
+
sharedAuthorization.target === target &&
|
|
304
|
+
sharedAuthorization.token === token
|
|
305
|
+
) {
|
|
306
|
+
return sharedAuthorization.client;
|
|
541
307
|
}
|
|
542
308
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
return authorizationModelRefFromProtoRequired(
|
|
547
|
-
await this.client.writeModel(authorizationWriteModelInputToProto(request)),
|
|
548
|
-
);
|
|
549
|
-
}
|
|
309
|
+
const client = new AuthorizationImpl(target, token);
|
|
310
|
+
sharedAuthorization = { target, token, client };
|
|
311
|
+
return client;
|
|
550
312
|
}
|
|
551
313
|
|
|
552
314
|
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>;
|
|
315
|
+
checkAccess: (request: CheckAccessRequest) => MaybePromise<CheckAccessResponse>;
|
|
316
|
+
checkAccessMany: (
|
|
317
|
+
request: CheckAccessManyRequest,
|
|
318
|
+
) => MaybePromise<CheckAccessManyResponse>;
|
|
319
|
+
listRelationships: (
|
|
320
|
+
request: ListRelationshipsRequest,
|
|
321
|
+
) => MaybePromise<ListRelationshipsResponse>;
|
|
322
|
+
addRelationship: (
|
|
323
|
+
request: AddRelationshipRequest,
|
|
324
|
+
) => MaybePromise<AddRelationshipResponse>;
|
|
325
|
+
deleteRelationship: (
|
|
326
|
+
request: DeleteRelationshipRequest,
|
|
327
|
+
) => MaybePromise<DeleteRelationshipResponse | void>;
|
|
328
|
+
setAuthorizationState: (
|
|
329
|
+
request: SetAuthorizationStateRequest,
|
|
330
|
+
) => MaybePromise<SetAuthorizationStateResponse>;
|
|
331
|
+
getActiveModelRef: () => MaybePromise<GetActiveModelRefResponse>;
|
|
332
|
+
setActiveModel: (
|
|
333
|
+
request: SetActiveModelRequest,
|
|
334
|
+
) => MaybePromise<SetActiveModelResponse>;
|
|
335
|
+
listActiveModelResourceTypes: (
|
|
336
|
+
request: ListActiveModelResourceTypesRequest,
|
|
337
|
+
) => MaybePromise<ListActiveModelResourceTypesResponse>;
|
|
591
338
|
}
|
|
592
339
|
|
|
593
340
|
export class AuthorizationProvider extends ProviderBase {
|
|
594
341
|
readonly kind = "authorization" as const;
|
|
595
342
|
|
|
596
|
-
private readonly
|
|
343
|
+
private readonly handlers: AuthorizationProviderOptions;
|
|
597
344
|
|
|
598
345
|
constructor(options: AuthorizationProviderOptions) {
|
|
599
346
|
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);
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
supportsEffectiveSearch(): boolean {
|
|
620
|
-
return (
|
|
621
|
-
this.options.effectiveSearchResources !== undefined &&
|
|
622
|
-
this.options.effectiveSearchSubjects !== undefined
|
|
623
|
-
);
|
|
347
|
+
this.handlers = options;
|
|
624
348
|
}
|
|
625
349
|
|
|
626
|
-
|
|
627
|
-
return
|
|
350
|
+
checkAccess(request: CheckAccessRequest): Promise<CheckAccessResponse> {
|
|
351
|
+
return Promise.resolve(this.handlers.checkAccess(request));
|
|
628
352
|
}
|
|
629
353
|
|
|
630
|
-
|
|
631
|
-
|
|
354
|
+
checkAccessMany(
|
|
355
|
+
request: CheckAccessManyRequest,
|
|
356
|
+
): Promise<CheckAccessManyResponse> {
|
|
357
|
+
return Promise.resolve(this.handlers.checkAccessMany(request));
|
|
632
358
|
}
|
|
633
359
|
|
|
634
|
-
|
|
635
|
-
|
|
360
|
+
listRelationships(
|
|
361
|
+
request: ListRelationshipsRequest,
|
|
362
|
+
): Promise<ListRelationshipsResponse> {
|
|
363
|
+
return Promise.resolve(this.handlers.listRelationships(request));
|
|
636
364
|
}
|
|
637
365
|
|
|
638
|
-
|
|
639
|
-
|
|
366
|
+
addRelationship(
|
|
367
|
+
request: AddRelationshipRequest,
|
|
368
|
+
): Promise<AddRelationshipResponse> {
|
|
369
|
+
return Promise.resolve(this.handlers.addRelationship(request));
|
|
640
370
|
}
|
|
641
371
|
|
|
642
|
-
|
|
643
|
-
|
|
372
|
+
deleteRelationship(
|
|
373
|
+
request: DeleteRelationshipRequest,
|
|
374
|
+
): Promise<DeleteRelationshipResponse | void> {
|
|
375
|
+
return Promise.resolve(this.handlers.deleteRelationship(request));
|
|
644
376
|
}
|
|
645
377
|
|
|
646
|
-
|
|
647
|
-
|
|
378
|
+
setAuthorizationState(
|
|
379
|
+
request: SetAuthorizationStateRequest,
|
|
380
|
+
): Promise<SetAuthorizationStateResponse> {
|
|
381
|
+
return Promise.resolve(this.handlers.setAuthorizationState(request));
|
|
648
382
|
}
|
|
649
383
|
|
|
650
|
-
|
|
651
|
-
return
|
|
384
|
+
getActiveModelRef(): Promise<GetActiveModelRefResponse> {
|
|
385
|
+
return Promise.resolve(this.handlers.getActiveModelRef());
|
|
652
386
|
}
|
|
653
387
|
|
|
654
|
-
|
|
655
|
-
|
|
388
|
+
setActiveModel(
|
|
389
|
+
request: SetActiveModelRequest,
|
|
390
|
+
): Promise<SetActiveModelResponse> {
|
|
391
|
+
return Promise.resolve(this.handlers.setActiveModel(request));
|
|
656
392
|
}
|
|
657
393
|
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
async listModels(request: AuthorizationListModelsInput) {
|
|
663
|
-
return await this.options.listModels(request);
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
async writeModel(request: AuthorizationWriteModelInput) {
|
|
667
|
-
return await this.options.writeModel(request);
|
|
394
|
+
listActiveModelResourceTypes(
|
|
395
|
+
request: ListActiveModelResourceTypesRequest,
|
|
396
|
+
): Promise<ListActiveModelResourceTypesResponse> {
|
|
397
|
+
return Promise.resolve(this.handlers.listActiveModelResourceTypes(request));
|
|
668
398
|
}
|
|
669
399
|
}
|
|
670
400
|
|
|
@@ -683,1086 +413,631 @@ export function isAuthorizationProvider(
|
|
|
683
413
|
value !== null &&
|
|
684
414
|
"kind" in value &&
|
|
685
415
|
String((value as { kind?: unknown }).kind ?? "") === "authorization" &&
|
|
686
|
-
"
|
|
687
|
-
"
|
|
688
|
-
"
|
|
689
|
-
"
|
|
690
|
-
"
|
|
691
|
-
"
|
|
692
|
-
"
|
|
693
|
-
"
|
|
694
|
-
"
|
|
695
|
-
"listModels" in value &&
|
|
696
|
-
"writeModel" in value)
|
|
416
|
+
"checkAccess" in value &&
|
|
417
|
+
"checkAccessMany" in value &&
|
|
418
|
+
"listRelationships" in value &&
|
|
419
|
+
"addRelationship" in value &&
|
|
420
|
+
"deleteRelationship" in value &&
|
|
421
|
+
"setAuthorizationState" in value &&
|
|
422
|
+
"getActiveModelRef" in value &&
|
|
423
|
+
"setActiveModel" in value &&
|
|
424
|
+
"listActiveModelResourceTypes" in value)
|
|
697
425
|
);
|
|
698
426
|
}
|
|
699
427
|
|
|
700
428
|
export function createAuthorizationProviderService(
|
|
701
429
|
provider: AuthorizationProvider,
|
|
702
|
-
):
|
|
430
|
+
): Partial<ServiceImpl<typeof AuthorizationProviderService>> {
|
|
703
431
|
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,
|
|
432
|
+
async checkAccess(request) {
|
|
433
|
+
try {
|
|
434
|
+
return checkAccessResponseToProto(
|
|
435
|
+
await provider.checkAccess(checkAccessRequestFromProto(request)),
|
|
741
436
|
);
|
|
437
|
+
} catch (error) {
|
|
438
|
+
throw authorizationRuntimeError("check access", error);
|
|
742
439
|
}
|
|
743
|
-
return authorizationResourceSearchToProto(
|
|
744
|
-
requiredAuthorizationResponse(
|
|
745
|
-
await provider.effectiveSearchResources(authorizationSearchResourcesInputFromProto(request)),
|
|
746
|
-
"effective search resources",
|
|
747
|
-
),
|
|
748
|
-
);
|
|
749
440
|
},
|
|
750
|
-
async
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
Code.Unimplemented,
|
|
441
|
+
async checkAccessMany(request) {
|
|
442
|
+
try {
|
|
443
|
+
return checkAccessManyResponseToProto(
|
|
444
|
+
await provider.checkAccessMany(checkAccessManyRequestFromProto(request)),
|
|
755
445
|
);
|
|
446
|
+
} catch (error) {
|
|
447
|
+
throw authorizationRuntimeError("check access many", error);
|
|
756
448
|
}
|
|
757
|
-
return authorizationEffectiveSubjectSearchToProto(
|
|
758
|
-
requiredAuthorizationResponse(
|
|
759
|
-
await provider.effectiveSearchSubjects(authorizationEffectiveSearchSubjectsInputFromProto(request)),
|
|
760
|
-
"effective search subjects",
|
|
761
|
-
),
|
|
762
|
-
);
|
|
763
449
|
},
|
|
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,
|
|
450
|
+
async listRelationships(request) {
|
|
451
|
+
try {
|
|
452
|
+
return listRelationshipsResponseToProto(
|
|
453
|
+
await provider.listRelationships(listRelationshipsRequestFromProto(request)),
|
|
777
454
|
);
|
|
455
|
+
} catch (error) {
|
|
456
|
+
throw authorizationRuntimeError("list relationships", error);
|
|
778
457
|
}
|
|
779
|
-
return authorizationExpandToProto(
|
|
780
|
-
requiredAuthorizationResponse(
|
|
781
|
-
await provider.expand(authorizationExpandInputFromProto(request)),
|
|
782
|
-
"expand",
|
|
783
|
-
),
|
|
784
|
-
);
|
|
785
458
|
},
|
|
786
|
-
async
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
}
|
|
794
|
-
if (provider.supportsExpand()) {
|
|
795
|
-
pushCapability(metadata.capabilities, "expand");
|
|
459
|
+
async addRelationship(request) {
|
|
460
|
+
try {
|
|
461
|
+
return addRelationshipResponseToProto(
|
|
462
|
+
await provider.addRelationship(addRelationshipRequestFromProto(request)),
|
|
463
|
+
);
|
|
464
|
+
} catch (error) {
|
|
465
|
+
throw authorizationRuntimeError("add relationship", error);
|
|
796
466
|
}
|
|
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
467
|
},
|
|
807
|
-
async
|
|
808
|
-
|
|
809
|
-
|
|
468
|
+
async deleteRelationship(request) {
|
|
469
|
+
try {
|
|
470
|
+
await provider.deleteRelationship(deleteRelationshipRequestFromProto(request));
|
|
471
|
+
return create(DeleteRelationshipResponseSchema);
|
|
472
|
+
} catch (error) {
|
|
473
|
+
throw authorizationRuntimeError("delete relationship", error);
|
|
474
|
+
}
|
|
810
475
|
},
|
|
811
|
-
async
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
await provider.
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
476
|
+
async setAuthorizationState(request) {
|
|
477
|
+
try {
|
|
478
|
+
return setAuthorizationStateResponseToProto(
|
|
479
|
+
await provider.setAuthorizationState(
|
|
480
|
+
setAuthorizationStateRequestFromProto(request),
|
|
481
|
+
),
|
|
482
|
+
);
|
|
483
|
+
} catch (error) {
|
|
484
|
+
throw authorizationRuntimeError("set authorization state", error);
|
|
485
|
+
}
|
|
818
486
|
},
|
|
819
|
-
async
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
);
|
|
487
|
+
async getActiveModelRef() {
|
|
488
|
+
try {
|
|
489
|
+
return getActiveModelRefResponseToProto(await provider.getActiveModelRef());
|
|
490
|
+
} catch (error) {
|
|
491
|
+
throw authorizationRuntimeError("get active model ref", error);
|
|
492
|
+
}
|
|
826
493
|
},
|
|
827
|
-
async
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
await provider.
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
494
|
+
async setActiveModel(request) {
|
|
495
|
+
try {
|
|
496
|
+
return setActiveModelResponseToProto(
|
|
497
|
+
await provider.setActiveModel(setActiveModelRequestFromProto(request)),
|
|
498
|
+
);
|
|
499
|
+
} catch (error) {
|
|
500
|
+
throw authorizationRuntimeError("set active model", error);
|
|
501
|
+
}
|
|
834
502
|
},
|
|
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),
|
|
503
|
+
async listActiveModelResourceTypes(request) {
|
|
504
|
+
try {
|
|
505
|
+
return listActiveModelResourceTypesResponseToProto(
|
|
506
|
+
await provider.listActiveModelResourceTypes(
|
|
507
|
+
listActiveModelResourceTypesRequestFromProto(request),
|
|
508
|
+
),
|
|
509
|
+
);
|
|
510
|
+
} catch (error) {
|
|
511
|
+
throw authorizationRuntimeError("list active model resource types", error);
|
|
512
|
+
}
|
|
921
513
|
},
|
|
922
514
|
};
|
|
923
515
|
}
|
|
924
516
|
|
|
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 {
|
|
517
|
+
function checkAccessRequestFromProto(
|
|
518
|
+
value: ProtoCheckAccessRequest,
|
|
519
|
+
): CheckAccessRequest {
|
|
987
520
|
return {
|
|
988
|
-
subject:
|
|
989
|
-
action:
|
|
990
|
-
|
|
991
|
-
|
|
521
|
+
subject: subjectFromProto(value.subject),
|
|
522
|
+
action: value.action
|
|
523
|
+
? {
|
|
524
|
+
name: value.action.name,
|
|
525
|
+
properties: jsonObjectFromStruct(value.action.properties),
|
|
526
|
+
}
|
|
527
|
+
: undefined,
|
|
528
|
+
resource: resourceFromProto(value.resource),
|
|
992
529
|
};
|
|
993
530
|
}
|
|
994
531
|
|
|
995
|
-
function
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
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 {
|
|
1021
|
-
return {
|
|
1022
|
-
subject: authorizationSubjectFromProto(input.subject),
|
|
1023
|
-
action: authorizationActionFromProto(input.action),
|
|
1024
|
-
resourceType: input.resourceType,
|
|
1025
|
-
context: optionalObjectFromStruct(input.context),
|
|
1026
|
-
pageSize: input.pageSize,
|
|
1027
|
-
pageToken: input.pageToken,
|
|
1028
|
-
};
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
function authorizationSearchSubjectsInputToProto(input: AuthorizationSearchSubjectsInput) {
|
|
1032
|
-
return create(SubjectSearchRequestSchema, {
|
|
1033
|
-
resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
|
|
1034
|
-
action: input.action === undefined ? undefined : authorizationActionToProto(input.action),
|
|
1035
|
-
subjectType: input.subjectType ?? "",
|
|
1036
|
-
context: optionalStruct(input.context),
|
|
1037
|
-
pageSize: input.pageSize ?? 0,
|
|
1038
|
-
pageToken: input.pageToken ?? "",
|
|
532
|
+
function checkAccessResponseToProto(value: CheckAccessResponse | undefined) {
|
|
533
|
+
if (!value) {
|
|
534
|
+
throw new ConnectError(
|
|
535
|
+
"authorization provider returned nil response",
|
|
536
|
+
Code.Internal,
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
return create(CheckAccessResponseSchema, {
|
|
540
|
+
allowed: value.allowed ?? false,
|
|
541
|
+
modelId: value.modelId ?? "",
|
|
1039
542
|
});
|
|
1040
543
|
}
|
|
1041
544
|
|
|
1042
|
-
function
|
|
1043
|
-
|
|
1044
|
-
):
|
|
545
|
+
function checkAccessManyRequestFromProto(
|
|
546
|
+
value: ProtoCheckAccessManyRequest,
|
|
547
|
+
): CheckAccessManyRequest {
|
|
1045
548
|
return {
|
|
1046
|
-
|
|
1047
|
-
action: authorizationActionFromProto(input.action),
|
|
1048
|
-
subjectType: input.subjectType,
|
|
1049
|
-
context: optionalObjectFromStruct(input.context),
|
|
1050
|
-
pageSize: input.pageSize,
|
|
1051
|
-
pageToken: input.pageToken,
|
|
549
|
+
requests: value.requests.map(checkAccessRequestFromProto),
|
|
1052
550
|
};
|
|
1053
551
|
}
|
|
1054
552
|
|
|
1055
|
-
function
|
|
1056
|
-
|
|
553
|
+
function checkAccessManyResponseToProto(
|
|
554
|
+
value: CheckAccessManyResponse | undefined,
|
|
1057
555
|
) {
|
|
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),
|
|
556
|
+
if (!value) {
|
|
557
|
+
throw new ConnectError(
|
|
558
|
+
"authorization provider returned nil response",
|
|
559
|
+
Code.Internal,
|
|
560
|
+
);
|
|
561
|
+
}
|
|
562
|
+
return create(CheckAccessManyResponseSchema, {
|
|
563
|
+
decisions: (value.decisions ?? []).map(checkAccessResponseToProto),
|
|
1130
564
|
});
|
|
1131
565
|
}
|
|
1132
566
|
|
|
1133
|
-
function
|
|
1134
|
-
|
|
1135
|
-
):
|
|
567
|
+
function listRelationshipsRequestFromProto(
|
|
568
|
+
value: ProtoListRelationshipsRequest,
|
|
569
|
+
): ListRelationshipsRequest {
|
|
1136
570
|
return {
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
pageSize: input.pageSize,
|
|
1141
|
-
pageToken: input.pageToken,
|
|
1142
|
-
modelId: input.modelId,
|
|
1143
|
-
target: authorizationRelationshipTargetFromProto(input.target),
|
|
571
|
+
filter: relationshipFilterFromProto(value.filter),
|
|
572
|
+
pageSize: value.pageSize,
|
|
573
|
+
pageToken: value.pageToken,
|
|
1144
574
|
};
|
|
1145
575
|
}
|
|
1146
576
|
|
|
1147
|
-
function
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
577
|
+
function listRelationshipsRequestToProto(
|
|
578
|
+
value: ListRelationshipsRequest,
|
|
579
|
+
) {
|
|
580
|
+
return create(ListRelationshipsRequestSchema, {
|
|
581
|
+
filter: relationshipFilterToProto(value.filter),
|
|
582
|
+
pageSize: value.pageSize ?? 0,
|
|
583
|
+
pageToken: value.pageToken ?? "",
|
|
1152
584
|
});
|
|
1153
585
|
}
|
|
1154
586
|
|
|
1155
|
-
function
|
|
1156
|
-
|
|
1157
|
-
):
|
|
587
|
+
function listRelationshipsResponseFromProto(
|
|
588
|
+
value: ProtoListRelationshipsResponse,
|
|
589
|
+
): ListRelationshipsResponse {
|
|
1158
590
|
return {
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
modelId: input.modelId,
|
|
591
|
+
relationships: value.relationships.map(relationshipFromProtoRequired),
|
|
592
|
+
nextPageToken: value.nextPageToken,
|
|
1162
593
|
};
|
|
1163
594
|
}
|
|
1164
595
|
|
|
1165
|
-
function
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
596
|
+
function listRelationshipsResponseToProto(
|
|
597
|
+
value: ListRelationshipsResponse | undefined,
|
|
598
|
+
) {
|
|
599
|
+
if (!value) {
|
|
600
|
+
throw new ConnectError(
|
|
601
|
+
"authorization provider returned nil response",
|
|
602
|
+
Code.Internal,
|
|
603
|
+
);
|
|
604
|
+
}
|
|
605
|
+
return create(ListRelationshipsResponseSchema, {
|
|
606
|
+
relationships: (value.relationships ?? []).map(relationshipToProtoRequired),
|
|
607
|
+
nextPageToken: value.nextPageToken ?? "",
|
|
1169
608
|
});
|
|
1170
609
|
}
|
|
1171
610
|
|
|
1172
|
-
function
|
|
611
|
+
function addRelationshipRequestFromProto(
|
|
612
|
+
value: ProtoAddRelationshipRequest,
|
|
613
|
+
): AddRelationshipRequest {
|
|
1173
614
|
return {
|
|
1174
|
-
|
|
1175
|
-
pageToken: input.pageToken,
|
|
615
|
+
relationship: relationshipFromProto(value.relationship),
|
|
1176
616
|
};
|
|
1177
617
|
}
|
|
1178
618
|
|
|
1179
|
-
function
|
|
1180
|
-
|
|
1181
|
-
|
|
619
|
+
function addRelationshipResponseToProto(
|
|
620
|
+
value: AddRelationshipResponse | undefined,
|
|
621
|
+
) {
|
|
622
|
+
if (!value) {
|
|
623
|
+
throw new ConnectError(
|
|
624
|
+
"authorization provider returned nil response",
|
|
625
|
+
Code.Internal,
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
return create(AddRelationshipResponseSchema, {
|
|
629
|
+
relationship: value.relationship
|
|
630
|
+
? relationshipToProto(value.relationship)
|
|
631
|
+
: undefined,
|
|
1182
632
|
});
|
|
1183
633
|
}
|
|
1184
634
|
|
|
1185
|
-
function
|
|
635
|
+
function deleteRelationshipRequestFromProto(
|
|
636
|
+
value: ProtoDeleteRelationshipRequest,
|
|
637
|
+
): DeleteRelationshipRequest {
|
|
1186
638
|
return {
|
|
1187
|
-
|
|
639
|
+
relationshipTuple: relationshipTupleFromProto(value.relationshipTuple),
|
|
1188
640
|
};
|
|
1189
641
|
}
|
|
1190
642
|
|
|
1191
|
-
function
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
context: optionalStruct(input.context),
|
|
1195
|
-
modelId: input.modelId ?? "",
|
|
1196
|
-
});
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
function authorizationDecisionFromProto(input: ProtoAccessDecision): AuthorizationDecision {
|
|
643
|
+
function setAuthorizationStateRequestFromProto(
|
|
644
|
+
value: ProtoSetAuthorizationStateRequest,
|
|
645
|
+
): SetAuthorizationStateRequest {
|
|
1200
646
|
return {
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
modelId: input.modelId,
|
|
647
|
+
model: authorizationModelFromProto(value.model),
|
|
648
|
+
relationships: value.relationships.map(relationshipFromProtoRequired),
|
|
1204
649
|
};
|
|
1205
650
|
}
|
|
1206
651
|
|
|
1207
|
-
function
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
return
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
return create(ResourceSearchResponseSchema, {
|
|
1221
|
-
resources: input.resources?.map(authorizationResourceToProto) ?? [],
|
|
1222
|
-
nextPageToken: input.nextPageToken ?? "",
|
|
1223
|
-
modelId: input.modelId ?? "",
|
|
652
|
+
function setAuthorizationStateResponseToProto(
|
|
653
|
+
value: SetAuthorizationStateResponse | undefined,
|
|
654
|
+
) {
|
|
655
|
+
if (!value) {
|
|
656
|
+
throw new ConnectError(
|
|
657
|
+
"authorization provider returned nil response",
|
|
658
|
+
Code.Internal,
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
return create(SetAuthorizationStateResponseSchema, {
|
|
662
|
+
activeModel: value.activeModel
|
|
663
|
+
? authorizationModelRefToProto(value.activeModel)
|
|
664
|
+
: undefined,
|
|
1224
665
|
});
|
|
1225
666
|
}
|
|
1226
667
|
|
|
1227
|
-
function
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
return create(
|
|
1237
|
-
|
|
1238
|
-
nextPageToken: input.nextPageToken ?? "",
|
|
1239
|
-
modelId: input.modelId ?? "",
|
|
668
|
+
function getActiveModelRefResponseToProto(
|
|
669
|
+
value: GetActiveModelRefResponse | undefined,
|
|
670
|
+
) {
|
|
671
|
+
if (!value) {
|
|
672
|
+
throw new ConnectError(
|
|
673
|
+
"authorization provider returned nil response",
|
|
674
|
+
Code.Internal,
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
return create(GetActiveModelRefResponseSchema, {
|
|
678
|
+
model: value.model ? authorizationModelRefToProto(value.model) : undefined,
|
|
1240
679
|
});
|
|
1241
680
|
}
|
|
1242
681
|
|
|
1243
|
-
function
|
|
682
|
+
function setActiveModelRequestFromProto(
|
|
683
|
+
value: ProtoSetActiveModelRequest,
|
|
684
|
+
): SetActiveModelRequest {
|
|
1244
685
|
return {
|
|
1245
|
-
|
|
1246
|
-
nextPageToken: input.nextPageToken,
|
|
1247
|
-
modelId: input.modelId,
|
|
686
|
+
model: authorizationModelFromProto(value.model),
|
|
1248
687
|
};
|
|
1249
688
|
}
|
|
1250
689
|
|
|
1251
|
-
function
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
690
|
+
function setActiveModelResponseToProto(value: SetActiveModelResponse | undefined) {
|
|
691
|
+
if (!value) {
|
|
692
|
+
throw new ConnectError(
|
|
693
|
+
"authorization provider returned nil response",
|
|
694
|
+
Code.Internal,
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
return create(SetActiveModelResponseSchema, {
|
|
698
|
+
model: value.model ? authorizationModelRefToProto(value.model) : undefined,
|
|
1257
699
|
});
|
|
1258
700
|
}
|
|
1259
701
|
|
|
1260
|
-
function
|
|
1261
|
-
|
|
1262
|
-
):
|
|
702
|
+
function listActiveModelResourceTypesRequestFromProto(
|
|
703
|
+
value: ProtoListActiveModelResourceTypesRequest,
|
|
704
|
+
): ListActiveModelResourceTypesRequest {
|
|
1263
705
|
return {
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
706
|
+
filter: value.filter
|
|
707
|
+
? {
|
|
708
|
+
name: value.filter.name,
|
|
709
|
+
sourceLayer: value.filter.sourceLayer,
|
|
710
|
+
}
|
|
711
|
+
: undefined,
|
|
712
|
+
pageSize: value.pageSize,
|
|
713
|
+
pageToken: value.pageToken,
|
|
1268
714
|
};
|
|
1269
715
|
}
|
|
1270
716
|
|
|
1271
|
-
function
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
717
|
+
function listActiveModelResourceTypesResponseToProto(
|
|
718
|
+
value: ListActiveModelResourceTypesResponse | undefined,
|
|
719
|
+
) {
|
|
720
|
+
if (!value) {
|
|
721
|
+
throw new ConnectError(
|
|
722
|
+
"authorization provider returned nil response",
|
|
723
|
+
Code.Internal,
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
return create(ListActiveModelResourceTypesResponseSchema, {
|
|
727
|
+
resourceTypes: (value.resourceTypes ?? []).map(
|
|
728
|
+
authorizationModelResourceTypeToProto,
|
|
729
|
+
),
|
|
730
|
+
nextPageToken: value.nextPageToken ?? "",
|
|
731
|
+
modelId: value.modelId ?? "",
|
|
1276
732
|
});
|
|
1277
733
|
}
|
|
1278
734
|
|
|
1279
|
-
function
|
|
735
|
+
function subjectFromProto(value: ProtoCheckAccessRequest["subject"]): AuthorizationSubject | undefined {
|
|
736
|
+
if (!value) {
|
|
737
|
+
return undefined;
|
|
738
|
+
}
|
|
1280
739
|
return {
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
740
|
+
type: value.type,
|
|
741
|
+
id: value.id,
|
|
742
|
+
properties: jsonObjectFromStruct(value.properties),
|
|
1284
743
|
};
|
|
1285
744
|
}
|
|
1286
745
|
|
|
1287
|
-
function
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
746
|
+
function subjectToProto(value: AuthorizationSubject | undefined) {
|
|
747
|
+
if (!value) {
|
|
748
|
+
return undefined;
|
|
749
|
+
}
|
|
750
|
+
return create(SubjectSchema, {
|
|
751
|
+
type: value.type ?? "",
|
|
752
|
+
id: value.id ?? "",
|
|
753
|
+
properties: value.properties === undefined
|
|
754
|
+
? undefined
|
|
755
|
+
: structFromObject(value.properties),
|
|
1291
756
|
});
|
|
1292
757
|
}
|
|
1293
758
|
|
|
1294
|
-
function
|
|
759
|
+
function resourceFromProto(value: ProtoRelationshipFilter["resource"]): AuthorizationResource | undefined {
|
|
760
|
+
if (!value) {
|
|
761
|
+
return undefined;
|
|
762
|
+
}
|
|
1295
763
|
return {
|
|
1296
|
-
|
|
1297
|
-
|
|
764
|
+
type: value.type,
|
|
765
|
+
id: value.id,
|
|
766
|
+
properties: jsonObjectFromStruct(value.properties),
|
|
1298
767
|
};
|
|
1299
768
|
}
|
|
1300
769
|
|
|
1301
|
-
function
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
770
|
+
function resourceToProto(value: AuthorizationResource | undefined) {
|
|
771
|
+
if (!value) {
|
|
772
|
+
return undefined;
|
|
773
|
+
}
|
|
774
|
+
return create(ResourceSchema, {
|
|
775
|
+
type: value.type ?? "",
|
|
776
|
+
id: value.id ?? "",
|
|
777
|
+
properties: value.properties === undefined
|
|
778
|
+
? undefined
|
|
779
|
+
: structFromObject(value.properties),
|
|
1306
780
|
});
|
|
1307
781
|
}
|
|
1308
782
|
|
|
1309
|
-
function
|
|
1310
|
-
|
|
1311
|
-
):
|
|
783
|
+
function relationshipFilterFromProto(
|
|
784
|
+
value: ProtoRelationshipFilter | undefined,
|
|
785
|
+
): RelationshipFilter | undefined {
|
|
786
|
+
if (!value) {
|
|
787
|
+
return undefined;
|
|
788
|
+
}
|
|
1312
789
|
return {
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
790
|
+
target: relationshipTargetFromProto(value.target),
|
|
791
|
+
relation: value.relation,
|
|
792
|
+
resource: resourceFromProto(value.resource),
|
|
793
|
+
targetType: value.targetType,
|
|
794
|
+
targetEntityType: value.targetEntityType,
|
|
795
|
+
resourceType: value.resourceType,
|
|
796
|
+
sourceLayer: value.sourceLayer,
|
|
1316
797
|
};
|
|
1317
798
|
}
|
|
1318
799
|
|
|
1319
|
-
function
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
|
|
1325
|
-
function authorizationGetActiveModelFromProto(input: ProtoGetActiveModelResponse): AuthorizationGetActiveModel {
|
|
800
|
+
function relationshipFilterToProto(value: RelationshipFilter | undefined) {
|
|
801
|
+
if (!value) {
|
|
802
|
+
return undefined;
|
|
803
|
+
}
|
|
1326
804
|
return {
|
|
1327
|
-
|
|
805
|
+
target: relationshipTargetToProto(value.target),
|
|
806
|
+
relation: value.relation ?? "",
|
|
807
|
+
resource: resourceToProto(value.resource),
|
|
808
|
+
targetType: value.targetType ?? RelationshipTargetType.UNSPECIFIED,
|
|
809
|
+
targetEntityType: value.targetEntityType ?? "",
|
|
810
|
+
resourceType: value.resourceType ?? "",
|
|
811
|
+
sourceLayer: value.sourceLayer ?? SourceLayer.UNSPECIFIED,
|
|
1328
812
|
};
|
|
1329
813
|
}
|
|
1330
814
|
|
|
1331
|
-
function
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
|
-
function authorizationListModelsFromProto(input: ProtoListModelsResponse): AuthorizationListModels {
|
|
815
|
+
function relationshipFromProto(
|
|
816
|
+
value: ProtoRelationship | undefined,
|
|
817
|
+
): Relationship | undefined {
|
|
818
|
+
if (!value) {
|
|
819
|
+
return undefined;
|
|
820
|
+
}
|
|
1339
821
|
return {
|
|
1340
|
-
|
|
1341
|
-
|
|
822
|
+
tuple: relationshipTupleFromProto(value.tuple),
|
|
823
|
+
properties: jsonObjectFromStruct(value.properties),
|
|
824
|
+
sourceLayer: value.sourceLayer,
|
|
1342
825
|
};
|
|
1343
826
|
}
|
|
1344
827
|
|
|
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);
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
function authorizationSubjectFromProtoRequired(input: ProtoSubject): AuthorizationSubject {
|
|
1358
|
-
return {
|
|
1359
|
-
type: input.type,
|
|
1360
|
-
id: input.id,
|
|
1361
|
-
properties: optionalObjectFromStruct(input.properties),
|
|
1362
|
-
};
|
|
828
|
+
function relationshipFromProtoRequired(value: ProtoRelationship): Relationship {
|
|
829
|
+
return relationshipFromProto(value)!;
|
|
1363
830
|
}
|
|
1364
831
|
|
|
1365
|
-
function
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
832
|
+
function relationshipToProto(value: Relationship | undefined) {
|
|
833
|
+
if (!value) {
|
|
834
|
+
return undefined;
|
|
835
|
+
}
|
|
836
|
+
return create(RelationshipSchema, {
|
|
837
|
+
tuple: relationshipTupleToProto(value.tuple),
|
|
838
|
+
properties: value.properties === undefined
|
|
839
|
+
? undefined
|
|
840
|
+
: structFromObject(value.properties),
|
|
841
|
+
sourceLayer: value.sourceLayer ?? SourceLayer.UNSPECIFIED,
|
|
1370
842
|
});
|
|
1371
843
|
}
|
|
1372
844
|
|
|
1373
|
-
function
|
|
1374
|
-
return
|
|
845
|
+
function relationshipToProtoRequired(value: Relationship) {
|
|
846
|
+
return relationshipToProto(value)!;
|
|
1375
847
|
}
|
|
1376
848
|
|
|
1377
|
-
function
|
|
849
|
+
function relationshipTupleFromProto(
|
|
850
|
+
value: ProtoRelationshipTuple | undefined,
|
|
851
|
+
): RelationshipTuple | undefined {
|
|
852
|
+
if (!value) {
|
|
853
|
+
return undefined;
|
|
854
|
+
}
|
|
1378
855
|
return {
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
856
|
+
target: relationshipTargetFromProto(value.target),
|
|
857
|
+
relation: value.relation,
|
|
858
|
+
resource: resourceFromProto(value.resource),
|
|
1382
859
|
};
|
|
1383
860
|
}
|
|
1384
861
|
|
|
1385
|
-
function
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
862
|
+
function relationshipTupleToProto(value: RelationshipTuple | undefined) {
|
|
863
|
+
if (!value) {
|
|
864
|
+
return undefined;
|
|
865
|
+
}
|
|
866
|
+
return create(RelationshipTupleSchema, {
|
|
867
|
+
target: relationshipTargetToProto(value.target),
|
|
868
|
+
relation: value.relation ?? "",
|
|
869
|
+
resource: resourceToProto(value.resource),
|
|
1389
870
|
});
|
|
1390
871
|
}
|
|
1391
872
|
|
|
1392
|
-
function
|
|
1393
|
-
|
|
873
|
+
function relationshipTargetFromProto(
|
|
874
|
+
value: ProtoRelationshipTarget | undefined,
|
|
875
|
+
): RelationshipTarget | undefined {
|
|
876
|
+
if (!value) {
|
|
1394
877
|
return undefined;
|
|
1395
878
|
}
|
|
1396
|
-
|
|
1397
|
-
resource: authorizationResourceFromProto(input.resource),
|
|
1398
|
-
relation: input.relation,
|
|
1399
|
-
};
|
|
1400
|
-
}
|
|
1401
|
-
|
|
1402
|
-
function authorizationRelationshipTargetToProto(input: AuthorizationRelationshipTarget) {
|
|
1403
|
-
switch (input.kind.case) {
|
|
879
|
+
switch (value.kind.case) {
|
|
1404
880
|
case "subject":
|
|
1405
|
-
return
|
|
1406
|
-
kind: { case: "subject", value: authorizationSubjectToProto(input.kind.value) },
|
|
1407
|
-
});
|
|
881
|
+
return { subject: subjectFromProto(value.kind.value) };
|
|
1408
882
|
case "resource":
|
|
1409
|
-
return
|
|
1410
|
-
kind: { case: "resource", value: authorizationResourceToProto(input.kind.value) },
|
|
1411
|
-
});
|
|
883
|
+
return { resource: resourceFromProto(value.kind.value) };
|
|
1412
884
|
case "subjectSet":
|
|
1413
|
-
return
|
|
1414
|
-
kind: { case: "subjectSet", value: authorizationSubjectSetToProto(input.kind.value) },
|
|
1415
|
-
});
|
|
885
|
+
return { subjectSet: subjectSetFromProto(value.kind.value) };
|
|
1416
886
|
default:
|
|
1417
|
-
return
|
|
887
|
+
return {};
|
|
1418
888
|
}
|
|
1419
889
|
}
|
|
1420
890
|
|
|
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 } };
|
|
891
|
+
function relationshipTargetToProto(value: RelationshipTarget | undefined) {
|
|
892
|
+
if (!value) {
|
|
893
|
+
return undefined;
|
|
1439
894
|
}
|
|
895
|
+
if (value.subject) {
|
|
896
|
+
return create(RelationshipTargetSchema, {
|
|
897
|
+
kind: { case: "subject", value: subjectToProto(value.subject)! },
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
if (value.resource) {
|
|
901
|
+
return create(RelationshipTargetSchema, {
|
|
902
|
+
kind: { case: "resource", value: resourceToProto(value.resource)! },
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
if (value.subjectSet) {
|
|
906
|
+
return create(RelationshipTargetSchema, {
|
|
907
|
+
kind: { case: "subjectSet", value: subjectSetToProto(value.subjectSet) },
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
return create(RelationshipTargetSchema);
|
|
1440
911
|
}
|
|
1441
912
|
|
|
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 {
|
|
913
|
+
function subjectSetFromProto(value: ProtoSubjectSet | undefined): SubjectSet | undefined {
|
|
914
|
+
if (!value) {
|
|
915
|
+
return undefined;
|
|
916
|
+
}
|
|
1471
917
|
return {
|
|
1472
|
-
|
|
1473
|
-
relation:
|
|
1474
|
-
resource: authorizationResourceFromProto(input.resource),
|
|
1475
|
-
properties: optionalObjectFromStruct(input.properties),
|
|
1476
|
-
target: authorizationRelationshipTargetFromProto(input.target),
|
|
918
|
+
resource: resourceFromProto(value.resource),
|
|
919
|
+
relation: value.relation,
|
|
1477
920
|
};
|
|
1478
921
|
}
|
|
1479
922
|
|
|
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),
|
|
923
|
+
function subjectSetToProto(value: SubjectSet) {
|
|
924
|
+
return create(SubjectSetSchema, {
|
|
925
|
+
resource: resourceToProto(value.resource),
|
|
926
|
+
relation: value.relation ?? "",
|
|
1486
927
|
});
|
|
1487
928
|
}
|
|
1488
929
|
|
|
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) {
|
|
930
|
+
function authorizationModelFromProto(
|
|
931
|
+
value: ProtoAuthorizationModel | undefined,
|
|
932
|
+
): AuthorizationModel | undefined {
|
|
933
|
+
if (!value) {
|
|
1507
934
|
return undefined;
|
|
1508
935
|
}
|
|
1509
936
|
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) ?? [],
|
|
937
|
+
id: value.id,
|
|
938
|
+
version: value.version,
|
|
939
|
+
resourceTypes: value.resourceTypes.map(authorizationModelResourceTypeFromProto),
|
|
1520
940
|
};
|
|
1521
941
|
}
|
|
1522
942
|
|
|
1523
943
|
function authorizationModelResourceTypeFromProto(
|
|
1524
|
-
|
|
944
|
+
value: ProtoAuthorizationModelResourceType,
|
|
1525
945
|
): AuthorizationModelResourceType {
|
|
1526
946
|
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),
|
|
947
|
+
name: value.name,
|
|
948
|
+
relations: value.relations.map((relation) => ({
|
|
949
|
+
name: relation.name,
|
|
950
|
+
allowedTargets: relation.allowedTargets.map(modelAllowedTargetFromProto),
|
|
951
|
+
})),
|
|
952
|
+
actions: value.actions.map((action) => ({
|
|
953
|
+
name: action.name,
|
|
954
|
+
relations: [...action.relations],
|
|
955
|
+
})),
|
|
956
|
+
sourceLayer: value.sourceLayer,
|
|
957
|
+
defaultAccessPolicy: value.defaultAccessPolicy,
|
|
1550
958
|
};
|
|
1551
959
|
}
|
|
1552
960
|
|
|
1553
|
-
function
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
case "subjectSet":
|
|
1576
|
-
return {
|
|
1577
|
-
kind: {
|
|
1578
|
-
case: "subjectSet" as const,
|
|
1579
|
-
value: {
|
|
1580
|
-
resourceType: input.kind.value.resourceType,
|
|
1581
|
-
relation: input.kind.value.relation,
|
|
1582
|
-
},
|
|
1583
|
-
},
|
|
1584
|
-
};
|
|
1585
|
-
default:
|
|
1586
|
-
return { kind: { case: undefined } };
|
|
1587
|
-
}
|
|
961
|
+
function authorizationModelResourceTypeToProto(
|
|
962
|
+
value: AuthorizationModelResourceType,
|
|
963
|
+
) {
|
|
964
|
+
return create(AuthorizationModelResourceTypeSchema, {
|
|
965
|
+
name: value.name ?? "",
|
|
966
|
+
relations: (value.relations ?? []).map((relation) =>
|
|
967
|
+
create(ModelRelationSchema, {
|
|
968
|
+
name: relation.name ?? "",
|
|
969
|
+
allowedTargets: (relation.allowedTargets ?? []).map(
|
|
970
|
+
modelAllowedTargetToProto,
|
|
971
|
+
),
|
|
972
|
+
})
|
|
973
|
+
),
|
|
974
|
+
actions: (value.actions ?? []).map((action) =>
|
|
975
|
+
create(ModelActionSchema, {
|
|
976
|
+
name: action.name ?? "",
|
|
977
|
+
relations: [...(action.relations ?? [])],
|
|
978
|
+
})
|
|
979
|
+
),
|
|
980
|
+
sourceLayer: value.sourceLayer ?? SourceLayer.UNSPECIFIED,
|
|
981
|
+
defaultAccessPolicy: value.defaultAccessPolicy ?? DefaultAccessPolicy.DENY,
|
|
982
|
+
});
|
|
1588
983
|
}
|
|
1589
984
|
|
|
1590
|
-
function
|
|
1591
|
-
|
|
1592
|
-
):
|
|
1593
|
-
switch (
|
|
985
|
+
function modelAllowedTargetFromProto(
|
|
986
|
+
value: ProtoModelAllowedTarget,
|
|
987
|
+
): ModelAllowedTarget {
|
|
988
|
+
switch (value.kind.case) {
|
|
1594
989
|
case "subjectType":
|
|
1595
|
-
return {
|
|
990
|
+
return { subjectType: value.kind.value };
|
|
1596
991
|
case "resourceType":
|
|
1597
|
-
return {
|
|
1598
|
-
case "
|
|
992
|
+
return { resourceType: value.kind.value };
|
|
993
|
+
case "subjectSetType":
|
|
1599
994
|
return {
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
995
|
+
subjectSetType: {
|
|
996
|
+
resourceType: value.kind.value.resourceType,
|
|
997
|
+
relation: value.kind.value.relation,
|
|
1603
998
|
},
|
|
1604
999
|
};
|
|
1605
1000
|
default:
|
|
1606
|
-
return {
|
|
1001
|
+
return {};
|
|
1607
1002
|
}
|
|
1608
1003
|
}
|
|
1609
1004
|
|
|
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;
|
|
1005
|
+
function modelAllowedTargetToProto(value: ModelAllowedTarget) {
|
|
1006
|
+
if (value.subjectType !== undefined) {
|
|
1007
|
+
return create(ModelAllowedTargetSchema, {
|
|
1008
|
+
kind: { case: "subjectType", value: value.subjectType },
|
|
1009
|
+
});
|
|
1651
1010
|
}
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
): AuthorizationModelRewrite | undefined {
|
|
1657
|
-
if (input === undefined) {
|
|
1658
|
-
return undefined;
|
|
1011
|
+
if (value.resourceType !== undefined) {
|
|
1012
|
+
return create(ModelAllowedTargetSchema, {
|
|
1013
|
+
kind: { case: "resourceType", value: value.resourceType },
|
|
1014
|
+
});
|
|
1659
1015
|
}
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
return { kind: { case: undefined } };
|
|
1016
|
+
if (value.subjectSetType !== undefined) {
|
|
1017
|
+
return create(ModelAllowedTargetSchema, {
|
|
1018
|
+
kind: {
|
|
1019
|
+
case: "subjectSetType",
|
|
1020
|
+
value: create(SubjectSetTypeSchema, {
|
|
1021
|
+
resourceType: value.subjectSetType.resourceType ?? "",
|
|
1022
|
+
relation: value.subjectSetType.relation ?? "",
|
|
1023
|
+
}),
|
|
1024
|
+
},
|
|
1025
|
+
});
|
|
1671
1026
|
}
|
|
1027
|
+
return create(ModelAllowedTargetSchema);
|
|
1672
1028
|
}
|
|
1673
1029
|
|
|
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) {
|
|
1030
|
+
function authorizationModelRefToProto(value: AuthorizationModelRef) {
|
|
1696
1031
|
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 ?? "",
|
|
1032
|
+
id: value.id ?? "",
|
|
1033
|
+
version: value.version ?? "",
|
|
1034
|
+
createdAt: value.createdAt ? timestampFromDate(value.createdAt) : undefined,
|
|
1722
1035
|
});
|
|
1723
1036
|
}
|
|
1724
1037
|
|
|
1725
|
-
function
|
|
1726
|
-
|
|
1727
|
-
|
|
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) ?? [],
|
|
1740
|
-
});
|
|
1741
|
-
}
|
|
1742
|
-
|
|
1743
|
-
function authorizationExpandNodeFromProto(input?: ProtoExpandNode | undefined): AuthorizationExpandNode | undefined {
|
|
1744
|
-
if (input === undefined) {
|
|
1745
|
-
return undefined;
|
|
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);
|
|
1038
|
+
function authorizationRuntimeError(label: string, error: unknown): ConnectError {
|
|
1039
|
+
if (error instanceof ConnectError) {
|
|
1040
|
+
return error;
|
|
1767
1041
|
}
|
|
1042
|
+
return new ConnectError(`${label}: ${errorMessage(error)}`, Code.Unknown);
|
|
1768
1043
|
}
|