Skip to content

Commit

Permalink
feat: Auth docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tmthecoder committed Sep 9, 2024
1 parent 0a88fe5 commit bda3d3b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
29 changes: 29 additions & 0 deletions packages/api-gateway/src/models/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ApiProperty } from "@nestjs/swagger";
import { IsNotEmpty } from "class-validator";
import { ApiKeyProto, IdentifierProto} from 'juno-proto';

export class IssueApiKeyRequest {
@ApiProperty({ description: 'Issuing user email' })
@IsNotEmpty()
email: string;
@ApiProperty({ description: 'Issuing user password' })
@IsNotEmpty()
password: string;
@ApiProperty({ description: 'Optional description for key' })
description?: string | undefined;
@ApiProperty({ description: 'Environemnt this key should be tied to' })
@IsNotEmpty()
environment: string;

@IsNotEmpty()
project: IdentifierProto.ProjectIdentifier;
}

export class IssueApiKeyResponse {
@ApiProperty({ type: 'boolean' })
apiKey: ApiKeyProto.ApiKey;

constructor(res: ApiKeyProto.IssueApiKeyResponse) {
this.apiKey = res.apiKey;
}
}
24 changes: 21 additions & 3 deletions packages/api-gateway/src/modules/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import {
Post,
} from '@nestjs/common';
import { ClientGrpc } from '@nestjs/microservices';
import { ApiBearerAuth, ApiOperation, ApiCreatedResponse} from '@nestjs/swagger';
import { ApiKeyProto, JwtProto } from 'juno-proto';
import {
ApiKeyServiceClient,
IssueApiKeyRequest,
} from 'juno-proto/dist/gen/api_key';
import { JwtServiceClient } from 'juno-proto/dist/gen/jwt';
import { lastValueFrom } from 'rxjs';
import { IssueApiKeyRequest, IssueApiKeyResponse } from 'src/models/auth';

const { JWT_SERVICE_NAME } = JwtProto;
const { API_KEY_SERVICE_NAME } = ApiKeyProto;
Expand All @@ -35,14 +37,30 @@ export class AuthController implements OnModuleInit {
}

@Get()
@ApiBearerAuth()
getJWT() {
console.log('CALLED');
// this.apiKeyService.issueApiKey({}).subscribe();
return 'test';
}

@ApiOperation({
description: 'Thie endpoint issues a new API key for the project tied to the specified environment.'
})
@ApiCreatedResponse({
description: 'The API Key has been successfully created',
type: IssueApiKeyResponse,
})
@Post('/key')
createApiKey(@Body() issueApiKeyRequest: IssueApiKeyRequest) {
this.apiKeyService.issueApiKey(issueApiKeyRequest).subscribe();
async createApiKey(@Body() issueApiKeyRequest: IssueApiKeyRequest) {
const obs = this.apiKeyService.issueApiKey({
email: issueApiKeyRequest.email,
password: issueApiKeyRequest.password,
description: issueApiKeyRequest.description,
environment: issueApiKeyRequest.environment,
project: issueApiKeyRequest.project
});

return new IssueApiKeyResponse(await lastValueFrom(obs));
}
}

0 comments on commit bda3d3b

Please sign in to comment.