Skip to content

Commit

Permalink
Merge pull request #307 from vscheuber/main
Browse files Browse the repository at this point in the history
offline connection profile ops
  • Loading branch information
vscheuber authored Sep 22, 2023
2 parents bbfa87a + fa8dd97 commit 4889dae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/ops/ConnectionProfileOps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ describe('ConnectionProfileOps', () => {
const host = 'https://openam-tenant-name.forgeblocks.com/am';
const user = 'frodo.baggins@shire.me';
const password = 'G@nd@lfTheW153';

state.setHost(host);
state.setUsername(user);
state.setPassword(password);
state.setConnectionProfilesPath(connectionProfilePath1);
await ConnectionProfileOps.saveConnectionProfile({ host, state });
await ConnectionProfileOps.saveConnectionProfile({ host, offline: true, state });
expect(fs.existsSync(connectionProfilePath1)).toBeTruthy();
const connections = JSON.parse(
fs.readFileSync(connectionProfilePath1, 'utf8')
Expand All @@ -88,7 +88,7 @@ describe('ConnectionProfileOps', () => {
state.setUsername(user);
state.setPassword(password);
state.setConnectionProfilesPath('');
await ConnectionProfileOps.saveConnectionProfile({ host, state });
await ConnectionProfileOps.saveConnectionProfile({ host, offline: true, state });
expect(ConnectionProfileOps.getConnectionProfilesPath({ state })).toEqual(
connectionProfilePath2
);
Expand All @@ -114,7 +114,7 @@ describe('ConnectionProfileOps', () => {
state.setUsername(user);
state.setPassword(password);
state.setConnectionProfilesPath(connectionProfilePath3);
await ConnectionProfileOps.saveConnectionProfile({ host, state });
await ConnectionProfileOps.saveConnectionProfile({ host, offline: true, state });
expect(fs.existsSync(connectionProfilePath3)).toBeTruthy();
const connections = JSON.parse(
fs.readFileSync(connectionProfilePath3, 'utf8')
Expand Down
18 changes: 11 additions & 7 deletions src/ops/ConnectionProfileOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,11 @@ export async function getConnectionProfile({
*/
export async function saveConnectionProfile({
host,
offline = false,
state,
}: {
host: string;
offline?: boolean;
state: State;
}): Promise<boolean> {
debugMessage({
Expand Down Expand Up @@ -496,19 +498,21 @@ export async function saveConnectionProfile({
// service account
if (state.getServiceAccountId()) {
profile.svcacctId = state.getServiceAccountId();
profile.svcacctName = (
await getServiceAccount({
serviceAccountId: state.getServiceAccountId(),
state,
})
).name;
if (!offline) {
profile.svcacctName = (
await getServiceAccount({
serviceAccountId: state.getServiceAccountId(),
state,
})
).name;
}
}
if (state.getServiceAccountJwk())
profile.encodedSvcacctJwk = await dataProtection.encrypt(
state.getServiceAccountJwk()
);
// update existing service account profile
if (profile.svcacctId && !profile.svcacctName) {
if (!offline && profile.svcacctId && !profile.svcacctName) {
profile.svcacctName = (
await getServiceAccount({ serviceAccountId: profile.svcacctId, state })
).name;
Expand Down

0 comments on commit 4889dae

Please sign in to comment.