Projekt

Obecné

Profil

Stáhnout (14.9 KB) Statistiky
| Větev: | Tag: | Revize:
1
<!doctype html>
2
<html lang="en">
3
<head>
4
<meta charset="utf-8">
5
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
6
<meta name="generator" content="pdoc 0.10.0" />
7
<title>sql_app.api.usb_logs API documentation</title>
8
<meta name="description" content="" />
9
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
10
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
11
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
12
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
13
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
14
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
15
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
16
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
17
</head>
18
<body>
19
<main>
20
<article id="content">
21
<header>
22
<h1 class="title">Module <code>sql_app.api.usb_logs</code></h1>
23
</header>
24
<section id="section-intro">
25
<details class="source">
26
<summary>
27
<span>Expand source code</span>
28
</summary>
29
<pre><code class="python">from typing import List
30
from fastapi import Depends, FastAPI, HTTPException, APIRouter, Form
31
from datetime import datetime
32
from sqlalchemy.orm import Session
33
from sql_app import crud, models, schemas
34
from ..database import SessionLocal, engine
35

    
36
models.Base.metadata.create_all(bind=engine)
37

    
38
# prefix used for all endpoints in this file
39
usblogs = APIRouter(prefix=&#34;/api/v1&#34;)
40

    
41

    
42
# Dependency
43
def get_db():
44
    db = SessionLocal()
45
    try:
46
        yield db
47
    finally:
48
        db.close()
49

    
50

    
51
@usblogs.post(&#34;/usb-logs&#34;, response_model=schemas.USBLog)
52
def create_device_logs(log: schemas.USBTempBase, db: Session = Depends(get_db)):
53
    &#34;&#34;&#34;
54
    Endpoint called from keyman detecting client. Parses timestamp into datetime object.
55
    Finds if device and pc defined in message already exists and creates them if necessary.
56
    Saves log into database
57
    &#34;&#34;&#34;
58
    dev = crud.find_device(db, log.device)
59
    dat = datetime.strptime(log.timestamp, &#39;%Y-%m-%d %H:%M:%S&#39;)
60
    if dev is None:
61
        dev = crud.create_device(db=db, device=log.device)
62
    pc = crud.find_pc(db, log.username, log.hostname)
63
    if pc is None:
64
        pc = crud.create_pc(db=db, user=log.username, host=log.hostname)
65

    
66
    print(crud.create_device_logs(db=db, item=log, dev_id=dev.id, pc_id=pc.id, date=dat))
67

    
68

    
69
@usblogs.post(&#34;/ld-logs&#34;, response_model=schemas.LDLog)
70
def create_ld_logs(log: schemas.LDTempBase, db: Session = Depends(get_db)):
71
    &#34;&#34;&#34;
72
    Endpoint called from debugger detecting client. Parses timestamp into datetime object.
73
    Finds if head device and body device defined in message already exists and creates them if necessary.
74
    Saves log into database
75
    &#34;&#34;&#34;
76
    head_dev = crud.find_head_device(db, log.head_device)
77
    body_dev = crud.find_body_device(db, log.body_device)
78
    if head_dev is None:
79
        crud.create_head_device(db, log.head_device)
80
    if body_dev is None:
81
        crud.create_body_device(db, log.body_device)
82

    
83
    pc = crud.find_pc(db, log.username, log.hostname)
84
    if pc is None:
85
        pc = crud.create_pc(db=db, user=log.username, host=log.hostname)
86
    dat = datetime.strptime(log.timestamp, &#39;%Y-%m-%d %H:%M:%S&#39;)
87
    print(crud.create_ld_logs(db=db, item=log, head_id=head_dev.id, body_id=body_dev.id, pc_id=pc.id, date=dat))
88

    
89

    
90
@usblogs.get(&#34;/logs&#34;, response_model=List[schemas.USBLog])
91
def read_logs(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
92
    &#34;&#34;&#34;
93
    Returns all usb logs saved in database
94
    &#34;&#34;&#34;
95
    items = crud.get_logs(db, skip=skip, limit=limit)
96
    return items
97

    
98

    
99
@usblogs.get(&#34;/logs/{device_id}&#34;, response_model=List[schemas.USBLog])
100
def read_log(device_id: int, db: Session = Depends(get_db)):
101
    &#34;&#34;&#34;
102
    Returns one specific log by given id
103
    &#34;&#34;&#34;
104
    db_log = crud.get_log(db, device_id=device_id)
105
    if db_log is None:
106
        raise HTTPException(status_code=404, detail=&#34;Logs not found&#34;)
107
    return db_log</code></pre>
108
</details>
109
</section>
110
<section>
111
</section>
112
<section>
113
</section>
114
<section>
115
<h2 class="section-title" id="header-functions">Functions</h2>
116
<dl>
117
<dt id="sql_app.api.usb_logs.create_device_logs"><code class="name flex">
118
<span>def <span class="ident">create_device_logs</span></span>(<span>log: <a title="sql_app.schemas.USBTempBase" href="../schemas.html#sql_app.schemas.USBTempBase">USBTempBase</a>, db: sqlalchemy.orm.session.Session = Depends(get_db))</span>
119
</code></dt>
120
<dd>
121
<div class="desc"><p>Endpoint called from keyman detecting client. Parses timestamp into datetime object.
122
Finds if device and pc defined in message already exists and creates them if necessary.
123
Saves log into database</p></div>
124
<details class="source">
125
<summary>
126
<span>Expand source code</span>
127
</summary>
128
<pre><code class="python">@usblogs.post(&#34;/usb-logs&#34;, response_model=schemas.USBLog)
129
def create_device_logs(log: schemas.USBTempBase, db: Session = Depends(get_db)):
130
    &#34;&#34;&#34;
131
    Endpoint called from keyman detecting client. Parses timestamp into datetime object.
132
    Finds if device and pc defined in message already exists and creates them if necessary.
133
    Saves log into database
134
    &#34;&#34;&#34;
135
    dev = crud.find_device(db, log.device)
136
    dat = datetime.strptime(log.timestamp, &#39;%Y-%m-%d %H:%M:%S&#39;)
137
    if dev is None:
138
        dev = crud.create_device(db=db, device=log.device)
139
    pc = crud.find_pc(db, log.username, log.hostname)
140
    if pc is None:
141
        pc = crud.create_pc(db=db, user=log.username, host=log.hostname)
142

    
143
    print(crud.create_device_logs(db=db, item=log, dev_id=dev.id, pc_id=pc.id, date=dat))</code></pre>
144
</details>
145
</dd>
146
<dt id="sql_app.api.usb_logs.create_ld_logs"><code class="name flex">
147
<span>def <span class="ident">create_ld_logs</span></span>(<span>log: <a title="sql_app.schemas.LDTempBase" href="../schemas.html#sql_app.schemas.LDTempBase">LDTempBase</a>, db: sqlalchemy.orm.session.Session = Depends(get_db))</span>
148
</code></dt>
149
<dd>
150
<div class="desc"><p>Endpoint called from debugger detecting client. Parses timestamp into datetime object.
151
Finds if head device and body device defined in message already exists and creates them if necessary.
152
Saves log into database</p></div>
153
<details class="source">
154
<summary>
155
<span>Expand source code</span>
156
</summary>
157
<pre><code class="python">@usblogs.post(&#34;/ld-logs&#34;, response_model=schemas.LDLog)
158
def create_ld_logs(log: schemas.LDTempBase, db: Session = Depends(get_db)):
159
    &#34;&#34;&#34;
160
    Endpoint called from debugger detecting client. Parses timestamp into datetime object.
161
    Finds if head device and body device defined in message already exists and creates them if necessary.
162
    Saves log into database
163
    &#34;&#34;&#34;
164
    head_dev = crud.find_head_device(db, log.head_device)
165
    body_dev = crud.find_body_device(db, log.body_device)
166
    if head_dev is None:
167
        crud.create_head_device(db, log.head_device)
168
    if body_dev is None:
169
        crud.create_body_device(db, log.body_device)
170

    
171
    pc = crud.find_pc(db, log.username, log.hostname)
172
    if pc is None:
173
        pc = crud.create_pc(db=db, user=log.username, host=log.hostname)
174
    dat = datetime.strptime(log.timestamp, &#39;%Y-%m-%d %H:%M:%S&#39;)
175
    print(crud.create_ld_logs(db=db, item=log, head_id=head_dev.id, body_id=body_dev.id, pc_id=pc.id, date=dat))</code></pre>
176
</details>
177
</dd>
178
<dt id="sql_app.api.usb_logs.get_db"><code class="name flex">
179
<span>def <span class="ident">get_db</span></span>(<span>)</span>
180
</code></dt>
181
<dd>
182
<div class="desc"></div>
183
<details class="source">
184
<summary>
185
<span>Expand source code</span>
186
</summary>
187
<pre><code class="python">def get_db():
188
    db = SessionLocal()
189
    try:
190
        yield db
191
    finally:
192
        db.close()</code></pre>
193
</details>
194
</dd>
195
<dt id="sql_app.api.usb_logs.read_log"><code class="name flex">
196
<span>def <span class="ident">read_log</span></span>(<span>device_id: int, db: sqlalchemy.orm.session.Session = Depends(get_db))</span>
197
</code></dt>
198
<dd>
199
<div class="desc"><p>Returns one specific log by given id</p></div>
200
<details class="source">
201
<summary>
202
<span>Expand source code</span>
203
</summary>
204
<pre><code class="python">@usblogs.get(&#34;/logs/{device_id}&#34;, response_model=List[schemas.USBLog])
205
def read_log(device_id: int, db: Session = Depends(get_db)):
206
    &#34;&#34;&#34;
207
    Returns one specific log by given id
208
    &#34;&#34;&#34;
209
    db_log = crud.get_log(db, device_id=device_id)
210
    if db_log is None:
211
        raise HTTPException(status_code=404, detail=&#34;Logs not found&#34;)
212
    return db_log</code></pre>
213
</details>
214
</dd>
215
<dt id="sql_app.api.usb_logs.read_logs"><code class="name flex">
216
<span>def <span class="ident">read_logs</span></span>(<span>skip: int = 0, limit: int = 100, db: sqlalchemy.orm.session.Session = Depends(get_db))</span>
217
</code></dt>
218
<dd>
219
<div class="desc"><p>Returns all usb logs saved in database</p></div>
220
<details class="source">
221
<summary>
222
<span>Expand source code</span>
223
</summary>
224
<pre><code class="python">@usblogs.get(&#34;/logs&#34;, response_model=List[schemas.USBLog])
225
def read_logs(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
226
    &#34;&#34;&#34;
227
    Returns all usb logs saved in database
228
    &#34;&#34;&#34;
229
    items = crud.get_logs(db, skip=skip, limit=limit)
230
    return items</code></pre>
231
</details>
232
</dd>
233
</dl>
234
</section>
235
<section>
236
</section>
237
</article>
238
<nav id="sidebar">
239
<h1>Index</h1>
240
<div class="toc">
241
<ul></ul>
242
</div>
243
<ul id="index">
244
<li><h3>Super-module</h3>
245
<ul>
246
<li><code><a title="sql_app.api" href="index.html">sql_app.api</a></code></li>
247
</ul>
248
</li>
249
<li><h3><a href="#header-functions">Functions</a></h3>
250
<ul class="">
251
<li><code><a title="sql_app.api.usb_logs.create_device_logs" href="#sql_app.api.usb_logs.create_device_logs">create_device_logs</a></code></li>
252
<li><code><a title="sql_app.api.usb_logs.create_ld_logs" href="#sql_app.api.usb_logs.create_ld_logs">create_ld_logs</a></code></li>
253
<li><code><a title="sql_app.api.usb_logs.get_db" href="#sql_app.api.usb_logs.get_db">get_db</a></code></li>
254
<li><code><a title="sql_app.api.usb_logs.read_log" href="#sql_app.api.usb_logs.read_log">read_log</a></code></li>
255
<li><code><a title="sql_app.api.usb_logs.read_logs" href="#sql_app.api.usb_logs.read_logs">read_logs</a></code></li>
256
</ul>
257
</li>
258
</ul>
259
</nav>
260
</main>
261
<footer id="footer">
262
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p>
263
</footer>
264
</body>
265
</html>
(10-10/11)