forked from qt-creator/qt-creator
Axivion: Isolate authorization recipe
It's going to be used in other recipes. Change-Id: I314f97cc596ce158b7d20e3bb963ca4e35bcb818 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -541,13 +541,11 @@ static Group postDtoRecipe(const Storage<PostDtoStorage<DtoType>> &dtoStorage)
|
|||||||
return recipe;
|
return recipe;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename DtoType>
|
static Group authorizationRecipe()
|
||||||
static Group fetchDataRecipe(const QUrl &url, const std::function<void(const DtoType &)> &handler)
|
|
||||||
{
|
{
|
||||||
const Storage<QString> passwordStorage;
|
const Storage<QString> passwordStorage;
|
||||||
const Storage<GetDtoStorage<Dto::DashboardInfoDto>> dashboardStorage;
|
const Storage<GetDtoStorage<Dto::DashboardInfoDto>> dashboardStorage;
|
||||||
const Storage<PostDtoStorage<Dto::ApiTokenInfoDto>> apiTokenStorage;
|
const Storage<PostDtoStorage<Dto::ApiTokenInfoDto>> apiTokenStorage;
|
||||||
const Storage<GetDtoStorage<DtoType>> dtoStorage;
|
|
||||||
|
|
||||||
const auto onGetCredentialSetup = [](CredentialQuery &credential) {
|
const auto onGetCredentialSetup = [](CredentialQuery &credential) {
|
||||||
credential.setOperation(CredentialOperation::Get);
|
credential.setOperation(CredentialOperation::Get);
|
||||||
@@ -610,20 +608,8 @@ static Group fetchDataRecipe(const QUrl &url, const std::function<void(const Dto
|
|||||||
return SetupResult::Continue;
|
return SetupResult::Continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto onDtoSetup = [dtoStorage, url] {
|
return {
|
||||||
if (!dd->m_apiToken)
|
// TODO: Try unauthorized access first
|
||||||
return SetupResult::StopWithError;
|
|
||||||
|
|
||||||
dtoStorage->credential = "AxToken " + *dd->m_apiToken;
|
|
||||||
dtoStorage->url = url;
|
|
||||||
return SetupResult::Continue;
|
|
||||||
};
|
|
||||||
const auto onDtoDone = [dtoStorage, handler] {
|
|
||||||
if (dtoStorage->dtoData)
|
|
||||||
handler(*dtoStorage->dtoData);
|
|
||||||
};
|
|
||||||
|
|
||||||
const Group recipe {
|
|
||||||
Group {
|
Group {
|
||||||
LoopUntil([](int) { return !dd->m_apiToken; }),
|
LoopUntil([](int) { return !dd->m_apiToken; }),
|
||||||
CredentialQueryTask(onGetCredentialSetup, onGetCredentialDone),
|
CredentialQueryTask(onGetCredentialSetup, onGetCredentialDone),
|
||||||
@@ -642,7 +628,30 @@ static Group fetchDataRecipe(const QUrl &url, const std::function<void(const Dto
|
|||||||
CredentialQueryTask(onSetCredentialSetup)
|
CredentialQueryTask(onSetCredentialSetup)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename DtoType>
|
||||||
|
static Group fetchDataRecipe(const QUrl &url, const std::function<void(const DtoType &)> &handler)
|
||||||
|
{
|
||||||
|
const Storage<GetDtoStorage<DtoType>> dtoStorage;
|
||||||
|
|
||||||
|
const auto onDtoSetup = [dtoStorage, url] {
|
||||||
|
if (!dd->m_apiToken)
|
||||||
|
return SetupResult::StopWithError;
|
||||||
|
|
||||||
|
dtoStorage->credential = "AxToken " + *dd->m_apiToken;
|
||||||
|
dtoStorage->url = url;
|
||||||
|
return SetupResult::Continue;
|
||||||
|
};
|
||||||
|
const auto onDtoDone = [dtoStorage, handler] {
|
||||||
|
if (dtoStorage->dtoData)
|
||||||
|
handler(*dtoStorage->dtoData);
|
||||||
|
};
|
||||||
|
|
||||||
|
const Group recipe {
|
||||||
|
authorizationRecipe(),
|
||||||
Group {
|
Group {
|
||||||
dtoStorage,
|
dtoStorage,
|
||||||
onGroupSetup(onDtoSetup),
|
onGroupSetup(onDtoSetup),
|
||||||
|
|||||||
Reference in New Issue
Block a user