Skip to content

Commit

Permalink
🔧 refactor(release.yml): add rustls feature to aarch64-unknown-linux-…
Browse files Browse the repository at this point in the history
…gnu target

🔧 refactor(Cargo.toml): make native-tls optional and add rustls feature
🔧 refactor(auth.rs): conditionally use native_tls based on feature flag

This commit is to add support for rustls, a pure-Rust TLS implementation, as an alternative to native-tls. This allows for more flexibility in environments where native-tls may not be available or desirable.
  • Loading branch information
wenxuanjun committed May 11, 2024
1 parent e02680e commit a21b708
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 37 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
include:
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
features: rustls
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-pc-windows-msvc
Expand All @@ -44,6 +45,6 @@ jobs:
include: LICENSE,README.md,.env.example
leading-dir: true
target: ${{ matrix.target }}
tar: unix
zip: windows
features: ${{ matrix.features || '' }}
no-default-features: ${{ matrix.features != '' }}
token: ${{ secrets.GITHUB_TOKEN }}
48 changes: 24 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,30 @@ serde_json = "1.0.116"
thiserror = "1.0.59"
anyhow = "1.0.83"
url = "2.5.0"
native-tls = "0.2.11"
jpeg-decoder = "0.3.1"

[dependencies.ureq]
version = "2.9.7"
features = ["native-tls"]
default-features = false

[dependencies.image]
version = "0.25.1"
features = ["jpeg"]
default-features = false

[dependencies.native-tls]
version = "0.2.8"
optional = true

[dependencies.simple_logger]
version = "5.0.0"
features = ["colors", "timestamps"]

[dependencies.onnxruntime]
git = "https://github.com/VOICEVOX/onnxruntime-rs.git"
branch = "master"

[dependencies.ureq]
version = "2.9.7"
default-features = false

[features]
default = ["native-tls"]
native-tls = ["ureq/native-tls", "dep:native-tls"]
rustls = ["ureq/tls"]
15 changes: 10 additions & 5 deletions src/auth.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use anyhow::{anyhow, Result};
use get_if_addrs::{get_if_addrs, IfAddr};
use native_tls::TlsConnector;
use std::collections::HashMap;
use std::error::Error;
use std::net::Ipv4Addr;
use std::str::FromStr;
use std::sync::Arc;
use thiserror::Error;
use ureq::Agent;
use ureq::{Agent, AgentBuilder};
use url::Url;

#[cfg(feature = "native-tls")]
use native_tls::TlsConnector;

use crate::classifier::Classifier;

const NET_AUTH_BASEURL: &str = "https://net-auth.shanghaitech.edu.cn:19008";
Expand Down Expand Up @@ -41,9 +43,12 @@ pub struct Authenticator {

impl Authenticator {
pub fn new(user_id: String, password: String, classifier: Classifier) -> Result<Self> {
let client = ureq::AgentBuilder::new()
.tls_connector(Arc::new(TlsConnector::new()?))
.build();
let client = {
let builder = AgentBuilder::new();
#[cfg(feature = "native-tls")]
let builder = builder.tls_connector(Arc::new(TlsConnector::new()?));
builder.build()
};
let ip_addresses = Self::get_ip_addresses()?;

Ok(Self {
Expand Down

0 comments on commit a21b708

Please sign in to comment.