Skip to content

Commit

Permalink
fix: Fix merged files
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-cucu committed Jan 15, 2024
1 parent dfaca63 commit 34c608a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 66 deletions.
24 changes: 6 additions & 18 deletions src/juju/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,12 +734,8 @@ describe("Juju API", () => {
.spyOn(jujuLibVersions, "jujuUpdateAvailable")
.mockImplementationOnce(async () => true)
.mockImplementationOnce(async () => false);
await fetchControllerList(
"wss://example.com/api",
conn,
true,
dispatch,
() => rootStateFactory.build(),
await fetchControllerList("wss://example.com/api", conn, dispatch, () =>
rootStateFactory.build(),
);
expect(dispatch).toHaveBeenCalledWith(
jujuActions.updateControllerList({
Expand Down Expand Up @@ -773,12 +769,8 @@ describe("Juju API", () => {
.spyOn(jujuLibVersions, "jujuUpdateAvailable")
.mockImplementationOnce(async () => true)
.mockImplementationOnce(async () => false);
await fetchControllerList(
"wss://example.com/api",
conn,
true,
dispatch,
() => rootStateFactory.build(),
await fetchControllerList("wss://example.com/api", conn, dispatch, () =>
rootStateFactory.build(),
);
expect(dispatch).toHaveBeenCalledWith(
jujuActions.updateControllerList({
Expand Down Expand Up @@ -849,12 +841,8 @@ describe("Juju API", () => {
jest
.spyOn(jujuLibVersions, "jujuUpdateAvailable")
.mockImplementationOnce(async () => null);
await fetchControllerList(
"wss://example.com/api",
conn,
true,
dispatch,
() => rootStateFactory.build(),
await fetchControllerList("wss://example.com/api", conn, dispatch, () =>
rootStateFactory.build(),
);
expect(dispatch).toHaveBeenCalledWith(
jujuActions.updateControllerList({
Expand Down
2 changes: 1 addition & 1 deletion src/store/app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type ControllerArgs = [
// credentials
Credential | undefined,
// identityProviderAvailable
boolean | undefined
boolean | undefined,
];

export const connectAndPollControllers = createAction<{
Expand Down
91 changes: 44 additions & 47 deletions src/store/middleware/model-poller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export enum LoginError {
NO_INFO = "Unable to retrieve controller details",
}

type ControllerOptions = [string, Credential, boolean];

const checkJIMMRelation = async (
conn: ConnectionWithFacades,
identity: string,
Expand Down Expand Up @@ -64,39 +62,38 @@ export const modelPollerMiddleware: Middleware<
// Each time we try to log in to a controller we get new macaroons, so
// first clean up any old auth requests:
reduxStore.dispatch(generalActions.clearVisitURLs());
action.payload.controllers.forEach(
async (controllerData: ControllerOptions) => {
const [wsControllerURL, credentials, identityProviderAvailable] =
controllerData;
let conn: ConnectionWithFacades | undefined;
let juju: Client | undefined;
let error: unknown;
let intervalId: number | null | undefined;
try {
({ conn, error, juju, intervalId } = await loginWithBakery(
wsControllerURL,
credentials,
identityProviderAvailable
));
if (conn) {
controllers.set(wsControllerURL, conn);
}
if (error && typeof error === "string") {
reduxStore.dispatch(
generalActions.storeLoginError({ wsControllerURL, error })
);
return;
}
} catch (e) {
for (const controllerData of action.payload.controllers) {
const [wsControllerURL, credentials, identityProviderAvailable] =
controllerData;
let conn: ConnectionWithFacades | undefined;
let juju: Client | undefined;
let error: unknown;
let intervalId: number | null | undefined;
try {
({ conn, error, juju, intervalId } = await loginWithBakery(
wsControllerURL,
credentials,
identityProviderAvailable,
));
if (conn) {
controllers.set(wsControllerURL, conn);
}
if (error && typeof error === "string") {
reduxStore.dispatch(
generalActions.storeLoginError({
wsControllerURL,
error:
"Unable to log into the controller, check that the controller address is correct and that it is online.",
})
generalActions.storeLoginError({ wsControllerURL, error }),
);
return console.log(LoginError.LOG, e, controllerData);
return;
}
} catch (e) {
reduxStore.dispatch(
generalActions.storeLoginError({
wsControllerURL,
error:
"Unable to log into the controller, check that the controller address is correct and that it is online.",
}),
);
return console.log(LoginError.LOG, e, controllerData);
}

if (!conn?.info || !Object.keys(conn.info).length) {
reduxStore.dispatch(
Expand Down Expand Up @@ -171,22 +168,22 @@ export const modelPollerMiddleware: Middleware<
);
}

await fetchControllerList(
wsControllerURL,
conn,
reduxStore.dispatch,
reduxStore.getState
);
if (identityProviderAvailable) {
// This call will be a noop if the user isn't an administrator
// on the JIMM controller we're connected to.
try {
await disableControllerUUIDMasking(conn);
} catch (e) {
// Silently fail, if this doesn't work then the user isn't authorized
// to perform the action.
}
await fetchControllerList(
wsControllerURL,
conn,
reduxStore.dispatch,
reduxStore.getState,
);
if (identityProviderAvailable) {
// This call will be a noop if the user isn't an administrator
// on the JIMM controller we're connected to.
try {
await disableControllerUUIDMasking(conn);
} catch (e) {
// Silently fail, if this doesn't work then the user isn't authorized
// to perform the action.
}
}

let pollCount = 0;
do {
Expand Down

0 comments on commit 34c608a

Please sign in to comment.