Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import WebhooksApi from "@octokit/webhooks";
import jwt from "jsonwebtoken";
import { Cluster } from "../../cluster";
import { Watch } from "../../watch"
import * as _ from "lodash";
interface ErrorResponse {
error: {};
}
/**
* gets hooks from github
*/
@Controller("api/v1/hooks/github")
export class GitHubHookAPI {
@Post("")
async githubHook(
@Res() response: Express.Response,
@Req() request: Express.Request,
@HeaderParams("x-github-event") eventType: string,
@BodyParams("") body?: { action?: string }, // we're just gonna cast this later
): Promise<{} | ErrorResponse> {
logger.info({msg: `received github hook for eventType ${eventType}`});
switch (eventType) {
case "pull_request": {
await this.handlePullRequest(request, body as WebhooksApi.WebhookPayloadPullRequest);
await this.createGithubCheck(request, body as WebhooksApi.WebhookPayloadPullRequest);
response.status(204);
return {};
}
} catch(err) {
await request.app.locals.stores.kotsAppStore.setUpdateDownloadStatus(String(err), "failed");
throw err;
} finally {
liveness.stop();
}
}
downloadUpdates(); // download asyncronously
response.status(200);
return {
updatesAvailable: updatesAvailable.length,
};
}
@Post("/license")
async kotsUploadLicense(
@BodyParams("") body: UploadLicenseBody,
@Req() request: Request,
@Res() response: Response,
@HeaderParams("Authorization") auth: string,
): Promise {
// Intentionally not processing registry settings here because empty strings don't
// necessarily mean existing info should be deleted.
const session: Session = await request.app.locals.stores.sessionStore.decode(auth);
if (!session || !session.userId) {
response.status(401);
return {};
}
// Check if bundle exists
const exists = await stores.troubleshootStore.supportBundleExists(supportBundleId);
if (!exists) {
response.send(404, "Bundle does not exist");
return;
}
const b = await stores.troubleshootStore.getSupportBundle(supportBundleId);
const analyzers = await stores.troubleshootStore.tryGetAnalyzersForKotsApp(b.watchId);
await performAnalysis(supportBundleId, analyzers, stores);
const analyzedBundle = await stores.troubleshootStore.getSupportBundle(supportBundleId);
response.send(200, analyzedBundle);
}
@Post("/:watchId/:supportBundleId")
public async bundleUploaded(
@Res() response: Response,
@Req() request: Request,
@BodyParams("") body: BundleUploadedBody,
@PathParams("watchId") watchId: string,
@PathParams("supportBundleId") supportBundleId: string,
): Promise {
const stores = request.app.locals.stores;
// Don't create support bundle if there is one with the same ID
const exists = await stores.troubleshootStore.supportBundleExists(supportBundleId);
if (exists) {
response.send(403);
return;
}
userId: string;
constructor(public userService: UserService) {}
@Post("/connect")
@Status(204)
async connect(@Session() session: Express.Session, @BodyParams("user") user: User) {
session.user = user;
}
@Get("/get-connected")
async getConnected(@Session("user") user: User): Promise {
return user;
}
@Post("/")
@Status(201)
async createUser(@BodyParams() userData: User) {
return await this.userService.create(userData);
}
@Get("/:user")
async testPerRequest(@PathParams("user") userId: string): Promise {
this.userService.user = userId;
this.userId = userId;
return new Promise((resolve, reject) => {
if (userId === "0") {
setTimeout(() => {
resolve({userId, idSrv: this.userService.user, idCtrl: this.userId});
}, 500);
}
import {BodyParams, Controller, Get, PathParams, Post, ProviderScope, Required, Scope, Session, Status} from "@tsed/common";
import {MultipartFile} from "../../../../../packages/multipartfiles/src";
import {Docs, Hidden} from "../../../../../packages/swagger/src";
import {IUser, User} from "../../models/User";
import {UserService} from "../../services/UserService";
@Controller("/user")
@Scope(ProviderScope.REQUEST)
@Hidden()
@Docs("hidden")
export class UserCtrl {
userId: string;
constructor(public userService: UserService) {}
@Post("/connect")
@Status(204)
async connect(@Session() session: Express.Session, @BodyParams("user") user: User) {
session.user = user;
}
@Get("/get-connected")
async getConnected(@Session("user") user: User): Promise {
return user;
}
@Post("/")
@Status(201)
async createUser(@BodyParams() userData: User) {
return await this.userService.create(userData);
}
} catch(err) {
await request.app.locals.stores.kotsAppStore.setUpdateDownloadStatus(String(err), "failed");
throw(err);
} finally {
liveness.stop();
}
}
processFile();
response.status(202);
}
@Post("/airgap/reset/:slug")
async kotsResetAirgapUpload(
@Req() request: Request,
@Res() response: Response,
@HeaderParams("Authorization") auth: string,
) {
const session: Session = await request.app.locals.stores.sessionStore.decode(auth);
if (!session || !session.userId) {
response.status(401);
return {};
}
const slug = request.params.slug;
const appId = await request.app.locals.stores.kotsAppStore.getIdFromSlug(slug);
await request.app.locals.stores.kotsAppStore.resetAirgapInstallInProgress(appId);
response.send(200);
return a.slug === slug;
});
if (!app) {
response.status(404);
return {};
}
response.header("Content-Type", "application/gzip");
response.status(200);
response.send(await app.getArchive(''+app.currentSequence));
}
@Post("/:slug/update-check")
async kotsUpdateCheck(
@Req() request: Request,
@Res() response: Response,
@PathParams("slug") slug: string,
@QueryParams("deploy") deploy: boolean,
) {
const apps = await request.app.locals.stores.kotsAppStore.listInstalledKotsApps();
const app = _.find(apps, (a: KotsApp) => {
return a.slug === slug;
});
if (!app) {
response.status(404);
return {};
}
import {BodyParams, Controller, Get, Post} from "@tsed/common";
import {ReturnsArray} from "@tsed/swagger";
import {User} from "../../entity/User";
import {UsersService} from "../../services/UsersService";
@Controller("/users")
export class UsersCtrl {
constructor(private usersService: UsersService) {
}
@Post("/")
create(@BodyParams() user: User): Promise {
return this.usersService.create(user);
}
@Get("/")
@ReturnsArray(User)
async getList(): Promise {
return this.usersService.find();
}
}
} from "@tsed/common";
interface SignupRequest {
email: string;
firstName: string;
lastName: string;
password: string;
}
interface ErrorResponse {
message: string;
}
@Controller("/api/v1/signup")
export class SignupAPI {
@Post("")
public async signup(
@Res() response: Express.Response,
@Req() request: Express.Request,
@BodyParams("") body: any,
): Promise {
if (body.email === "" || body.password === "") {
return {
message: `Email and password are both required`,
};
}
const user = await request.app.locals.stores.userStore.createPasswordUser(body.email, body.password, body.firstName, body.lastName);
const sessionToken = await request.app.locals.stores.sessionStore.createPasswordSession(user.id);
response.status(201);
return {text: "hello world with no authorisation"};
}
@Head("/post-auth-scoped")
@Post("/post-auth-scoped")
@OAuthBearer({scopes: ["tester"]})
postAuthScoped(@OAuthParams("scopes") scopes: string[], @BodyParams() message: any) {
$log.info({event: "postAuthScoped", scopes});
return {text: "Auth w Scopes: " + message.text};
}
@Head("/post-auth-not-scoped")
@Post("/post-auth-not-scoped")
@OAuthBearer()
postAuthNotScopedHead(@OAuthParams("scopes") scopes: string[], @BodyParams() message: any) {
$log.info({event: "postAuthNotScopedHead", scopes});
return {text: "Auth wout Scopes: " + message.text};
}
@OAuthHead()
@Post("/post-no-auth")
postNoAuth(@OAuthParams("scopes") scopes: string[], @BodyParams() message: any) {
$log.info({event: "postNoAuth", scopes});
return {text: "No Auth: " + message.text};
}