feat: 🚚 try to get containers api working
This commit is contained in:
parent
786524bd8a
commit
699185ee76
@ -1,7 +1,7 @@
|
|||||||
from os import getenv, path
|
from os import getenv, path
|
||||||
from typing import Annotated
|
from typing import Annotated, Any
|
||||||
|
|
||||||
from docker import from_env
|
from docker import errors, from_env
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from fastapi import Depends, FastAPI, HTTPException, Request
|
from fastapi import Depends, FastAPI, HTTPException, Request
|
||||||
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
||||||
@ -72,6 +72,25 @@ def get_containers(
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/api/container/{container_name}")
|
||||||
|
def get_container(
|
||||||
|
container_name: str,
|
||||||
|
credentials: Annotated[HTTPBasicCredentials, Depends(security)],
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
try:
|
||||||
|
container = client.containers.get(container_name)
|
||||||
|
except errors.APIError:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
||||||
|
|
||||||
|
if (
|
||||||
|
credentials.username != "admin"
|
||||||
|
and f"owner={credentials.username}" not in container.labels
|
||||||
|
):
|
||||||
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN)
|
||||||
|
|
||||||
|
return container.attrs
|
||||||
|
|
||||||
|
|
||||||
app.mount(
|
app.mount(
|
||||||
"/",
|
"/",
|
||||||
AuthStaticFiles(
|
AuthStaticFiles(
|
||||||
|
@ -2,7 +2,7 @@ import 'bulma/css/bulma.min.css'
|
|||||||
import 'font-awesome/css/font-awesome.min.css'
|
import 'font-awesome/css/font-awesome.min.css'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
import router from './router'
|
import router from './router.ts'
|
||||||
|
|
||||||
const app = createApp(App)
|
const app = createApp(App)
|
||||||
app.use(router)
|
app.use(router)
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
import { createRouter, createWebHistory } from 'vue-router'
|
import { createRouter, createWebHistory } from 'vue-router'
|
||||||
import Containers from '../views/Containers.vue'
|
import Container from './views/Container.vue'
|
||||||
|
import Home from './views/Home.vue'
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: createWebHistory(import.meta.env.BASE_URL),
|
history: createWebHistory(import.meta.env.BASE_URL),
|
||||||
routes: [
|
routes: [
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
name: 'home',
|
component: Home,
|
||||||
component: Containers,
|
},
|
||||||
|
{
|
||||||
|
path: '/container/:name',
|
||||||
|
component: Container,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
9
frontend/views/Container.vue
Normal file
9
frontend/views/Container.vue
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<template>
|
||||||
|
<oui>oui</oui>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
export default {
|
||||||
|
name: 'Container',
|
||||||
|
}
|
||||||
|
</script>
|
@ -3,7 +3,9 @@
|
|||||||
<Message v-if="error" type="danger">{{ error }}</Message>
|
<Message v-if="error" type="danger">{{ error }}</Message>
|
||||||
<ul v-if="!loading && !error">
|
<ul v-if="!loading && !error">
|
||||||
<li v-for="container in containers" :key="container">
|
<li v-for="container in containers" :key="container">
|
||||||
{{ container }}
|
<router-link :to="`/container/${container}`">
|
||||||
|
{{ container }}
|
||||||
|
</router-link>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</Loading>
|
</Loading>
|
||||||
@ -15,7 +17,7 @@ import Loading from '@/components/Loading.vue'
|
|||||||
import Message from '@/components/Message.vue'
|
import Message from '@/components/Message.vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Containers',
|
name: 'Home',
|
||||||
components: {
|
components: {
|
||||||
Loading,
|
Loading,
|
||||||
Message,
|
Message,
|
@ -7,6 +7,7 @@
|
|||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["frontend/*"]
|
"@/*": ["frontend/*"]
|
||||||
}
|
},
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user