Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the installation process in the HTTP-based version #1132

Merged
merged 13 commits into from
Apr 8, 2024
Merged
11 changes: 9 additions & 2 deletions rust/agama-server/src/manager/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct ManagerState<'a> {

/// Holds information about the manager's status.
#[derive(Clone, Serialize, utoipa::ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct InstallerStatus {
/// Current installation phase.
phase: InstallationPhase,
Expand Down Expand Up @@ -128,10 +129,16 @@ async fn finish_action(State(state): State<ManagerState<'_>>) -> Result<(), Erro
async fn installer_status(
State(state): State<ManagerState<'_>>,
) -> Result<Json<InstallerStatus>, Error> {
let phase = state.manager.current_installation_phase().await?;
// CanInstall gets blocked during installation
let can_install = match phase {
InstallationPhase::Install => false,
_ => state.manager.can_install().await?,
};
let status = InstallerStatus {
phase: state.manager.current_installation_phase().await?,
phase,
can_install,
busy: state.manager.busy_services().await?,
can_install: state.manager.can_install().await?,
iguana: state.manager.use_iguana().await?,
};
Ok(Json(status))
Expand Down
7 changes: 7 additions & 0 deletions rust/agama-server/src/questions/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ struct QuestionsState<'a> {
}

#[derive(Clone, Serialize, Deserialize, utoipa::ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct Question {
generic: GenericQuestion,
with_password: Option<QuestionWithPassword>,
Expand All @@ -154,6 +155,7 @@ pub struct Question {
/// question and its answer. So here it is split into GenericQuestion
/// and GenericAnswer
#[derive(Clone, Serialize, Deserialize, utoipa::ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct GenericQuestion {
id: u32,
class: String,
Expand All @@ -171,27 +173,32 @@ pub struct GenericQuestion {
/// Here for web API we want to have in json that separation that would
/// allow to compose any possible future specialization of question
#[derive(Clone, Serialize, Deserialize, utoipa::ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct QuestionWithPassword {
password: String,
}

#[derive(Clone, Serialize, Deserialize, utoipa::ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct Answer {
generic: GenericAnswer,
with_password: Option<PasswordAnswer>,
}

/// Answer needed for GenericQuestion
#[derive(Clone, Serialize, Deserialize, utoipa::ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct GenericAnswer {
answer: String,
}

/// Answer needed for Password specific questions.
#[derive(Clone, Serialize, Deserialize, utoipa::ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct PasswordAnswer {
password: String,
}

/// Sets up and returns the axum service for the questions module.
pub async fn questions_service(dbus: zbus::Connection) -> Result<Router, ServiceError> {
let questions = QuestionsClient::new(dbus.clone()).await?;
Expand Down
4 changes: 2 additions & 2 deletions rust/agama-server/src/web/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,12 @@ async fn build_issues_proxy<'a>(
/// struct HelloWorldState {};
///
/// let dbus = connection().await.unwrap();
/// let issues_router = validation_router(
/// let validation_routes = validation_router(
/// &dbus, "org.opensuse.HelloWorld", "/org/opensuse/hello"
/// ).await.unwrap();
/// let router: Router<HelloWorldState> = Router::new()
/// .route("/hello", get(hello))
/// .merge(validation_router)
/// .merge(validation_routes)
/// .with_state(HelloWorldState {});
/// });
/// ```
Expand Down
32 changes: 16 additions & 16 deletions web/src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const createClient = (url) => {
const software = new SoftwareClient(client);
// const storage = new StorageClient(address);
const users = new UsersClient(client);
// const questions = new QuestionsClient(address);
const questions = new QuestionsClient(client);

/**
* Gets all issues, grouping them by context.
Expand All @@ -91,13 +91,13 @@ const createClient = (url) => {
*
* @returns {Promise<Issues>}
*/
// const issues = async () => {
// return {
// product: await software.product.getIssues(),
// storage: await storage.getIssues(),
// software: await software.getIssues(),
// };
// };
const issues = async () => {
return {
product: await product.getIssues(),
// storage: await storage.getIssues(),
software: await software.getIssues(),
};
};

/**
* Registers a callback to be executed when issues change.
Expand All @@ -108,15 +108,15 @@ const createClient = (url) => {
const onIssuesChange = (handler) => {
const unsubscribeCallbacks = [];

// unsubscribeCallbacks.push(
// software.product.onIssuesChange((i) => handler({ product: i })),
// );
unsubscribeCallbacks.push(
product.onIssuesChange((i) => handler({ product: i })),
);
// unsubscribeCallbacks.push(
// storage.onIssuesChange((i) => handler({ storage: i })),
// );
// unsubscribeCallbacks.push(
// software.onIssuesChange((i) => handler({ software: i })),
// );
unsubscribeCallbacks.push(
software.onIssuesChange((i) => handler({ software: i })),
);

return () => {
unsubscribeCallbacks.forEach((cb) => cb());
Expand All @@ -142,8 +142,8 @@ const createClient = (url) => {
software,
// storage,
users,
// questions,
// issues,
questions,
issues,
onIssuesChange,
isConnected,
onDisconnect: (handler) => {
Expand Down
4 changes: 2 additions & 2 deletions web/src/client/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ManagerBaseClient {
*/
async canInstall() {
const installer = await this.client.get("/manager/installer");
return installer.can_install;
return installer.canInstall;
}

/**
Expand Down Expand Up @@ -112,7 +112,7 @@ class ManagerBaseClient {
* Runs cleanup when installation is done
*/
finishInstallation() {
return this.client.post("/manager/install");
return this.client.post("/manager/finish");
}

/**
Expand Down
Loading
Loading