Inline environment authorization errors
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
14159eaf68
commit
ceb4fdc310
3 files changed
+11
-9
No files matched your search
@@ -3132,6 +3132,10 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
||||
assert.equal(rpcError._tag, "EnvironmentAuthorizationError");
|
||||
if (rpcError._tag === "EnvironmentAuthorizationError") {
|
||||
assert.equal(rpcError.requiredScope, "orchestration:read");
|
||||
assert.equal(
|
||||
rpcError.message,
|
||||
"The authenticated token is missing required scope: orchestration:read.",
|
||||
);
|
||||
}
|
||||
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
|
||||
);
|
||||
|
||||
@@ -463,25 +463,20 @@ const makeWsRpcLayer = (currentSession: EnvironmentAuth.AuthenticatedSession) =>
|
||||
const processDiagnostics = yield* ProcessDiagnostics.ProcessDiagnostics;
|
||||
const processResourceMonitor = yield* ProcessResourceMonitor.ProcessResourceMonitor;
|
||||
const relayClient = yield* RelayClient.RelayClient;
|
||||
const authorizationError = (requiredScope: AuthEnvironmentScope) =>
|
||||
new EnvironmentAuthorizationError({
|
||||
message: `The authenticated token is missing required scope: ${requiredScope}.`,
|
||||
requiredScope,
|
||||
});
|
||||
const authorizeEffect = <A, E, R>(
|
||||
requiredScope: AuthEnvironmentScope,
|
||||
effect: Effect.Effect<A, E, R>,
|
||||
): Effect.Effect<A, E | EnvironmentAuthorizationError, R> =>
|
||||
currentSession.scopes.includes(requiredScope)
|
||||
? effect
|
||||
: Effect.fail(authorizationError(requiredScope));
|
||||
: Effect.fail(new EnvironmentAuthorizationError({ requiredScope }));
|
||||
const authorizeStream = <A, E, R>(
|
||||
requiredScope: AuthEnvironmentScope,
|
||||
stream: Stream.Stream<A, E, R>,
|
||||
): Stream.Stream<A, E | EnvironmentAuthorizationError, R> =>
|
||||
currentSession.scopes.includes(requiredScope)
|
||||
? stream
|
||||
: Stream.fail(authorizationError(requiredScope));
|
||||
: Stream.fail(new EnvironmentAuthorizationError({ requiredScope }));
|
||||
const requiredScopeForMethod = (method: string): AuthEnvironmentScope => {
|
||||
const requiredScope = RPC_REQUIRED_SCOPE.get(method);
|
||||
if (requiredScope === undefined) {
|
||||
|
||||
@@ -300,10 +300,13 @@ export class AuthAccessStreamError extends Schema.TaggedErrorClass<AuthAccessStr
|
||||
export class EnvironmentAuthorizationError extends Schema.TaggedErrorClass<EnvironmentAuthorizationError>()(
|
||||
"EnvironmentAuthorizationError",
|
||||
{
|
||||
message: Schema.String,
|
||||
requiredScope: AuthEnvironmentScope,
|
||||
},
|
||||
) {}
|
||||
) {
|
||||
override get message(): string {
|
||||
return `The authenticated token is missing required scope: ${this.requiredScope}.`;
|
||||
}
|
||||
}
|
||||
|
||||
export const AuthAccessStreamClientUpsertedEvent = Schema.Struct({
|
||||
version: Schema.Literal(1),
|
||||
|
||||
Reference in new issue
Block a user