Inline environment authorization errors

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex committed 2026-06-20 20:17:07 -07:00
1 parent 14159eaf68
commit ceb4fdc310
3 files changed
+11 -9

No files matched your search

+4
View File
@@ -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)),
);
+2 -7
View File
@@ -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) {
+5 -2
View File
@@ -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),