Skip to content

Commit f3bfcbc

Browse files
committed
Move encryption methods to the private API
1 parent 98015b7 commit f3bfcbc

File tree

15 files changed

+112
-27
lines changed

15 files changed

+112
-27
lines changed

rust/agama-manager/src/message.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,10 @@ impl SolveStorageModel {
167167
impl Message for SolveStorageModel {
168168
type Reply = Option<Value>;
169169
}
170+
171+
/// Gets the available encryption methods.
172+
pub struct GetEncryptionMethods;
173+
174+
impl Message for GetEncryptionMethods {
175+
type Reply = Vec<String>;
176+
}

rust/agama-manager/src/service.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,20 @@ impl MessageHandler<message::SolveStorageModel> for Service {
866866
}
867867
}
868868

869+
#[async_trait]
870+
impl MessageHandler<message::GetEncryptionMethods> for Service {
871+
/// Gets the available encryption methods.
872+
async fn handle(
873+
&mut self,
874+
_message: message::GetEncryptionMethods,
875+
) -> Result<Vec<String>, Error> {
876+
Ok(self
877+
.storage
878+
.call(storage::message::GetEncryptionMethods)
879+
.await?)
880+
}
881+
}
882+
869883
// FIXME: write a macro to forward a message.
870884
#[async_trait]
871885
impl MessageHandler<software::message::SetResolvables> for Service {

rust/agama-server/src/server/web.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ pub fn server_with_state(state: ServerState) -> Result<Router, ServiceError> {
141141
.route("/private/resolvables/:id", put(set_resolvables))
142142
.route("/private/download_logs", get(download_logs))
143143
.route("/private/password_check", post(check_password))
144+
.route("/private/encryption_methods", get(get_encryption_methods))
144145
.with_state(state))
145146
}
146147

@@ -586,3 +587,20 @@ async fn check_password(
586587
.await?;
587588
Ok(Json(result))
588589
}
590+
591+
/// Returns the available encryption methods for the current system and product.
592+
#[utoipa::path(
593+
get,
594+
path = "/private/encryption_methods",
595+
context_path = "/api/v2",
596+
responses(
597+
(status = 200, description = "Available encryption methods", body = Vec<String>),
598+
(status = 400, description = "Could not retrieve encryption methods")
599+
)
600+
)]
601+
async fn get_encryption_methods(
602+
State(state): State<ServerState>,
603+
) -> Result<Json<Vec<String>>, Error> {
604+
let methods = state.manager.call(message::GetEncryptionMethods).await?;
605+
Ok(Json(methods))
606+
}

rust/agama-storage-client/src/message.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ impl Message for GetIssues {
9090
type Reply = Vec<Issue>;
9191
}
9292

93+
pub struct GetEncryptionMethods;
94+
95+
impl Message for GetEncryptionMethods {
96+
type Reply = Vec<String>;
97+
}
98+
9399
pub struct GetConfigFromModel {
94100
pub model: serde_json::Value,
95101
}

rust/agama-storage-client/src/proxies/storage1.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ pub trait Storage1 {
3232
/// Finish method
3333
fn finish(&self) -> zbus::Result<()>;
3434

35+
/// GetEncryptionMethods method
36+
fn get_encryption_methods(&self) -> zbus::Result<String>;
37+
3538
/// GetConfigFromModel method
3639
fn get_config_from_model(&self, model: &str) -> zbus::Result<String>;
3740

rust/agama-storage-client/src/service.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,17 @@ impl MessageHandler<message::GetIssues> for Service {
168168
}
169169
}
170170

171+
#[async_trait]
172+
impl MessageHandler<message::GetEncryptionMethods> for Service {
173+
async fn handle(
174+
&mut self,
175+
_message: message::GetEncryptionMethods,
176+
) -> Result<Vec<String>, Error> {
177+
let raw_json = self.storage_proxy.get_encryption_methods().await?;
178+
Ok(try_from_string(&raw_json)?)
179+
}
180+
}
181+
171182
#[async_trait]
172183
impl MessageHandler<message::GetConfigFromModel> for Service {
173184
async fn handle(

rust/agama-storage/src/client.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pub trait StorageClient {
6868
) -> Result<BoxFuture<Result<(), Error>>, Error>;
6969
async fn solve_config_model(&self, model: Value) -> Result<Option<Value>, Error>;
7070
async fn set_locale(&self, locale: String) -> Result<(), Error>;
71+
async fn get_encryption_methods(&self) -> Result<Vec<String>, Error>;
7172
}
7273

7374
/// D-Bus client for the storage service
@@ -164,4 +165,12 @@ impl StorageClient for Client {
164165
.await?;
165166
Ok(())
166167
}
168+
169+
async fn get_encryption_methods(&self) -> Result<Vec<String>, Error> {
170+
let value = self
171+
.storage_client
172+
.call(message::GetEncryptionMethods)
173+
.await?;
174+
Ok(value)
175+
}
167176
}

rust/agama-storage/src/message.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,10 @@ impl SetLocale {
169169
impl Message for SetLocale {
170170
type Reply = ();
171171
}
172+
173+
#[derive(Clone)]
174+
pub struct GetEncryptionMethods;
175+
176+
impl Message for GetEncryptionMethods {
177+
type Reply = Vec<String>;
178+
}

rust/agama-storage/src/service.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,13 @@ impl MessageHandler<message::SetLocale> for Service {
238238
Ok(())
239239
}
240240
}
241+
242+
#[async_trait]
243+
impl MessageHandler<message::GetEncryptionMethods> for Service {
244+
async fn handle(
245+
&mut self,
246+
_message: message::GetEncryptionMethods,
247+
) -> Result<Vec<String>, Error> {
248+
Ok(self.client.get_encryption_methods().await?)
249+
}
250+
}

rust/agama-storage/src/test_utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ impl StorageClient for TestClient {
165165
async fn set_locale(&self, _locale: String) -> Result<(), Error> {
166166
Ok(())
167167
}
168+
169+
async fn get_encryption_methods(&self) -> Result<Vec<String>, Error> {
170+
Ok(vec!["luks2".to_string()])
171+
}
168172
}
169173

170174
/// Starts a testing storage service.

0 commit comments

Comments
 (0)