-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vscode): Auto regenerate managed api connection keys (#4982)
* introducing connectionKeys.ts for auto regenerate keys * removed comment in pickFuncProcess * jwtHelper compatible without atob and local setting file access fixes * add logic for resolving connection ids * added function to format settings before api call * updated jwtHelper and workflow services and their imports, added unit tests and logging * update changes to connection.ts * changed workflow to export functions and enabled duration telemetry * fixed typo in workflow * fixed workflow utility * feat(vscode): Auto regenerate managed api connection keys (#5147) * introducing connectionKeys.ts for auto regenerate keys * removed comment in pickFuncProcess * jwtHelper compatible without atob and local setting file access fixes * add logic for resolving connection ids * added function to format settings before api call * updated jwtHelper and workflow services and their imports, added unit tests and logging * update changes to connection.ts * changed workflow to export functions and enabled duration telemetry * fixed typo in workflow * fixed workflow utility --------- Co-authored-by: Joaquim Malcampo <jmalcampo@microsoft.com> * Solve issue with mocking libraries * adjusted unit tests and telemetry settings in pickFuncProcess --------- Co-authored-by: Joaquim Malcampo <jmalcampo@microsoft.com> Co-authored-by: Carlos Emiliano Castro Trejo <ccastrotrejo@microsoft.com>
- Loading branch information
1 parent
831f3cf
commit c31d440
Showing
14 changed files
with
252 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
apps/vs-code-designer/src/app/utils/appSettings/connectionKeys.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { isEmptyString } from '@microsoft/logic-apps-shared'; | ||
import { localize } from '../../../localize'; | ||
import { tryGetLogicAppProjectRoot } from '../verifyIsProject'; | ||
import { getWorkspaceFolder } from '../workspace'; | ||
import { getAzureConnectorDetailsForLocalProject } from '../codeless/common'; | ||
import { getParametersJson } from '../codeless/parameter'; | ||
import type { IActionContext } from '@microsoft/vscode-azext-utils'; | ||
import { workspace } from 'vscode'; | ||
import { ext } from '../../../extensionVariables'; | ||
import type { AzureConnectorDetails, ConnectionsData } from '@microsoft/vscode-extension-logic-apps'; | ||
import { getConnectionsAndSettingsToUpdate, getConnectionsJson, saveConnectionReferences } from '../codeless/connection'; | ||
|
||
export async function verifyLocalConnectionKeys(context: IActionContext): Promise<void> { | ||
if (workspace.workspaceFolders && workspace.workspaceFolders.length > 0) { | ||
const workspaceFolder = await getWorkspaceFolder(context); | ||
const projectPath = await tryGetLogicAppProjectRoot(context, workspaceFolder); | ||
let azureDetails: AzureConnectorDetails; | ||
|
||
if (projectPath) { | ||
azureDetails = await getAzureConnectorDetailsForLocalProject(context, projectPath); | ||
try { | ||
const connectionsJson = await getConnectionsJson(projectPath); | ||
if (isEmptyString(connectionsJson)) { | ||
ext.outputChannel.appendLog(localize('noConnectionKeysFound', 'No connection keys found to verify')); | ||
return; | ||
} | ||
const connectionsData: ConnectionsData = JSON.parse(connectionsJson); | ||
const parametersData = getParametersJson(projectPath); | ||
const managedApiConnectionReferences = connectionsData.managedApiConnections; | ||
|
||
if (connectionsData.managedApiConnections && !(Object.keys(managedApiConnectionReferences).length === 0)) { | ||
const connectionsAndSettingsToUpdate = await getConnectionsAndSettingsToUpdate( | ||
context, | ||
projectPath, | ||
managedApiConnectionReferences, | ||
azureDetails.tenantId, | ||
azureDetails.workflowManagementBaseUrl, | ||
parametersData | ||
); | ||
|
||
await saveConnectionReferences(this.context, projectPath, connectionsAndSettingsToUpdate); | ||
} | ||
} catch (error) { | ||
const errorMessage = localize( | ||
'errorVerifyingConnectionKeys', | ||
'Error while verifying existing managed api connections: {0}', | ||
error.message ?? error | ||
); | ||
ext.outputChannel.appendLog(errorMessage); | ||
context.telemetry.properties.error = errorMessage; | ||
throw new Error(errorMessage); | ||
} | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
apps/vs-code-designer/src/app/utils/codeless/__test__/verifyConnectionKeys.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { isKeyExpired } from '../connection'; | ||
import { JwtTokenHelper } from '@microsoft/vscode-extension-logic-apps'; | ||
import { describe, it, expect } from 'vitest'; | ||
|
||
describe('isKeyExpired', () => { | ||
it('should expose the isKeyExpired function'), | ||
() => { | ||
expect(isKeyExpired).toBeDefined(); | ||
}; | ||
}); | ||
|
||
describe('isKeyExpired with JWTs', () => { | ||
const jwtTokenHelper: JwtTokenHelper = JwtTokenHelper.createInstance(); | ||
// expires June 17 2024 17:56:44 | ||
const testConnectionKey = | ||
'eyJhbGciOiJSzI1NiIsImtpZCI6IjU5NUZDMDdGQTI0RTEyQjdGRUIyMDU2M0FGNkJEMDQ5REU1ODdBMkQiLCJ4NXQiOiJXVl9BZjZKT0VyZi1zZ1ZqcjJ2UVNkNVllaTAiLCJ0eXAiOiJKV1QifQ.eyJ0cyI6IjcyZjk4OGJmLTg2ZjEtNDFhZi05MWFiLTJkN2NkMDExZGI0NyIsImNzIjoibG9naWMtYXBpcy1ub3J0aGNlbnRyYWx1cy9hcm0vYzU3MDBjZjlmYWNmNDMyNzlmODBmN2E5MTE4MDZlMjgiLCJ2IjoiLTkyMjMzNzIwMzY4NTQ3NzU4MDgiLCJlbnZpZCI6IjlkNTFkMWZmYzlmNzc1NzIiLCJhdWQiOiJodHRwczovLzlkNTFkMWZmYzlmNzc1NzIuMDAuY29tbW9uLmxvZ2ljLW5vcnRoY2VudHJhbHVzLmF6dXJlLWFwaWh1Yi5uZXQvYXBpbS9hcm0vYzU3MDBjZjlmYWNmNDMyNzlmODBmN2E5MTE4MDZlMjgiLCJydW50aW1ldXJsIjoiaHR0cHM6Ly85ZDUxZDFmZmM5Zjc3NTcyLjAwLmNvbW1vbi5sb2dpYy1ub3J0aGNlbnRyYWx1cy5henVyZS1hcGlodWIubmV0L2FwaW0vYXJtL2M1NzAwY2Y5ZmFjZjQzMjc5ZjgwZjdhOTExODA2ZTI4IiwibWFuYWdlbWVudCI6Imh0dHBzOi8vbWFuYWdlbWVudC5sb2dpYy1ub3J0aGNlbnRyYWx1cy5henVyZS1hcGlodWIubmV0LyIsIm5iZiI6MTcxODA0MjIwNCwiZXhwIjoxNzE4NjQ3MDA0LCJpYXQiOjE3MTgwNDIyMDQsImlzcyI6Imh0dHBzOi8vbG9naWMtYXBpcy1ub3J0aGNlbnRyYWx1cy5henVyZS1hcGltLm5ldC8ifQ.LTOKYJfBs2SNVwnOvk2HpHecW2oU_rDDwCpiwrr3l9oLfeTsQIM2yZW7XJav35YsbSOGgW2p9cP--u6skFuEEWwEM2oKulh-5PhJ3V_5Bh08w5UeulgrnD7bThkxvo92U5VhOFEg_-v6vpuwDWFAI2KKdiAed1LzpuTZELvYL-h1ijjO5Xnvss5iFHRJ8BEISGIlKTZmKJsvVCTYocPOj2KA8vEzkqI9L2nCUBrsKraNehND-b6MOz5ZiGJ4bd6zQbZRv904CPrwjGWa7fE0GPgr1HsIg-TjfoDDcM7G3S5VwPbYtzOlXVQCh7-PHtH4MuuhXv7fylRpVSVHnnptAQ'; | ||
|
||
it('should return false with a JWT expiry later than the test date', () => { | ||
const testDate: number = Date.UTC(2024, 4); // May 1 2024 00:00:00 | ||
expect(isKeyExpired(jwtTokenHelper, testDate, testConnectionKey, 0)).toBeFalsy(); | ||
}); | ||
|
||
it('should return true with a JWT expiry earlier than the test date', () => { | ||
const testDate: number = Date.UTC(2024, 6); // July 1 2024 00:00:00 | ||
expect(isKeyExpired(jwtTokenHelper, testDate, testConnectionKey, 0)).toBeTruthy(); | ||
}); | ||
|
||
it('should return true with the test date within 3 hours before JWT expiry', () => { | ||
const testDate: number = Date.UTC(2024, 5, 17, 15); // June 17 2024 15:00:00 | ||
expect(isKeyExpired(jwtTokenHelper, testDate, testConnectionKey, 3)).toBeTruthy(); | ||
}); | ||
|
||
it('should return false with the test date on the same day as JWT expiry but outside buffer', () => { | ||
const testDate: number = Date.UTC(2024, 5, 17, 2); // June 17 2024 2:00:00 | ||
expect(isKeyExpired(jwtTokenHelper, testDate, testConnectionKey, 3)).toBeFalsy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
import '@testing-library/jest-dom/vitest'; | ||
import { cleanup } from '@testing-library/react'; | ||
import { afterEach } from 'vitest'; | ||
import { afterEach, vi } from 'vitest'; | ||
|
||
// https://testing-library.com/docs/react-testing-library/api#cleanup | ||
afterEach(() => cleanup()); | ||
|
||
vi.mock('@microsoft/vscode-azext-azureutils', () => ({ | ||
// mock implementation or empty object | ||
})); | ||
|
||
vi.mock('@microsoft/vscode-azext-utils', () => { | ||
return { | ||
AzureWizardExecuteStep: vi.fn().mockImplementation(() => { | ||
return {}; | ||
}), | ||
AzureWizardPromptStep: vi.fn().mockImplementation(() => { | ||
return {}; | ||
}), | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.