Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AzureFunctionV2 #20933

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Add AzureFunctionV2 #20933

wants to merge 7 commits into from

Conversation

LeftTwixWand
Copy link
Contributor

Task name: AzureFunctionV2

Description: New version of AzureFunction task with support of ARM Service Connection authentication.
The previous version of the task was running on server and it's impossible to add additional logic, which ARM service connection requires. So, a completelly new version of the task was created to support ARM service connection authentication.

Risk Assesment(Low/Medium/High): Low

Tests Performed: Added e2e tests

Documentation changes required: Y

Attached related issue: AB#2221642

Checklist:

  • Task version was bumped - please check instruction how to do it
  • Checked that applied changes work as expected

@LeftTwixWand
Copy link
Contributor Author

/azp run

@LeftTwixWand
Copy link
Contributor Author

/azp run

Copy link
Contributor

@onetocny onetocny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at my inline comments. Also please add more CI tests to cover majority scenarios that are supported by this task (e.g. callback, both auth types, response validation etc.).

"label": "Query parameters",
"defaultValue": "",
"required": false,
"helpMarkDown": "Query parameters string to append to the function URL. It should not start with with \"?\" nor \"&\"."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit; There is double negation in this sentence. I believe it should be "It should start neither with ? nor &." or "It should not start either with ? or &.". Also note duplicate "with".


// Add query parameters if present
if (this.inputs.queryParameters) {
url += this.inputs.queryParameters;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description of query param input in task.json says that input should not start with &. However, if you just concatenate it here it will not produce valid url. E.g.:

https://function.azure.com?code=xxxxxxqueryparam1=value&queryparam2=value

I would not rely on the fact that users wont put & or & as first character in query parameter input. Lets trim it or maybe even parse it and use only valid parts.

tl.debug(`Building request with ARM authentication using service connection: ${this.inputs.serviceConnection}`);

try {
const request = this.buildKeyAuthRequest();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will produce url with code query param which is not valid in this scenario as auth is done via ARM endpoint. Please extract code that is common for both buildKeyAuthRequest and buildArmAuthRequest into separate method.

private getDefaultHeaders(): Record<string, string> {
return {
'Content-Type': 'application/json',
PlanUrl: tl.getVariable('system.CollectionUri') || '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something that was even in previous version? Why are we including these values? PlanId, JobId etc. are internal ADO details. They should be irrelevant for request that is targeting Azure.

// Safe evaluation with a restricted context
try {
// Use with statement to provide the context to the expression
const result = eval(`with (context) { ${expression} }`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain what is expected format of the success criteria input? As far as I can see eval does not really work with expressions described in input's description. Apart of that using eval should be a big no no.

* Checks if the callback has been received
* @returns The callback result, or null if not received yet
*/
private async checkCallbackStatus(): Promise<CallbackResult | null> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this async? I do not see any await inside the function.

@onetocny
Copy link
Contributor

One general comment. The PR description claims "it's impossible to add additional logic, which ARM service connection requires". What exactly is not possible to achieve in agent less task? For example InvokeRestApiV1 is server task and it is using the ARM service connection.

@LeftTwixWand
Copy link
Contributor Author

One general comment. The PR description claims "it's impossible to add additional logic, which ARM service connection requires". What exactly is not possible to achieve in agent less task? For example InvokeRestApiV1 is server task and it is using the ARM service connection.

InvokeRestApiV1 accepts Generic or ARM service connections. Both have the same structure, so the process of retrieving the URL for request is identical and it can be described in json format for server tasks.
But in case with Azure Function, the customers should provide URL manually and there is no way to add logic of selecting the URL into server tasks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants