Skip to content
Merged
9,343 changes: 4,686 additions & 4,657 deletions connect-go/gen/proto/wg/cosmo/platform/v1/platform.pb.go

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions connect/src/wg/cosmo/platform/v1/platform_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8275,6 +8275,16 @@ export class APIKey_Group extends Message<APIKey_Group> {
* @generated from message wg.cosmo.platform.v1.GetAPIKeysRequest
*/
export class GetAPIKeysRequest extends Message<GetAPIKeysRequest> {
/**
* @generated from field: int32 limit = 1;
*/
limit = 0;

/**
* @generated from field: int32 offset = 2;
*/
offset = 0;

constructor(data?: PartialMessage<GetAPIKeysRequest>) {
super();
proto3.util.initPartial(data, this);
Expand All @@ -8283,6 +8293,8 @@ export class GetAPIKeysRequest extends Message<GetAPIKeysRequest> {
static readonly runtime: typeof proto3 = proto3;
static readonly typeName = "wg.cosmo.platform.v1.GetAPIKeysRequest";
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "limit", kind: "scalar", T: 5 /* ScalarType.INT32 */ },
{ no: 2, name: "offset", kind: "scalar", T: 5 /* ScalarType.INT32 */ },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): GetAPIKeysRequest {
Expand Down Expand Up @@ -8316,6 +8328,11 @@ export class GetAPIKeysResponse extends Message<GetAPIKeysResponse> {
*/
apiKeys: APIKey[] = [];

/**
* @generated from field: int32 count = 3;
*/
count = 0;

constructor(data?: PartialMessage<GetAPIKeysResponse>) {
super();
proto3.util.initPartial(data, this);
Expand All @@ -8326,6 +8343,7 @@ export class GetAPIKeysResponse extends Message<GetAPIKeysResponse> {
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "response", kind: "message", T: Response },
{ no: 2, name: "apiKeys", kind: "message", T: APIKey, repeated: true },
{ no: 3, name: "count", kind: "scalar", T: 5 /* ScalarType.INT32 */ },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): GetAPIKeysResponse {
Expand Down
15 changes: 15 additions & 0 deletions controlplane/src/core/bufservices/api-key/createAPIKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ export function createAPIKey(

const keyName = req.name.trim();

// Check if the organization has reached the limit of 200 API keys
const apiKeysCount = await apiKeyRepo.getAPIKeysCount({
organizationID: authContext.organizationId,
});

if (apiKeysCount >= 200) {
return {
response: {
code: EnumStatusCode.ERR,
details: 'Cannot create API key. Organization has reached the maximum limit of 200 API keys',
},
apiKey: '',
};
}
Comment thread
JivusAyrus marked this conversation as resolved.

const apiKeyModel = await apiKeyRepo.getAPIKeyByName({
organizationID: authContext.organizationId,
name: keyName,
Expand Down
18 changes: 16 additions & 2 deletions controlplane/src/core/bufservices/api-key/getAPIKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb
import { GetAPIKeysRequest, GetAPIKeysResponse } from '@wundergraph/cosmo-connect/dist/platform/v1/platform_pb';
import { ApiKeyRepository } from '../../repositories/ApiKeyRepository.js';
import type { RouterOptions } from '../../routes.js';
import { enrichLogger, getLogger, handleError } from '../../util.js';
import { clamp, enrichLogger, getLogger, handleError } from '../../util.js';

export function getAPIKeys(
opts: RouterOptions,
Expand All @@ -19,13 +19,27 @@ export function getAPIKeys(

const apiKeyRepo = new ApiKeyRepository(opts.db);

const apiKeys = await apiKeyRepo.getAPIKeys({ organizationID: authContext.organizationId });
// default to 10 if no limit is provided
req.limit = clamp(req.limit || 10, 1, 50);
// the max no of api keys is 200, but set the max to 1000 to be safe
req.offset = clamp(req.offset || 0, 0, 1000);

const apiKeys = await apiKeyRepo.getAPIKeys({
organizationID: authContext.organizationId,
limit: req.limit,
offset: req.offset,
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.

const count = await apiKeyRepo.getAPIKeysCount({
organizationID: authContext.organizationId,
});

return {
response: {
code: EnumStatusCode.OK,
},
apiKeys,
count,
};
});
}
21 changes: 4 additions & 17 deletions controlplane/src/core/bufservices/check/getCheckOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { OperationsRepository } from '../../repositories/OperationsRepository.js
import { SchemaCheckRepository } from '../../repositories/SchemaCheckRepository.js';
import { SubgraphRepository } from '../../repositories/SubgraphRepository.js';
import type { RouterOptions } from '../../routes.js';
import { enrichLogger, getLogger, handleError } from '../../util.js';
import { clamp, enrichLogger, getLogger, handleError } from '../../util.js';
import { UnauthorizedError } from '../../errors/errors.js';

export function getCheckOperations(
Expand Down Expand Up @@ -73,22 +73,9 @@ export function getCheckOperations(
};
}

// check that the limit is less than the max option provided in the ui
if (req.limit > 200) {
return {
response: {
code: EnumStatusCode.ERR,
details: 'Invalid limit',
},
operations: [],
trafficCheckDays: 0,
createdAt: '',
clientTrafficCheckSkipped: false,
totalOperationsCount: 0,
doAllOperationsHaveIgnoreAllOverride: false,
doAllOperationsHaveAllTheirChangesMarkedSafe: false,
};
}
// default to 10 if no limit is provided
req.limit = clamp(req.limit || 10, 1, 200);
req.offset = clamp(req.offset || 0, 0, 500_000);

const affectedOperations = await schemaCheckRepo.getAffectedOperationsByCheckId({
checkId: req.checkId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { DefaultNamespace } from '../../repositories/NamespaceRepository.js';
import { OrganizationRepository } from '../../repositories/OrganizationRepository.js';
import { SubgraphRepository } from '../../repositories/SubgraphRepository.js';
import type { RouterOptions } from '../../routes.js';
import { enrichLogger, getLogger, handleError, validateDateRanges } from '../../util.js';
import { clamp, enrichLogger, getLogger, handleError, validateDateRanges } from '../../util.js';
import { UnauthorizedError } from '../../errors/errors.js';

export function getChecksByFederatedGraphName(
Expand Down Expand Up @@ -70,17 +70,9 @@ export function getChecksByFederatedGraphName(
};
}

// check that the limit is less than the max option provided in the ui
if (req.limit > 50) {
return {
response: {
code: EnumStatusCode.ERR,
details: 'Invalid limit',
},
checks: [],
checksCountBasedOnDateRange: 0,
};
}
// default to 10 if no limit is provided
req.limit = clamp(req.limit || 10, 1, 50);
req.offset = clamp(req.offset || 0, 0, 500_000);

const includeSubgraphs = req.filters?.subgraphs?.filter((id) => isValidUuid(id)) ?? [];
const checksData = await subgraphRepo.checks({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { GraphCompositionRepository } from '../../repositories/GraphCompositionR
import { DefaultNamespace } from '../../repositories/NamespaceRepository.js';
import { OrganizationRepository } from '../../repositories/OrganizationRepository.js';
import type { RouterOptions } from '../../routes.js';
import { enrichLogger, getLogger, handleError, validateDateRanges } from '../../util.js';
import { clamp, enrichLogger, getLogger, handleError, validateDateRanges } from '../../util.js';
import { UnauthorizedError } from '../../errors/errors.js';

export function getCompositions(
Expand Down Expand Up @@ -71,17 +71,9 @@ export function getCompositions(
};
}

// check that the limit is less than the max option provided in the ui
if (req.limit > 50) {
return {
response: {
code: EnumStatusCode.ERR,
details: 'Invalid limit',
},
compositions: [],
count: 0,
};
}
// default to 10 if no limit is provided
req.limit = clamp(req.limit || 10, 1, 50);
req.offset = clamp(req.offset || 0, 0, 500_000);

const compositions = await graphCompositionRepository.getGraphCompositions({
fedGraphTargetId: federatedGraph.targetId,
Expand Down
16 changes: 4 additions & 12 deletions controlplane/src/core/bufservices/organization/getAuditLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { AuditLogRepository } from '../../repositories/AuditLogRepository.js';
import { OrganizationRepository } from '../../repositories/OrganizationRepository.js';
import type { RouterOptions } from '../../routes.js';
import { enrichLogger, getLogger, handleError, validateDateRanges } from '../../util.js';
import { clamp, enrichLogger, getLogger, handleError, validateDateRanges } from '../../util.js';
import { UnauthorizedError } from '../../errors/errors.js';

export function getAuditLogs(
Expand Down Expand Up @@ -54,17 +54,9 @@ export function getAuditLogs(
};
}

// check that the limit is less than the max option provided in the ui
if (req.limit > 50) {
return {
response: {
code: EnumStatusCode.ERR,
details: 'Invalid limit',
},
logs: [],
count: 0,
};
}
// default to 10 if no limit is provided
req.limit = clamp(req.limit || 10, 1, 50);
req.offset = clamp(req.offset || 0, 0, 500_000);

const auditLogs = await auditLogRepo.getAuditLogs({
organizationId: authContext.organizationId,
Expand Down
16 changes: 4 additions & 12 deletions controlplane/src/core/bufservices/proposal/getProposalChecks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { OrganizationRepository } from '../../repositories/OrganizationRepository.js';
import { ProposalRepository } from '../../repositories/ProposalRepository.js';
import type { RouterOptions } from '../../routes.js';
import { enrichLogger, getLogger, handleError, validateDateRanges } from '../../util.js';
import { clamp, enrichLogger, getLogger, handleError, validateDateRanges } from '../../util.js';
import { FederatedGraphRepository } from '../../repositories/FederatedGraphRepository.js';

export function getProposalChecks(
Expand Down Expand Up @@ -75,17 +75,9 @@ export function getProposalChecks(
};
}

// check that the limit is less than the max option provided in the ui
if (req.limit > 50) {
return {
response: {
code: EnumStatusCode.ERR,
details: 'Invalid limit',
},
checks: [],
totalChecksCount: 0,
};
}
// default to 10 if no limit is provided
req.limit = clamp(req.limit || 10, 1, 50);
req.offset = clamp(req.offset || 0, 0, 500_000);

// Get checks for the proposal
const { checks, checksCount } = await proposalRepo.getChecksByProposalId({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { FederatedGraphRepository } from '../../repositories/FederatedGraphRepository.js';
import { ProposalRepository } from '../../repositories/ProposalRepository.js';
import type { RouterOptions } from '../../routes.js';
import { enrichLogger, fromProposalOriginEnum, getLogger, handleError, validateDateRanges } from '../../util.js';
import { clamp, enrichLogger, fromProposalOriginEnum, getLogger, handleError, validateDateRanges } from '../../util.js';
import { OrganizationRepository } from '../../repositories/OrganizationRepository.js';
import { DefaultNamespace, NamespaceRepository } from '../../repositories/NamespaceRepository.js';
import { UnauthorizedError } from '../../errors/errors.js';
Expand Down Expand Up @@ -95,17 +95,9 @@ export function getProposalsByFederatedGraph(
};
}

// check that the limit is less than the max option provided in the ui
if (req.limit > 50) {
return {
response: {
code: EnumStatusCode.ERR,
details: 'Invalid limit',
},
proposals: [],
isProposalsEnabled: namespace.enableProposals,
};
}
// default to 10 if no limit is provided
req.limit = clamp(req.limit || 10, 1, 50);
req.offset = clamp(req.offset || 0, 0, 500_000);

const { proposals } = await proposalRepo.ByFederatedGraphId({
federatedGraphId: federatedGraph.id,
Expand Down
31 changes: 26 additions & 5 deletions controlplane/src/core/repositories/ApiKeyRepository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExpiresAt } from '@wundergraph/cosmo-connect/dist/platform/v1/platform_pb';
import { and, asc, eq } from 'drizzle-orm';
import { and, asc, count, eq } from 'drizzle-orm';
import { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
import * as schema from '../../db/schema.js';
import { apiKeyPermissions, apiKeyResources, apiKeys, users } from '../../db/schema.js';
Expand Down Expand Up @@ -110,8 +110,8 @@ export class ApiKeyRepository {
} as APIKeyDTO;
}

public async getAPIKeys(input: { organizationID: string }): Promise<APIKeyDTO[]> {
const keys = await this.db
public async getAPIKeys(input: { organizationID: string; limit: number; offset: number }): Promise<APIKeyDTO[]> {
const query = this.db
.select({
id: apiKeys.id,
name: apiKeys.name,
Expand All @@ -127,8 +127,17 @@ export class ApiKeyRepository {
.innerJoin(users, eq(users.id, apiKeys.userId))
.leftJoin(schema.organizationGroups, eq(schema.organizationGroups.id, apiKeys.groupId))
.where(eq(apiKeys.organizationId, input.organizationID))
.orderBy(asc(apiKeys.createdAt))
.execute();
.orderBy(asc(apiKeys.createdAt));

if (input.limit) {
query.limit(input.limit);
}

if (input.offset) {
query.offset(input.offset);
}
Comment thread
JivusAyrus marked this conversation as resolved.

const keys = await query.execute();

return keys.map(
({ groupId, groupName, ...key }) =>
Expand All @@ -145,6 +154,18 @@ export class ApiKeyRepository {
);
}

public async getAPIKeysCount(input: { organizationID: string }): Promise<number> {
const result = await this.db
.select({
count: count(),
})
.from(apiKeys)
.where(eq(apiKeys.organizationId, input.organizationID))
.execute();

return result[0]?.count ?? 0;
}

public updateAPIKeyGroup(input: { apiKeyId: string; groupId: string }) {
return this.db
.update(schema.apiKeys)
Expand Down
Loading
Loading