adding callback for reusable credentials (#983)

This allows more control over how the credentials are saved to the cache
This commit is contained in:
Louis Seubert 2022-05-20 12:53:44 +02:00 committed by GitHub
parent 1efda79787
commit 6c2491b9a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 17 additions and 8 deletions

View file

@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [playback] `Sink`: `write()` now receives ownership of the packet (breaking).
- [playback] `pipe`: create file if it doesn't already exist
- [playback] More robust dynamic limiter for very wide dynamic range (breaking)
- [core] `Session`: `connect()` now returns the long-term credentials.
- [core] `Session`: `connect()` now accespt a flag if the credentails should be stored via the cache.
- [build] The MSRV is now 1.53.
### Added

View file

@ -66,7 +66,8 @@ impl Session {
config: SessionConfig,
credentials: Credentials,
cache: Option<Cache>,
) -> Result<Session, SessionError> {
store_credentials: bool,
) -> Result<(Session, Credentials), SessionError> {
let ap = apresolve(config.proxy.as_ref(), config.ap_port).await;
info!("Connecting to AP \"{}\"", ap);
@ -76,18 +77,20 @@ impl Session {
connection::authenticate(&mut conn, credentials, &config.device_id).await?;
info!("Authenticated as \"{}\" !", reusable_credentials.username);
if let Some(cache) = &cache {
cache.save_credentials(&reusable_credentials);
if store_credentials {
cache.save_credentials(&reusable_credentials);
}
}
let session = Session::create(
conn,
config,
cache,
reusable_credentials.username,
reusable_credentials.username.clone(),
tokio::runtime::Handle::current(),
);
Ok(session)
Ok((session, reusable_credentials))
}
fn create(

View file

@ -13,6 +13,7 @@ async fn test_connection() {
SessionConfig::default(),
Credentials::with_password("test", "test"),
None,
false,
)
.await;

View file

@ -20,7 +20,7 @@ async fn main() {
println!("Connecting..");
let credentials = Credentials::with_password(&args[1], &args[2]);
let session = Session::connect(session_config, credentials, None)
let (session, _) = Session::connect(session_config, credentials, None, false)
.await
.unwrap();

View file

@ -27,7 +27,7 @@ async fn main() {
let backend = audio_backend::find(None).unwrap();
println!("Connecting ..");
let session = Session::connect(session_config, credentials, None)
let (session, _) = Session::connect(session_config, credentials, None, false)
.await
.unwrap();

View file

@ -27,7 +27,7 @@ async fn main() {
process::exit(1);
});
let session = Session::connect(session_config, credentials, None)
let (session, _) = Session::connect(session_config, credentials, None, false)
.await
.unwrap();

View file

@ -1599,6 +1599,7 @@ async fn main() {
setup.session_config.clone(),
credentials,
setup.cache.clone(),
true,
)
.fuse(),
);
@ -1634,6 +1635,7 @@ async fn main() {
setup.session_config.clone(),
credentials,
setup.cache.clone(),
true,
).fuse());
},
None => {
@ -1643,7 +1645,7 @@ async fn main() {
}
},
session = &mut connecting, if !connecting.is_terminated() => match session {
Ok(session) => {
Ok((session,_)) => {
let mixer_config = setup.mixer_config.clone();
let mixer = (setup.mixer)(mixer_config);
let player_config = setup.player_config.clone();
@ -1711,6 +1713,7 @@ async fn main() {
setup.session_config.clone(),
credentials,
setup.cache.clone(),
true
).fuse());
},
_ => {