Skip to content

Commit 2992d16

Browse files
feat(cli): rudimentary support for http authentication (#165)
This MR implements the basic infrastructure for adding authentication to HTTP requests (to indices, project source, ...). It is an intermediate MR to #157, which intends to bring more complete support, both in terms of supported authentication schemes and configurability. This MR only implements: - Basic authentication scheme (username:password) - Configurable in the CLI, via environment variables The CLI looks for triplets of environment variables following the pattern `SYSAND_CRED_<X>`, `SYSAND_CRED_<X>_BASIC_USER`, `SYSAND_CRED_<X>_BASIC_PASS`. The `<X>` part is arbitrary, but every `<X>` has to appear either not at all, or for all three patterns. The first variable is a glob pattern to match URLs to allow authentication for, while the other two provide the actual credentials. Example ``` SYSAND_CRED_FOO='https://*.foo.com/**' SYSAND_CRED_FOO_BASIC_USER="bar" SYSAND_CRED_BASIC_PASS="baz" sysand <OP> ``` Would allow the use of `bar:baz` as credentials for urls such as `https://www.foo.com/a/b/c`, `https://index.foo.com/hey.kpar`, ... Credentials are only actually sent if an initial request generates a 4xx status. The strictly correct behaviour here would be to try sending credentials only in response to an explicit `401` with `WWW-Authenticate` header, but this would, I believe, be incompatible with using, for example, private GitLab/GitHub pages. --------- Signed-off-by: Tilo Wiklund <tilo.wiklund@sensmetry.com> Signed-off-by: Tilo Wiklund <75035892+tilowiklundSensmetry@users.noreply.github.com> Co-authored-by: Victor Linroth <victor.linroth@sensmetry.com>
1 parent 0d4f2ac commit 2992d16

33 files changed

Lines changed: 1490 additions & 190 deletions

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ the code as free software.
1616
The text accepted by signing the commit, is the widely adopted DCO, maintained
1717
by the Linux Foundation, the full text of which is reproduced below.
1818

19-
```plain
19+
```text
2020
Developer Certificate of Origin
2121
Version 1.1
2222

Cargo.lock

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

DEVELOPMENT.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ Rules to follow:
155155
Rules for markdown (Rust doc comments, `.md` files):
156156

157157
- always include a language specifier in fenced code blocks,
158-
use `plain` if no language is appropriate:
158+
use `text` if no language is appropriate:
159159

160160
````md
161-
```plain
161+
```text
162162
```
163163
````
164164

bindings/java/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ allow native modules as described in [JEP
3333
472](https://openjdk.org/jeps/472#Description). Currently, the warning looks as
3434
follows:
3535

36-
```plain
36+
```text
3737
WARNING: A restricted method in java.lang.System has been called
3838
WARNING: java.lang.System::load has been called by com.sensmetry.sysand.NativeLoader in an unnamed module (file:.../sysand-0.0.4-SNAPSHOT.jar)
3939
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module

bindings/java/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use jni::{
1010
objects::{JClass, JObject, JObjectArray, JString},
1111
};
1212
use sysand_core::{
13+
auth::Unauthenticated,
1314
build::KParBuildError,
1415
commands,
1516
env::local_directory::{self, LocalWriteError},
@@ -226,6 +227,8 @@ pub extern "system" fn Java_com_sensmetry_sysand_Sysand_info<'local>(
226227
Some(client),
227228
index_base_url.map(|x| vec![x]),
228229
runtime,
230+
// FIXME: Add Java support for authentication
231+
Arc::new(Unauthenticated {}),
229232
);
230233

231234
let results = match commands::info::do_info(&uri, &combined_resolver) {

bindings/js/package-lock.json

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/py/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use pyo3::{
1111
use semver::{Version, VersionReq};
1212
use sysand_core::{
1313
add::do_add,
14+
auth::Unauthenticated,
1415
build::{KParBuildError, do_build_kpar},
1516
commands::{
1617
env::{EnvError, do_env_local_dir},
@@ -156,6 +157,8 @@ fn do_info_py(
156157
Some(client),
157158
index_url,
158159
runtime,
160+
// FIXME: Add Python support for authentication
161+
Arc::new(Unauthenticated {}),
159162
);
160163

161164
match do_info(&uri, &combined_resolver) {

core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ futures = { version = "0.3.31", default-features = false, features = ["alloc", "
6060
tokio = { version = "1.48.0", default-features = false, features = ["rt", "io-util"] }
6161
bytes = { version = "1.11.0", default-features = false }
6262
toml_edit = { version = "0.23.9", features = ["serde"] }
63+
globset = { version = "0.4.18", default-features = false }
6364

6465
# Use native TLS only on Windows and Apple OSs
6566
[target.'cfg(any(target_os = "windows", target_vendor = "apple"))'.dependencies]

core/scripts/run_tests.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ PACKAGE_DIR=$(dirname "$SCRIPT_DIR")
88

99
cd "$PACKAGE_DIR"
1010

11-
cargo test --features filesystem,networking,alltests
12-
cargo test --features js
13-
cargo test --features python
11+
cargo test --features filesystem,networking,alltests $@
12+
cargo test --features js $@
13+
cargo test --features python $@

0 commit comments

Comments
 (0)