parent
2274b476d6
commit
8079769881
@ -1,13 +1,15 @@
|
|||||||
|
import * as jwt from "jsonwebtoken";
|
||||||
import { Get, JsonController, OnUndefined, Param } from 'routing-controllers';
|
import { Get, JsonController, OnUndefined, Param } from 'routing-controllers';
|
||||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||||
import { getConnectionManager, Repository } from 'typeorm';
|
import { getConnectionManager, Repository } from 'typeorm';
|
||||||
|
import { config } from '../config';
|
||||||
|
import { InvalidCredentialsError } from '../errors/AuthError';
|
||||||
import { RunnerNotFoundError } from '../errors/RunnerErrors';
|
import { RunnerNotFoundError } from '../errors/RunnerErrors';
|
||||||
import { Runner } from '../models/entities/Runner';
|
import { Runner } from '../models/entities/Runner';
|
||||||
import { ResponseUser } from '../models/responses/ResponseUser';
|
import { ResponseUser } from '../models/responses/ResponseUser';
|
||||||
|
|
||||||
|
|
||||||
@JsonController('/runners')
|
@JsonController('/runners')
|
||||||
@OpenAPI({ security: [{ "AuthToken": [] }, { "RefreshTokenCookie": [] }] })
|
|
||||||
export class RunnerSelfServiceController {
|
export class RunnerSelfServiceController {
|
||||||
private runnerRepository: Repository<Runner>;
|
private runnerRepository: Repository<Runner>;
|
||||||
|
|
||||||
@ -23,12 +25,27 @@ export class RunnerSelfServiceController {
|
|||||||
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
||||||
@OnUndefined(RunnerNotFoundError)
|
@OnUndefined(RunnerNotFoundError)
|
||||||
@OpenAPI({ description: 'Lists all information about yourself. <br> Please provide your runner jwt for auth.' })
|
@OpenAPI({ description: 'Lists all information about yourself. <br> Please provide your runner jwt for auth.' })
|
||||||
async get(@Param('jwt') jwt: string) {
|
async get(@Param('jwt') token: string) {
|
||||||
//TODO:
|
//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…
x
Reference in New Issue
Block a user