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

Made a cli for frontend operation of Domainforge #40

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
196 changes: 196 additions & 0 deletions docker/named_pipe/nohup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
1000
Deleting... news.domains.mdgspace.org
rm: cannot remove '/etc/nginx/sites-available/news.domains.mdgspace.org.conf': No such file or directory
rm: cannot remove '/etc/nginx/sites-enabled/news.domains.mdgspace.org.conf': No such file or directory
Error response from daemon: No such container: news.domains.mdgspace.org
Error response from daemon: No such container: news.domains.mdgspace.org
Error response from daemon: No such image: news.domains.mdgspace.org:latest
1000
Creating subdomain news.domains.mdgspace.org which redirects to https://news.ycombinator.com/
Generating url.conf
url: https://news.ycombinator.com/
1000
Creating subdomain github.domains.mdgspace.org which redirects to https://github.com/
Generating url.conf
url: https://github.com/
1000
Deleting... github.domains.mdgspace.org
Error response from daemon: No such container: github.domains.mdgspace.org
Error response from daemon: No such container: github.domains.mdgspace.org
Error response from daemon: No such image: github.domains.mdgspace.org:latest
1000
Deleting... nik-55.domains.mdgspace.org
Error response from daemon: No such container: nik-55.domains.mdgspace.org
Error response from daemon: No such container: nik-55.domains.mdgspace.org
Error response from daemon: No such image: nik-55.domains.mdgspace.org:latest
1000
Creating subdomain kituuu.mdgspace.org.domains.mdgspace.org which redirects to https://your-personal-gallery.vercel.app/
Generating url.conf
url: https://your-personal-gallery.vercel.app/
1000
Deleting... kituuu.mdgspace.org.domains.mdgspace.org
Error response from daemon: No such container: kituuu.mdgspace.org.domains.mdgspace.org
Error response from daemon: No such container: kituuu.mdgspace.org.domains.mdgspace.org
Error response from daemon: No such image: kituuu.mdgspace.org.domains.mdgspace.org:latest
1000
Creating subdomain kituuu.domains.mdgspace.org which redirects to https://your-personal-gallery.vercel.app/
Generating url.conf
url: https://your-personal-gallery.vercel.app/
1000
Deleting... kituuu.domains.mdgspace.org
Error response from daemon: No such container: kituuu.domains.mdgspace.org
Error response from daemon: No such container: kituuu.domains.mdgspace.org
Error response from daemon: No such image: kituuu.domains.mdgspace.org:latest
1000
Creating subdomain google.domains.mdgspace.org which redirects to https://www.google.com/
Generating url.conf
url: https://www.google.com/
1000
Creating subdomain nano-test.domains.mdgspace.org which redirects to https://nanonish.github.io/
Generating url.conf
url: https://nanonish.github.io/
1000
Creating subdomain wiki.domains.mdgspace.org which redirects to https://www.wikipedia.org/
Generating url.conf
url: https://www.wikipedia.org/
1000
Creating subdomain wiki.domains.mdgspace.org which redirects to https://www.wikipedia.org/
Generating url.conf
url: https://www.wikipedia.org/
1000
Deleting... todo.domains.mdgspace.org
Error response from daemon: No such container: todo.domains.mdgspace.org
Error response from daemon: No such container: todo.domains.mdgspace.org
Error response from daemon: No such image: todo.domains.mdgspace.org:latest
1000
Deleting... hey.domains.mdgspace.org
Error response from daemon: No such container: hey.domains.mdgspace.org
Error response from daemon: No such container: hey.domains.mdgspace.org
Error response from daemon: No such image: hey.domains.mdgspace.org:latest
Available ports: 8067
Creating subdomain hey.domains.mdgspace.org
Cloning into 'hey.domains.mdgspace.org'...
#0 building with "default" instance using docker driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 225B done
#1 DONE 0.0s

#2 [internal] load metadata for docker.io/library/python:latest
#2 DONE 2.2s

#3 [internal] load .dockerignore
#3 transferring context: 2B done
#3 DONE 0.0s

#4 [1/5] FROM docker.io/library/python:latest@sha256:7859853e7607927aa1d1b1a5a2f9e580ac90c2b66feeb1b77da97fed03b1ccbe
#4 resolve docker.io/library/python:latest@sha256:7859853e7607927aa1d1b1a5a2f9e580ac90c2b66feeb1b77da97fed03b1ccbe 0.0s done
#4 sha256:2e66a70da0bec13fb3d492fcdef60fd8a5ef0a1a65c4e8a4909e26742852f0f2 0B / 64.15MB 0.1s
#4 sha256:7859853e7607927aa1d1b1a5a2f9e580ac90c2b66feeb1b77da97fed03b1ccbe 9.72kB / 9.72kB done
#4 sha256:ea2ebd905ab246ece277be25520ca0cfe82758b3d2b369e2fd69b374c1d6c7fa 5.86kB / 5.86kB done
#4 sha256:2e6afa3f266c11e8960349e7866203a9df478a50362bb5488c45fe39d99b2707 0B / 24.05MB 0.1s
#4 sha256:f6b1cea9aa1bba7fdf508248d1ab303a4cb11274997f39c9a0d6646f221379da 2.32kB / 2.32kB done
#4 sha256:8cd46d290033f265db57fd808ac81c444ec5a5b3f189c3d6d85043b647336913 0B / 49.56MB 0.1s
#4 CANCELED

