Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions cdn-server/cdn/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,15 @@ const jwtMiddleware = (secret: string | ((c: Context) => string)) => {

const organizationId = result.payload.organization_id;
const federatedGraphId = result.payload.federated_graph_id;
if (!organizationId || !federatedGraphId) {
if (!organizationId) {
return c.text('Unauthorized - Malformed token', 403);
}
c.set('authenticatedOrganizationId', organizationId as string);
c.set('authenticatedFederatedGraphId', federatedGraphId as string);

if (federatedGraphId) {
// Only assign the federated graph id when it was provided
c.set('authenticatedFederatedGraphId', federatedGraphId as string);
}

await next();
};
Expand Down Expand Up @@ -258,6 +262,40 @@ const cacheOperations = (storage: BlobStorage) => {
};
};

const subgraphChecks = (storage: BlobStorage) => {
return async (c: Context) => {
const organizationId = c.get('authenticatedOrganizationId');

if (organizationId !== c.req.param('organization_id')) {
return c.text('Bad Request', 400);
}

const uniqueId = c.req.param('uniqueid');
if (!uniqueId.endsWith('.json')) {
return c.notFound();
}

const key = `${organizationId}/subgraph_checks/${uniqueId}`;
let blobObject: BlobObject;

try {
blobObject = await storage.getObject({ context: c, key, cacheControl: 'no-cache' });
} catch (e: any) {
if (e instanceof BlobNotFoundError) {
return c.notFound();
}
throw e;
}

c.header('Content-Type', 'application/json; charset=UTF-8');
c.header('Cache-Control', 'no-cache, no-store, must-revalidate');

return stream(c, async (stream) => {
await stream.pipe(blobObject.stream);
});
};
};

// eslint-disable-next-line @typescript-eslint/ban-types
export const cdn = <E extends Env, S extends Schema = {}, BasePath extends string = '/'>(
hono: Hono<E, S, BasePath>,
Expand Down Expand Up @@ -286,4 +324,9 @@ export const cdn = <E extends Env, S extends Schema = {}, BasePath extends strin
hono
.use(cacheOperationsPath, jwtMiddleware(opts.authJwtSecret))
.get(cacheOperationsPath, cacheOperations(opts.blobStorage));

const subgraphChecksPath = '/:organization_id/subgraph_checks/:uniqueid{.+\\.json$}';
hono
.use(subgraphChecksPath, jwtMiddleware(opts.authJwtSecret))
.get(subgraphChecksPath, subgraphChecks(opts.blobStorage));
};
8 changes: 7 additions & 1 deletion cli/src/handle-check-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export const handleCheckResult = (resp: CheckSubgraphSchemaResponse) => {
resp.lintErrors.length === 0 &&
resp.lintWarnings.length === 0 &&
resp.graphPruneErrors.length === 0 &&
resp.graphPruneWarnings.length === 0
resp.graphPruneWarnings.length === 0 &&
(resp.isCheckExtensionSkipped ?? true)
) {
console.log(
`\nDetected no changes.\nDetected no lint issues.\nDetected no graph pruning issues.\n\n${studioCheckDestination}\n`,
Expand Down Expand Up @@ -243,6 +244,11 @@ export const handleCheckResult = (resp: CheckSubgraphSchemaResponse) => {
success = false;
}

if (resp.checkExtensionErrorMessage) {
success = false;
finalStatement += `\n${logSymbols.error} Subgraph extension check failed with message: ${resp.checkExtensionErrorMessage}`;
}

if (success) {
console.log(
'\n' +
Expand Down
13,488 changes: 7,019 additions & 6,469 deletions connect-go/gen/proto/wg/cosmo/platform/v1/platform.pb.go

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading