parent
2274b476d6
commit
8079769881
|
@ -1,13 +1,15 @@
|
|||
import * as jwt from "jsonwebtoken";
|
||||
import { Get, JsonController, OnUndefined, Param } from 'routing-controllers';
|
||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||
import { getConnectionManager, Repository } from 'typeorm';
|
||||
import { config } from '../config';
|
||||
import { InvalidCredentialsError } from '../errors/AuthError';
|
||||
import { RunnerNotFoundError } from '../errors/RunnerErrors';
|
||||
import { Runner } from '../models/entities/Runner';
|
||||
import { ResponseUser } from '../models/responses/ResponseUser';
|
||||
|
||||
|
||||
@JsonController('/runners')
|
||||
@OpenAPI({ security: [{ "AuthToken": [] }, { "RefreshTokenCookie": [] }] })
|
||||
export class RunnerSelfServiceController {
|
||||
private runnerRepository: Repository<Runner>;
|
||||
|
||||
|
@ -23,12 +25,27 @@ export class RunnerSelfServiceController {
|
|||
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
||||
@OnUndefined(RunnerNotFoundError)
|
||||
@OpenAPI({ description: 'Lists all information about yourself. <br> Please provide your runner jwt for auth.' })
|
||||
async get(@Param('jwt') jwt: string) {
|
||||
//TODO:
|
||||
async get(@Param('jwt') token: string) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
public async getRunner(jwt: string): Promise<Runner> {
|
||||
return null;
|
||||
/**
|
||||
* Get's a runner by a provided jwt token.
|
||||
* @param token The runner jwt provided by the runner to identitfy themselves.
|
||||
*/
|
||||
private async getRunner(token: string): Promise<Runner> {
|
||||
let jwtPayload = undefined
|
||||
try {
|
||||
jwtPayload = <any>jwt.verify(token, config.jwt_secret);
|
||||
} catch (error) {
|
||||
throw new InvalidCredentialsError();
|
||||
}
|
||||
|
||||
console.log(jwtPayload);
|
||||
|
||||
const runner = await this.runnerRepository.findOne({ id: jwtPayload["id"] });
|
||||
if (!runner) { throw new RunnerNotFoundError() }
|
||||
return runner;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue