Skip to content

Add azure resource graph action#1603

Merged
bigfluffycookie merged 22 commits intomainfrom
lb/rg
Nov 12, 2025
Merged

Add azure resource graph action#1603
bigfluffycookie merged 22 commits intomainfrom
lb/rg

Conversation

@bigfluffycookie
Copy link
Copy Markdown
Contributor

@bigfluffycookie bigfluffycookie commented Nov 12, 2025

Fixes OPS-2860

image

@linear
Copy link
Copy Markdown

linear Bot commented Nov 12, 2025

@bigfluffycookie bigfluffycookie marked this pull request as ready for review November 12, 2025 12:09
Copilot AI review requested due to automatic review settings November 12, 2025 12:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds Azure Resource Graph query functionality to the Azure block, enabling users to execute KQL queries across multiple Azure subscriptions.

Key Changes

  • Adds a new resource_graph_query action that queries Azure Resource Graph using KQL
  • Implements subscription batching (max 1000 per query) to handle Azure API limits
  • Supports both service principal and host session authentication methods

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
packages/blocks/azure/src/lib/actions/azure-resource-graph-action.ts Implements the new Resource Graph query action with pagination and subscription batching
packages/blocks/azure/src/index.ts Registers the new action in the Azure block
packages/blocks/azure/test/azure-resource-graph-action.test.ts Adds comprehensive test coverage for the new action
packages/blocks/azure/test/index.test.ts Updates test to reflect the new action count

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/blocks/azure/src/lib/actions/azure-resource-graph-action.ts Outdated
Comment thread packages/blocks/azure/src/lib/actions/azure-resource-graph-action.ts Outdated
required: false,
validators: [Validators.minValue(1), Validators.integer],
}),
apiVersion: Property.ShortText({
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

idk if i should have added this or not, i feel like its a pain if we have to change it in the backend everytime theres a new one

@bigfluffycookie bigfluffycookie changed the base branch from main to lb/ref November 12, 2025 12:53
Comment on lines +193 to +195
const token = useHostSession?.['useHostSessionCheckbox']
? await getHostAccessToken(context.auth)
: (await authenticateUserWithAzure(context.auth)).access_token;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please extract this to a new file. It will be useful for future actions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

#1606 dealt with it here

@bigfluffycookie bigfluffycookie changed the base branch from lb/ref to lb/tok November 12, 2025 14:37
Comment thread packages/blocks/azure/src/lib/actions/azure-resource-graph-action.ts Outdated
Comment thread packages/blocks/azure/src/lib/actions/azure-resource-graph-action.ts Outdated
Comment on lines +152 to +159
const batches: (string[] | undefined)[] = [];
if (subscriptionList?.length) {
for (let i = 0; i < subscriptionList.length; i += BATCH_SIZE) {
batches.push(subscriptionList.slice(i, i + BATCH_SIZE));
}
} else {
batches.push(undefined);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Extract to a method:

function splitSubscriptionListIntoBatches(
  subscriptionList?: string[],
): (string[] | undefined)[] {
  if (!subscriptionList?.length) {
    return [undefined];
  }

  const batches: string[][] = [];
  for (let i = 0; i < subscriptionList.length; i += BATCH_SIZE) {
    const batch = subscriptionList.slice(i, i + BATCH_SIZE);
    batches.push(batch);
  }

  return batches;
}

batches.push(undefined);
}

const allResults: Record<string, unknown>[] = [];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

    const allResults = await getQueryResults(
      splitSubscriptionListIntoBatches(subscriptionList),
      buildResourceGraphUrl(apiVersion),
      headers,
      kql,
      normalizedMax,
    );

Comment thread packages/blocks/azure/src/lib/actions/azure-resource-graph-action.ts Outdated
Base automatically changed from lb/tok to main November 12, 2025 19:11
@sonarqubecloud
Copy link
Copy Markdown

@bigfluffycookie bigfluffycookie merged commit d01515f into main Nov 12, 2025
21 checks passed
@bigfluffycookie bigfluffycookie deleted the lb/rg branch November 12, 2025 20:48
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.

3 participants