Skip to content

Commit 69a949f

Browse files
committed
support mtls
1 parent 7d69513 commit 69a949f

File tree

24 files changed

+230
-223
lines changed

24 files changed

+230
-223
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ on: [push]
22

33
name: CI
44
env:
5-
BINSTALL_VERSION: 1.1.2
6-
PROTOC_VERSION: 23.4
5+
BINSTALL_VERSION: 1.6.4
6+
PROTOC_VERSION: 26.1
77

88
jobs:
99
rust:

Cargo.lock

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

libplatune/management/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ sqlx = { version = "0.7", default-features = false, features = [
3838
"macros",
3939
"runtime-tokio",
4040
] }
41-
daemon-slayer = { git = "https://github.com/aschey/daemon-slayer", rev = "23659b534dbb46eb4d9b7d251037a9a67a6ce50e", features = [
41+
daemon-slayer = { git = "https://github.com/aschey/daemon-slayer", rev = "4a26cca8ae2599596dabdd626409c960b7423b8f", features = [
4242
"native-notification",
4343
] }
4444
strum = { version = "0.26", features = ["derive"] }

libplatune/management/src/path_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ where
3434
P: AsRef<Path>,
3535
{
3636
let file_path = file_path.as_ref();
37-
if file_path.starts_with("http://") {
37+
if file_path.starts_with("http://") || file_path.starts_with("https://") {
3838
// No need to normalize http urls
3939
return Ok(file_path.to_string_lossy().to_string());
4040
}

libplatune/management/src/search/search_engine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl SearchEngine {
211211
.await?;
212212

213213
for r in &mut search_entries {
214-
r.weights = weights.clone();
214+
r.weights.clone_from(&weights)
215215
}
216216
search_entries.extend(rest);
217217
let search_entries = search_entries

libplatune/management/src/sync/progress_stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl futures::Stream for ProgressStream {
3131
None => Poll::Ready(None),
3232
Some(progress_val_result) => match progress_val_result {
3333
Ok(progress_val) => {
34-
self.last_val = progress_val.clone();
34+
self.last_val.clone_from(&progress_val);
3535
Poll::Ready(progress_val)
3636
}
3737
Err(BroadcastStreamRecvError::Lagged(_)) => Poll::Ready(self.last_val.clone()),

libplatune/management/src/sync/tag.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl From<TaggedFile> for Tag {
3030
let artists = tag.get_strings(&ItemKey::TrackArtist).join("/");
3131
let mut album_artists = tag.get_strings(&ItemKey::AlbumArtist).join("/");
3232
if album_artists.is_empty() {
33-
album_artists = artists.clone();
33+
album_artists.clone_from(&artists);
3434
}
3535
Tag {
3636
title: tag.title().unwrap_or_default().into_owned(),

libplatune/player/src/http_stream_reader.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use std::num::NonZeroUsize;
2+
use std::{env, fs};
23

34
use decal::decoder::{ReadSeekSource, Source};
45
use eyre::{Context, Result};
5-
use stream_download::http::reqwest::Client;
6+
use stream_download::http::reqwest::{Client, Identity};
67
use stream_download::http::HttpStream;
78
use stream_download::source::SourceStream;
89
use stream_download::storage::adaptive::AdaptiveStorageProvider;
@@ -19,7 +20,18 @@ pub(crate) struct HttpStreamReader {
1920

2021
impl HttpStreamReader {
2122
pub async fn new(url: String) -> Result<Self> {
22-
let stream = HttpStream::<Client>::create(url.parse()?)
23+
let mut client_builder = Client::builder();
24+
if url.starts_with("https://") {
25+
let mtls_cert = env::var("PLATUNE_MTLS_CLIENT_CERT_PATH");
26+
let mtls_key = env::var("PLATUNE_MTLS_CLIENT_KEY_PATH");
27+
if let (Ok(mtls_cert), Ok(mtls_key)) = (mtls_cert, mtls_key) {
28+
let mut cert = fs::read(mtls_cert).wrap_err_with(|| "mtls cert path invalid")?;
29+
let mut key = fs::read(mtls_key).wrap_err_with(|| "mtls key path invalid")?;
30+
cert.append(&mut key);
31+
client_builder = client_builder.identity(Identity::from_pem(&cert)?);
32+
}
33+
}
34+
let stream = HttpStream::new(client_builder.build()?, url.parse()?)
2335
.await
2436
.wrap_err_with(|| "Error creating http stream")?;
2537
let file_len = stream.content_length();

libplatune/player/src/player.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Player {
6767
}
6868

6969
async fn get_source(&self, path: String) -> Option<Box<dyn Source>> {
70-
if path.starts_with("http") {
70+
if path.starts_with("http://") || path.starts_with("https://") {
7171
info!("Creating http stream");
7272

7373
HttpStreamReader::new(path.to_owned())

platune-cli/cmd/completer.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import (
1212
"github.com/nathan-fiscaletti/consolesize-go"
1313
)
1414

15-
const selectAll = "(Select All)"
16-
const back = "(Back)"
15+
const (
16+
selectAll = "(Select All)"
17+
back = "(Back)"
18+
)
1719

1820
var filePathCompleter = internal.FilePathCompleter{
1921
IgnoreCase: true,
@@ -73,7 +75,8 @@ func (state *cmdState) completerMode(in prompt.Document, returnChan chan []promp
7375
suggestions = append(suggestions, prompt.Suggest{
7476
Text: r.Song,
7577
CompletionText: completionText,
76-
Metadata: r})
78+
Metadata: r,
79+
})
7780
}
7881
returnChan <- prompt.FilterHasPrefix(suggestions, in.CurrentLineBeforeCursor(), true)
7982
}
@@ -93,7 +96,7 @@ func (state *cmdState) completerCmd(in prompt.Document, before []string, returnC
9396
}
9497
}
9598

96-
func (state *cmdState) updateMaxWidths(in prompt.Document, titleRatio float32) {
99+
func (state *cmdState) updateMaxWidths(titleRatio float32) {
97100
size, _ := consolesize.GetConsoleSize()
98101
base := float32(size)
99102

@@ -132,7 +135,7 @@ func (state *cmdState) completerDefault(in prompt.Document, returnChan chan []pr
132135
}
133136

134137
func (state *cmdState) dbCompleter(in prompt.Document, rest string, filePathSkipFirst bool, returnChan chan []prompt.Suggest) []prompt.Suggest {
135-
state.updateMaxWidths(in, 1./3)
138+
state.updateMaxWidths(1. / 3)
136139

137140
suggestions := filePathCompleter.Complete(in, filePathSkipFirst)
138141
if len(suggestions) > 0 && strings.ContainsAny(rest, "/\\") {

platune-cli/cmd/executor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ func (state *cmdState) executeEntryType(selected *prompt.Suggest, defaultMode mo
193193
state.currentQueue = append(state.currentQueue, lookupResult.Entries...)
194194
}
195195
} else {
196+
state.mode.Set(defaultMode)
196197
path := selected.Metadata.(string)
197198
state.currentQueue = append(state.currentQueue, &platune.LookupEntry{Path: path})
198199
}

0 commit comments

Comments
 (0)