Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anthony/api key environment #54

Merged
merged 11 commits into from
Mar 4, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class ApiKeyController implements ApiKeyProto.ApiKeyServiceController {
description: request.description,
scopes: [ApiKeyProto.ApiScope.FULL],
project: request.project,
environment: request.environment,
},
});
if (!key) {
Expand Down
3 changes: 3 additions & 0 deletions packages/auth-service/test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ describe('Auth Service API Key Tests', () => {
email: '[email protected]',
password: 'password123',
description: 'Valid API key',
environment: 'dev',
},
(err, resp) => {
if (err) return reject(err);
Expand All @@ -171,6 +172,7 @@ describe('Auth Service API Key Tests', () => {
email: '[email protected]',
password: 'notthepassword123',
description: 'API key request with invalid password',
environment: 'dev',
},
(err, resp) => {
if (err) return reject(err);
Expand All @@ -190,6 +192,7 @@ describe('Auth Service API Key Tests', () => {
email: '[email protected]',
password: 'password123',
description: 'API key request with unpriviledged user',
environment: 'dev',
},
(err, resp) => {
if (err) return reject(err);
Expand Down
2 changes: 1 addition & 1 deletion packages/db-service/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ if [[ ${RUN_MODE} == *"test"* ]]; then
yarn prisma migrate reset --force
fi

yarn prisma migrate dev
yarn prisma migrate dev

yarn ${DB_COMMAND-start:dev}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:

- Added the required column `environment` to the `ApiKey` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE "ApiKey" ADD COLUMN "environment" TEXT NOT NULL;
3 changes: 2 additions & 1 deletion packages/db-service/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ generator client {
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
// url = "postgresql://johndoe:mysecretpassword@localhost:5432"
//url = "postgresql://johndoe:mysecretpassword@localhost:5432"
}

model User {
Expand All @@ -34,6 +34,7 @@ model ApiKey {
description String
projectId Int
project Project @relation(fields: [projectId], references: [id])
environment String
}

enum ApiScope {
Expand Down
1 change: 1 addition & 0 deletions packages/db-service/src/modules/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class ApiKeyDbController
name: request.apiKey.project.name,
},
},
environment: request.apiKey.environment,
};

const apiKey = this.apiKeyService.createApiKey(prepareCreateApiKey);
Expand Down
2 changes: 2 additions & 0 deletions packages/db-service/src/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class AuthService {
description: input.description,
scopes: [],
projectId: projectId,
environment: input.environment,
},
include: {
project: true,
Expand Down Expand Up @@ -101,6 +102,7 @@ const convertDbApiKeyToTs = (key: ApiKey): ApiKeyProto.ApiKey => {
scopes: mappedScopes,
description: key.description,
project: { id: key.projectId },
environment: key.environment,
};
return apiKey;
};
2 changes: 2 additions & 0 deletions packages/db-service/test/auth.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ describe('DB Service API Key Tests', () => {
description: 'Valid API key',
scopes: [0],
project: { name: 'apiKeyTestProject' },
environment: 'dev',
},
},
(err, res) => {
Expand All @@ -142,5 +143,6 @@ describe('DB Service API Key Tests', () => {
);
expect(response).toHaveProperty('description', 'Valid API key');
expect(response).toHaveProperty('project');
expect(response).toHaveProperty('environment', 'dev');
});
});
3 changes: 3 additions & 0 deletions packages/proto/definitions/api_key.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ message IssueApiKeyRequest {
string email = 2;
string password = 3;
string description = 4;
string environment = 5;
}

message CreateApiKeyParams {
Expand All @@ -35,13 +36,15 @@ message ApiKey {
string description = 3;
repeated ApiScope scopes = 4;
identifiers.ProjectIdentifier project = 5;
string environment = 6;
}

message ApiKeyNoId {
string hash = 1;
string description = 2;
repeated ApiScope scopes = 3;
identifiers.ProjectIdentifier project = 4;
string environment = 5;
}

message IssueApiKeyResponse {
Expand Down
3 changes: 3 additions & 0 deletions packages/proto/src/gen/api_key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface IssueApiKeyRequest {
email: string;
password: string;
description: string;
environment: string;
}

export interface CreateApiKeyParams {
Expand All @@ -27,13 +28,15 @@ export interface ApiKey {
description: string;
scopes: ApiScope[];
project: ProjectIdentifier | undefined;
environment: string;
}

export interface ApiKeyNoId {
hash: string;
description: string;
scopes: ApiScope[];
project: ProjectIdentifier | undefined;
environment: string;
}

export interface IssueApiKeyResponse {
Expand Down
Loading