Skip to content

Commit

Permalink
Merge pull request #1714 from jo-lund/failed-inventory-update
Browse files Browse the repository at this point in the history
fix: Resend the inventory when the device has reauthenticated
  • Loading branch information
lluiscampos authored Dec 17, 2024
2 parents 5931106 + efc3fca commit 47313c6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/api/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ error::Error HTTPClient::AsyncCall(
});
return;
}
reauthenticated_ = true;
};

return authenticator_.WithToken(
Expand Down
9 changes: 9 additions & 0 deletions src/api/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,19 @@ class HTTPClient : public Client {
authenticator_.ExpireToken();
}

bool HasReauthenticated() {
return reauthenticated_;
}

void SetReauthenticated(bool reauthenticated) {
reauthenticated_ = reauthenticated;
}

private:
events::EventLoop &event_loop_;
http::Client http_client_;
auth::Authenticator &authenticator_;
bool reauthenticated_ {false};
};

} // namespace api
Expand Down
7 changes: 6 additions & 1 deletion src/mender-update/daemon/states.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,12 @@ void PollForDeploymentState::OnEnter(Context &ctx, sm::EventPoster<StateEvent> &
} else if (!response.value()) {
log::Info("No update available");
poster.PostEvent(StateEvent::NothingToDo);

if (ctx.http_client.HasReauthenticated()) {
log::Debug("Client has reauthenticated, clear inventory data cache");
ctx.inventory_client->ClearDataCache();
ctx.has_submitted_inventory = false;
ctx.http_client.SetReauthenticated(false);
}
if (not ctx.has_submitted_inventory) {
// If we have not submitted inventory successfully at least
// once, schedule this after receiving a successful response
Expand Down

0 comments on commit 47313c6

Please sign in to comment.