#5 [internal] load build context
#5 transferring context: 16.77MB 0.2s done
#5 DONE 0.3s

#6 [2/5] WORKDIR /app
#6 CACHED

#7 [3/5] COPY requirements.txt .
#7 ERROR: failed to calculate checksum of ref 44b139ae-3131-4796-9538-e5f44b9c0408::pe7dzgi8kpgbwg9fr8gsw1js8: "/requirements.txt": not found
------
> [3/5] COPY requirements.txt .:
------
Dockerfile:3
--------------------
1 | FROM python:latest
2 | WORKDIR /app
3 | >>> COPY requirements.txt .
4 | RUN pip install --no-cache-dir -r requirements.txt
5 | COPY . .
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref 44b139ae-3131-4796-9538-e5f44b9c0408::pe7dzgi8kpgbwg9fr8gsw1js8: "/requirements.txt": not found
Unable to find image 'hey.domains.mdgspace.org:latest' locally
docker: Error response from daemon: pull access denied for hey.domains.mdgspace.org, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.
Available ports: 8067
Creating subdomain hy.domains.mdgspace.org
Cloning into 'hy.domains.mdgspace.org'...
#0 building with "default" instance using docker driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 225B done
#1 DONE 0.0s

#2 [internal] load metadata for docker.io/library/python:latest
#2 DONE 0.7s

#3 [internal] load .dockerignore
#3 transferring context: 2B done
#3 DONE 0.0s

#4 [1/5] FROM docker.io/library/python:latest@sha256:7859853e7607927aa1d1b1a5a2f9e580ac90c2b66feeb1b77da97fed03b1ccbe
#4 resolve docker.io/library/python:latest@sha256:7859853e7607927aa1d1b1a5a2f9e580ac90c2b66feeb1b77da97fed03b1ccbe 0.0s done
#4 sha256:f6b1cea9aa1bba7fdf508248d1ab303a4cb11274997f39c9a0d6646f221379da 2.32kB / 2.32kB done
#4 sha256:ea2ebd905ab246ece277be25520ca0cfe82758b3d2b369e2fd69b374c1d6c7fa 5.86kB / 5.86kB done
#4 sha256:2e6afa3f266c11e8960349e7866203a9df478a50362bb5488c45fe39d99b2707 0B / 24.05MB 0.1s
#4 sha256:7859853e7607927aa1d1b1a5a2f9e580ac90c2b66feeb1b77da97fed03b1ccbe 9.72kB / 9.72kB done
#4 sha256:8cd46d290033f265db57fd808ac81c444ec5a5b3f189c3d6d85043b647336913 0B / 49.56MB 0.1s
#4 sha256:2e66a70da0bec13fb3d492fcdef60fd8a5ef0a1a65c4e8a4909e26742852f0f2 0B / 64.15MB 0.1s
#4 ...

#5 [internal] load build context
#5 transferring context: 16.77MB 0.1s done
#5 DONE 0.2s

#6 [2/5] WORKDIR /app
#6 CACHED

