Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
44 changes: 44 additions & 0 deletions client/public/img/icons/avatar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 14 additions & 7 deletions client/src/components/accounts/tokens.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{{ item.id }}
</template>
<template v-slot:[`item.user.username`]="{ item }">
<span>{{ item.user.username }}</span>
<span>{{ item.user?.username }}</span>
</template>
<template v-slot:[`item.expiresAt`]="{ item }">
<span v-if="item.expiresAt">{{ new Date(item.expiresAt).toLocaleString() }}</span>
Expand All @@ -47,7 +47,7 @@
</template>
</v-data-table>

<!-- Button to add a token -->
<!-- Button to add a token
<div style="display: flex; justify-content: flex-end; margin-top: 16px;">
<v-btn
fab
Expand All @@ -60,12 +60,12 @@
</v-btn>
</div>

<!-- Dialog for a new Token -->
<!-- Dialog for a new Token
<v-dialog v-model="createDialog" max-width="500px">
<v-card>
<v-card-title>Create Token</v-card-title>
<v-card-text>
<v-text-field v-model="newToken.token" label="Token Value"></v-text-field>
<v-text-field v-model="newToken.name" label="Name"></v-text-field>
<v-text-field
v-model="newToken.expiresAt"
label="Expires At (ISO)"
Expand All @@ -79,6 +79,7 @@
</v-card-actions>
</v-card>
</v-dialog>
-->
</v-container>
</template>

