Skip to content
This repository was archived by the owner on Jun 12, 2024. It is now read-only.

Commit 7848a13

Browse files
committed
Merge branch 'release/0.0.2'
2 parents fc00c9c + bc8b0c3 commit 7848a13

File tree

11 files changed

+303
-55
lines changed

11 files changed

+303
-55
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
## v0.0.1
1+
## v0.0.x
22

33
First public-ish version

Cargo.lock

Lines changed: 36 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
authors = ["Germano Rizzo <oss /AT/ germanorizzo /DOT/ it>"]
33
description = "A SQLite remote gateway - query SQLite via HTTP"
44
name = "sqliterg"
5-
version = "0.0.1"
5+
version = "0.0.2"
66
edition = "2021"
77
license = "Apache-2.0"
88

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ Obtaining an answer of:
6262
- "[**Macros**](https://germ.gitbook.io/sqliterg/documentation/macros)": lists of statements that can be executed at db creation, at startup, periodically or calling a web service;
6363
- **Backups**, rotated and also runnable at db creation, at startup, periodically or calling a web service;
6464
- [**CORS**](https://germ.gitbook.io/sqliterg/documentation/configuration-file#corsorigin) mode, configurable per-db;
65-
- Scheduled tasks can be: backup (with rotation), vacuum and/or a set of SQL statements;
6665
- [**Journal Mode**](https://sqlite.org/wal.html) (e.g. WAL) can be configured;
6766
- [**Embedded web server**](https://germ.gitbook.io/sqliterg/documentation/web-server) to directly serve web pages that can access sqliterg without CORS;- [Quite fast](features/performances.md)!
6867
- Comprehensive test suite (`make test`);

db_conf.template.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# If present, "auth" defines the authentication for this database
44
auth:
5+
# Optional, by default 401. The error HTTP code to be returned if auth fails.
6+
authErrorCode: 499
57
# Mandatory. Defines how the credentials are passed to the server.
68
# "INLINE" means that credentials are passed in the request
79
# "HTTP_BASIC" uses Basic Authentication (via the "Authorization: Basic" header)
@@ -55,6 +57,8 @@ macros:
5557
# Exposes an endpoint to execute the macro. A token-based for of authentication is mandatory.
5658
# Endpoint is http://<host>:<port>/<db_name>/macro/<macro_id>
5759
webService:
60+
# Optional, by default 401. The error HTTP code to be returned if auth fails.
61+
authErrorCode: 499
5862
# Either a plaintext "authToken" or a SHA-256 hashed "hashedAuthToken" must be supplied.
5963
authToken: ciao
6064
hashedAuthToken: b133a0c0e9bee3be20163d2ad31d6248db292aa6dcb1ee087a2aa50e0fc75ae2
@@ -76,6 +80,8 @@ backup:
7680
# Exposes an endpoint to execute the backup. A token-based for of authentication is mandatory.
7781
# Endpoint is http://<host>:<port>/<db_name>/backup
7882
webService:
83+
# Optional, by default 401. The error HTTP code to be returned if auth fails.
84+
authErrorCode: 499
7985
# Either a plaintext "authToken" or a SHA-256 hashed "hashedAuthToken" must be supplied.
8086
authToken: ciao
8187
hashedAuthToken: b133a0c0e9bee3be20163d2ad31d6248db292aa6dcb1ee087a2aa50e0fc75ae2

src/backup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub async fn handler(
8686
Some(bkp_ws) => {
8787
if !process_creds(&token.token, &bkp_ws.auth_token, &bkp_ws.hashed_auth_token) {
8888
return Response::new_err(
89-
401,
89+
bkp_ws.auth_error_code,
9090
-1,
9191
format!("In database '{}', backup: token mismatch", db_name),
9292
);

src/db_config.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,15 @@ pub enum AuthMode {
2626
Inline,
2727
}
2828

29+
fn default_401() -> u16 {
30+
401
31+
}
32+
2933
#[derive(Debug, Deserialize, Clone)]
3034
pub struct Auth {
35+
#[serde(rename = "authErrorCode")]
36+
#[serde(default = "default_401")]
37+
pub auth_error_code: u16,
3138
pub mode: AuthMode,
3239
#[serde(rename = "byQuery")]
3340
pub by_query: Option<String>,
@@ -51,6 +58,9 @@ pub struct StoredStatement {
5158

5259
#[derive(Debug, Deserialize, Clone)]
5360
pub struct ExecutionWebService {
61+
#[serde(rename = "authErrorCode")]
62+
#[serde(default = "default_401")]
63+
pub auth_error_code: u16,
5464
#[serde(rename = "authToken")]
5565
pub auth_token: Option<String>,
5666
#[serde(rename = "hashedAuthToken")]

src/logic.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,14 @@ fn process(
114114
dbconf: &DbConfig,
115115
auth_header: &Option<Authorization<Basic>>,
116116
) -> Result<Response> {
117-
if dbconf.auth.is_some()
118-
&& !process_auth(
119-
dbconf.auth.as_ref().unwrap(),
120-
conn,
121-
&http_req.credentials,
122-
auth_header,
123-
)
124-
{
125-
return Ok(Response::new_err(
126-
401,
127-
-1,
128-
"Authorization failed".to_string(),
129-
));
117+
if let Some(ac) = &dbconf.auth {
118+
if !process_auth(ac, conn, &http_req.credentials, auth_header) {
119+
return Ok(Response::new_err(
120+
ac.auth_error_code,
121+
-1,
122+
"Authorization failed".to_string(),
123+
));
124+
}
130125
}
131126

132127
let tx = conn.transaction()?;

src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub async fn handler(
158158
Some(mex_ws) => {
159159
if !process_creds(&token.token, &mex_ws.auth_token, &mex_ws.hashed_auth_token) {
160160
return Response::new_err(
161-
401,
161+
mex_ws.auth_error_code,
162162
-1,
163163
format!(
164164
"In database '{}', macro '{}': token mismatch",

0 commit comments

Comments
 (0)