#7 [3/5] COPY requirements.txt .
#7 ERROR: failed to calculate checksum of ref 44b139ae-3131-4796-9538-e5f44b9c0408::w1g4h9pt6iyidbf3u91xq1fq9: "/requirements.txt": not found
------
> [3/5] COPY requirements.txt .:
------
Dockerfile:3
--------------------
1 | FROM python:latest
2 | WORKDIR /app
3 | >>> COPY requirements.txt .
4 | RUN pip install --no-cache-dir -r requirements.txt
5 | COPY . .
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref 44b139ae-3131-4796-9538-e5f44b9c0408::w1g4h9pt6iyidbf3u91xq1fq9: "/requirements.txt": not found
Unable to find image 'hy.domains.mdgspace.org:latest' locally
docker: Error response from daemon: pull access denied for hy.domains.mdgspace.org, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.
1000
Creating subdomain alpha.domains.mdgspace.org which redirects to https://github.com
Generating url.conf
url: https://github.com
1000
Creating subdomain raj.domains.mdgspace.org which redirects to https://github.com/raj210809
Generating url.conf
url: https://github.com/raj210809
1000
Deleting... tola.domains.mdgspace.org
Error response from daemon: No such container: tola.domains.mdgspace.org
Error response from daemon: No such container: tola.domains.mdgspace.org
Error response from daemon: No such image: tola.domains.mdgspace.org:latest
1000
Creating subdomain toka.domains.mdgspace.org which redirects to https://github.com/amsorrytola
Generating url.conf
url: https://github.com/amsorrytola
1000
Deleting... toka.domains.mdgspace.org
Error response from daemon: No such container: toka.domains.mdgspace.org
Error response from daemon: No such container: toka.domains.mdgspace.org
Error response from daemon: No such image: toka.domains.mdgspace.org:latest
1000
Deleting... tola.domains.mdgspace.org
Error response from daemon: No such container: tola.domains.mdgspace.org
Error response from daemon: No such container: tola.domains.mdgspace.org
Error response from daemon: No such image: tola.domains.mdgspace.org:latest
5 changes: 4 additions & 1 deletion src/backend/auth/github.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Context, Sentry } from "../dependencies.ts";
import { checkUser } from "../db.ts";
import { checkJWT, createJWT } from "../utils/jwt.ts";
import { generateApiKey } from "../utils/apiKeyGen.ts";

async function githubAuth(ctx: Context, id: string, secret: string) {
await authenticateAndCreateJWT(ctx, id, secret, "github");
Expand Down Expand Up @@ -94,7 +95,9 @@ async function handleJwtAuthentication(ctx: Context) {
}
const jwt_token = document.jwt_token;
const provider = document.provider;
ctx.response.body = await checkJWT(provider, jwt_token);
const user = await checkJWT(provider, jwt_token);
const apiKey = generateApiKey(user)
ctx.response.body = {user , apiKey};
}

export { githubAuth, gitlabAuth, handleJwtAuthentication };
2 changes: 1 addition & 1 deletion src/backend/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { Session } from "https://deno.land/x/[email protected]/mod.ts";
import { create, verify } from "https://deno.land/x/[email protected]/mod.ts";
import { exec } from "https://deno.land/x/[email protected]/mod.ts";
import * as Sentry from "npm:@sentry/node";
import * as Sentry from 'https://deno.land/x/sentry/index.mjs';
import { oakCors } from "https://deno.land/x/[email protected]/mod.ts";

export {
Expand Down
3 changes: 0 additions & 3 deletions src/backend/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ const frontend: string = Deno.env.get("FRONTEND")!;

Sentry.init({
dsn: dsn,
integrations: [
new Sentry.Integrations.Http({ tracing: true }),
],
debug: true,
tracesSampleRate: 1.0,
});
Expand Down
35 changes: 35 additions & 0 deletions src/backend/utils/apiKeyGen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

function encodePayload(payload: string): string {
const encoded = btoa(payload); // Convert payload to Base64
return encoded;
}

function generateRandomString(length: number): string {
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = "";
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
}
return result;
}


function getSimpleDateString(): string {
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0');
const day = String(now.getDate()).padStart(2, '0');
return `${year}${month}${day}`;
}

function generateRandomPart(): string {
return generateRandomString(16);
}

export function generateApiKey(payload: string): string {
const datePart = getSimpleDateString();
const encodedPayload = encodePayload(payload);
const randomPart = generateRandomPart();
const apiKey = `${datePart}.${encodedPayload}.${randomPart}`;
return apiKey;
}
24 changes: 22 additions & 2 deletions src/backend/utils/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,30 @@ async function createJWT(provider: string, githubId: string) {
return token;
}

function decodePayload(encodedPayload: string): string {
const decoded = atob(encodedPayload);
return decoded;
}

function decodeApiKey(apiKey: string) {
const parts = apiKey.split(".");
if (parts.length !== 3) {
return "not verified";
}

const [datePart, encodedPayload, randomPart] = parts;
const decodedPayload = decodePayload(encodedPayload);
return decodedPayload
}

async function checkJWT(provider: string, token: string) {
try {
const payload = await verify(token, key);
return payload[`${provider}Id`]!;
if (provider === "CLI"){
return decodeApiKey(token)
} else {
const payload = await verify(token, key);
return payload[`${provider}Id`]!;
}
} catch (error) {
return "not verified";
}
Expand Down
15 changes: 15 additions & 0 deletions src/cli/features/authUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import axios from 'axios';
import chalk from 'chalk';

export async function verifyApiKey(apiKey: string, provider: string , backendUrl : string) {
try {
const response = await axios.post(`${backendUrl}/auth/jwt`, {
jwt_token: apiKey,
provider: provider,
});
return response.data;
} catch (error) {
console.error(chalk.red('Error verifying API key:'));
return 'not verified';
}
}
Loading