Expand All @@ -91,18 +92,24 @@ export default defineComponent({
setup() {
interface Token {
id?: string;
token: string;
token?: string;
name: string;
expiresAt?: string;
userId?: string;
user?: {
id: string;
username: string;
};
}
const tokens = ref<Token[]>([])
const loading = ref(false)
const search = ref('')
const createDialog = ref(false)
const newToken = ref<Token>({ token: '', expiresAt: '', userId: '' })
const newToken = ref<Token>({ token: '', name: '', expiresAt: '', userId: '' })

const headers = [
{ title: 'Token ID', value: 'token' },
{ title: 'Name', value: 'name' },
{ title: 'Owner', value: 'user.username' },
{ title: 'Expires At', value: 'expiresAt' },
{ title: 'Actions', value: 'actions', sortable: false, align: 'end' as const },
Expand All @@ -129,7 +136,7 @@ export default defineComponent({
}

const openCreateDialog = () => {
newToken.value = { token: '', expiresAt: '', userId: '' }
newToken.value = { token: '', name: '', expiresAt: '', userId: '' }
createDialog.value = true
}

Expand Down
50 changes: 50 additions & 0 deletions client/src/components/profile/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@
<v-col cols="12">
<v-card class="pa-4">
<h3 class="mb-4">API Tokens</h3>
<div style="display: flex; justify-content: flex-end; margin-bottom: 8px;">
<v-btn
fab
color="primary"
style="margin-right: 6px;"
@click="openCreateDialog"
>
<v-icon>mdi-plus</v-icon>
<span class="sr-only">Create Token</span>
</v-btn>
</div>
<v-table density="compact">
<thead>
<tr>
Expand Down Expand Up @@ -126,6 +137,24 @@
</tr>
</tbody>
</v-table>
<v-dialog v-model="createDialog" max-width="500px">
<v-card>
<v-card-title>Create Token</v-card-title>
<v-card-text>
<v-text-field v-model="newToken.name" label="Name"></v-text-field>
<v-text-field
v-model="newToken.expiresAt"
label="Expires At (ISO)"
type="datetime-local"
></v-text-field>
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn text @click="createDialog = false">Abort</v-btn>
<v-btn color="primary" @click="saveCreate">Create</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-card>
</v-col>
</v-row>
Expand Down Expand Up @@ -154,6 +183,8 @@ export default defineComponent({
const tokens = ref<any[]>([])
const editAvatarDialog = ref(false)
const avatarFile = ref<File | null>(null)
const createDialog = ref(false)
const newToken = ref<any>({ name: '', expiresAt: '' })

const loadProfile = async () => {
try {
Expand Down Expand Up @@ -197,6 +228,21 @@ export default defineComponent({
}
}

const openCreateDialog = () => {
newToken.value = { name: '', expiresAt: '' }
createDialog.value = true
}

const saveCreate = async () => {
try {
await axios.post('/api/tokens', newToken.value)
await loadTokens()
createDialog.value = false
} catch (e) {
// error handling
}
}

onMounted(() => {
loadProfile()
loadTokens()
Expand All @@ -210,6 +256,10 @@ export default defineComponent({
editAvatarDialog,
avatarFile,
saveAvatar,
createDialog,
newToken,
openCreateDialog,
saveCreate,
}
},
})
Expand Down
2 changes: 1 addition & 1 deletion client/src/layouts/default/NavDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
>
<template #prepend>
<v-avatar size="30">
<v-img :src="userAvatar || '/avatar.svg'" alt="User avatar" />
<v-img :src="userAvatar || '/img/icons/avatar.svg'" alt="User avatar" />
</v-avatar>
</template>
<template #title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ CREATE TABLE "Role" (
-- CreateTable
CREATE TABLE "Token" (
"id" TEXT NOT NULL PRIMARY KEY,
"name" TEXT,
"userId" TEXT NOT NULL,
"token" TEXT NOT NULL,
"expiresAt" DATETIME NOT NULL,
Expand All @@ -83,6 +84,69 @@ CREATE TABLE "Permission" (
"updatedAt" DATETIME NOT NULL
);

-- CreateTable
CREATE TABLE "Buildpack" (
"id" TEXT NOT NULL PRIMARY KEY,
"name" TEXT NOT NULL,
"language" TEXT NOT NULL,
"fetchId" TEXT NOT NULL,
"buildId" TEXT NOT NULL,
"runId" TEXT NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
CONSTRAINT "Buildpack_fetchId_fkey" FOREIGN KEY ("fetchId") REFERENCES "BuildpackPhase" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Buildpack_buildId_fkey" FOREIGN KEY ("buildId") REFERENCES "BuildpackPhase" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Buildpack_runId_fkey" FOREIGN KEY ("runId") REFERENCES "BuildpackPhase" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "BuildpackPhase" (
"id" TEXT NOT NULL PRIMARY KEY,
"repository" TEXT NOT NULL,
"tag" TEXT NOT NULL,
"command" TEXT,
"readOnlyAppStorage" BOOLEAN NOT NULL,
"securityContextId" TEXT NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
CONSTRAINT "BuildpackPhase_securityContextId_fkey" FOREIGN KEY ("securityContextId") REFERENCES "SecurityContext" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "SecurityContext" (
"id" TEXT NOT NULL PRIMARY KEY,
"runAsUser" INTEGER NOT NULL,
"runAsGroup" INTEGER NOT NULL,
"runAsNonRoot" BOOLEAN NOT NULL,
"readOnlyRootFilesystem" BOOLEAN NOT NULL,
"allowPrivilegeEscalation" BOOLEAN NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL
);

-- CreateTable
CREATE TABLE "Capability" (
"id" TEXT NOT NULL PRIMARY KEY,
"securityCtxId" TEXT NOT NULL,
CONSTRAINT "Capability_securityCtxId_fkey" FOREIGN KEY ("securityCtxId") REFERENCES "SecurityContext" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "CapabilityAdd" (
"id" TEXT NOT NULL PRIMARY KEY,
"value" TEXT NOT NULL,
"capabilityId" TEXT NOT NULL,
CONSTRAINT "CapabilityAdd_capabilityId_fkey" FOREIGN KEY ("capabilityId") REFERENCES "Capability" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "CapabilityDrop" (
"id" TEXT NOT NULL PRIMARY KEY,
"value" TEXT NOT NULL,
"capabilityId" TEXT NOT NULL,
CONSTRAINT "CapabilityDrop_capabilityId_fkey" FOREIGN KEY ("capabilityId") REFERENCES "Capability" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "_UserToUserGroup" (
"A" TEXT NOT NULL,
Expand Down
68 changes: 67 additions & 1 deletion server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ model Role {

model Token {
id String @id @default(cuid())
name String
name String?
userId String
user User @relation(fields: [userId], references: [id])
token String @unique
Expand Down Expand Up @@ -149,3 +149,69 @@ model Permission {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}


// CONFIGURATION
model Buildpack {
id String @id @default(cuid())
name String
language String
fetch BuildpackPhase @relation("fetch", fields: [fetchId], references: [id])
fetchId String
build BuildpackPhase @relation("build", fields: [buildId], references: [id])
buildId String
run BuildpackPhase @relation("run", fields: [runId], references: [id])
runId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

model BuildpackPhase {
id String @id @default(cuid())
repository String
tag String
command String?
readOnlyAppStorage Boolean
securityContext SecurityContext @relation("SecurityContextOnBuildpackPhase", fields: [securityContextId], references: [id])
securityContextId String
buildpacksFetch Buildpack[] @relation("fetch")
buildpacksBuild Buildpack[] @relation("build")
buildpacksRun Buildpack[] @relation("run")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

model SecurityContext {
id String @id @default(cuid())
runAsUser Int
runAsGroup Int
runAsNonRoot Boolean
readOnlyRootFilesystem Boolean
allowPrivilegeEscalation Boolean
capabilities Capability[]
buildpackPhases BuildpackPhase[] @relation("SecurityContextOnBuildpackPhase")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

model Capability {
id String @id @default(cuid())
add CapabilityAdd[]
drop CapabilityDrop[]
securityCtxId String
securityCtx SecurityContext @relation(fields: [securityCtxId], references: [id])
}

model CapabilityAdd {
id String @id @default(cuid())
value String
capability Capability @relation(fields: [capabilityId], references: [id])
capabilityId String
}

model CapabilityDrop {
id String @id @default(cuid())
value String
capability Capability @relation(fields: [capabilityId], references: [id])
capabilityId String
}
6 changes: 3 additions & 3 deletions server/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ export class AuthController {
@UseGuards(AuthGuard('github'))
@ApiBearerAuth('OAuth2')
async githubCallback(@Request() req: any, @Response() res: any) {
//console.log(req.user);
const token = await this.authService.loginOAuth2(req.user.username);
console.log(req.user);
const token = await this.authService.loginOAuth2(req.user);
res.cookie('kubero.JWT_TOKEN', token);
res.redirect('/');
}
Expand All @@ -138,7 +138,7 @@ export class AuthController {
@ApiBearerAuth('OAuth2')
async oauth2Callback(@Request() req: any, @Response() res: any) {
//console.log(req.user);
const token = await this.authService.loginOAuth2(req.user.username);
const token = await this.authService.loginOAuth2(req.user);
res.cookie('kubero.JWT_TOKEN', token);
res.redirect('/');
}
Expand Down
Loading
Loading