@gradientedge/cdk-utils-azure 2.16.0 → 2.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
+ import { isDevStage, isPrdStage, isTestStage, isUatStage } from '@gradientedge/cdk-utils-common';
1
2
  import { getWorkspaceOutput } from '@pulumi/azure-native/operationalinsights/index.js';
2
3
  import * as pulumi from '@pulumi/pulumi';
3
4
  import { ComponentResource } from '@pulumi/pulumi';
4
- import { isDevStage, isPrdStage, isTestStage, isUatStage } from '@gradientedge/cdk-utils-common';
5
5
  import { AzureAuthorisationManager } from '../services/authorisation/main.js';
6
6
  import { AzureApiManagementManager, AzureAppConfigurationManager, AzureApplicationInsightsManager, AzureAppServiceManager, AzureCosmosDbManager, AzureDnsManager, AzureEventgridManager, AzureFunctionManager, AzureKeyVaultManager, AzureMonitorManager, AzureOperationalInsightsManager, AzurePortalManager, AzureRedisManager, AzureResourceGroupManager, AzureSecurityCentermanager, AzureServiceBusManager, AzureStorageManager, } from '../services/index.js';
7
7
  import { AzureResourceNameFormatter } from './resource-name-formatter.js';
@@ -76,7 +76,9 @@ export class CommonAzureConstruct extends ComponentResource {
76
76
  resolveStack(stackName) {
77
77
  if (!stackName)
78
78
  throw new Error('Stack name undefined');
79
- return new pulumi.StackReference(stackName);
79
+ return new pulumi.StackReference(stackName, {
80
+ name: stackName,
81
+ });
80
82
  }
81
83
  createResourceGroup() {
82
84
  if (this.resourceGroup)
@@ -21,6 +21,7 @@ export declare class CommonAzureStack extends ComponentResource {
21
21
  construct: CommonAzureConstruct;
22
22
  props: CommonAzureStackProps;
23
23
  config: Config;
24
+ outputs?: Record<string, unknown>;
24
25
  constructor(name: string, props: CommonAzureStackProps, options?: ComponentResourceOptions);
25
26
  /**
26
27
  * @summary Method to determine the core construct properties injected via context
@@ -40,8 +41,12 @@ export declare class CommonAzureStack extends ComponentResource {
40
41
  * - Primary use is to have layered config for each environment which is injected into the context
41
42
  */
42
43
  protected determineStageContexts(): any;
44
+ protected createConstruct(): void;
45
+ protected registerOutputs(): void;
43
46
  /**
44
47
  * @summary Determine the fully qualified domain name based on domainName & subDomain
45
48
  */
46
49
  protected fullyQualifiedDomain(): string;
50
+ protected static determineEnvironmentProperty(): string;
51
+ protected static getEnvironmentProperty(property: string): any;
47
52
  }
@@ -1,9 +1,9 @@
1
- import fs from 'fs';
2
- import path from 'path';
1
+ import fs, { readFileSync, statSync } from 'fs';
2
+ import path, { dirname, join } from 'path';
3
+ import { isDevStage } from '@gradientedge/cdk-utils-common';
3
4
  import { ComponentResource, Config } from '@pulumi/pulumi';
4
5
  import appRoot from 'app-root-path';
5
6
  import _ from 'lodash';
6
- import { isDevStage } from '@gradientedge/cdk-utils-common';
7
7
  import { registerTagTransformation } from './tagging.js';
8
8
  /**
9
9
  * Common stack to use as a base for all higher level constructs using Pulumi
@@ -25,6 +25,7 @@ export class CommonAzureStack extends ComponentResource {
25
25
  construct;
26
26
  props;
27
27
  config;
28
+ outputs;
28
29
  constructor(name, props, options) {
29
30
  super(`stack:${name}`, name, props, options);
30
31
  /* initialise config */
@@ -34,6 +35,8 @@ export class CommonAzureStack extends ComponentResource {
34
35
  if (this.props.defaultTags) {
35
36
  registerTagTransformation(this.props.defaultTags);
36
37
  }
38
+ this.createConstruct();
39
+ this.registerOutputs();
37
40
  }
38
41
  /**
39
42
  * @summary Method to determine the core construct properties injected via context
@@ -110,6 +113,16 @@ export class CommonAzureStack extends ComponentResource {
110
113
  /* parse as JSON properties */
111
114
  return JSON.parse(stageContextPropsBuffer.toString('utf-8'));
112
115
  }
116
+ createConstruct() { }
117
+ registerOutputs() {
118
+ if (this.construct && this.construct.resourceGroup) {
119
+ this.outputs = {
120
+ resourceGroupId: this.construct.resourceGroup.id,
121
+ resourceGroupName: this.construct.resourceGroup.name,
122
+ };
123
+ super.registerOutputs(this.outputs);
124
+ }
125
+ }
113
126
  /**
114
127
  * @summary Determine the fully qualified domain name based on domainName & subDomain
115
128
  */
@@ -118,4 +131,27 @@ export class CommonAzureStack extends ComponentResource {
118
131
  const subDomain = this.props.subDomain;
119
132
  return subDomain ? `${subDomain}.${domainName}` : domainName;
120
133
  }
134
+ static determineEnvironmentProperty() {
135
+ const config = new Config();
136
+ const stageContextPath = config.get('stageContextPath');
137
+ let dir = process.cwd();
138
+ for (let i = 0; i < 6; i++) {
139
+ try {
140
+ if (statSync(join(dir, `${stageContextPath}`)).isDirectory())
141
+ return dir;
142
+ }
143
+ catch {
144
+ /* keep walking */
145
+ }
146
+ dir = dirname(dir);
147
+ }
148
+ throw new Error('Could not locate infrastructure root (pulumi-env/ not found)');
149
+ }
150
+ static getEnvironmentProperty(property) {
151
+ const config = new Config();
152
+ const stage = config.get('stage');
153
+ const stageContextPath = config.get('stageContextPath');
154
+ const envConfig = JSON.parse(readFileSync(join(this.determineEnvironmentProperty(), `${stageContextPath}`, `${stage}.json`), 'utf8'));
155
+ return envConfig[property];
156
+ }
121
157
  }
@@ -7,6 +7,13 @@ import { RESOURCES_TO_EXCLUDE_TAGS } from './constants.js';
7
7
  */
8
8
  /** @category Constant */
9
9
  export function isTaggableResource(resourceType) {
10
+ // Entire providers that don't support tags
11
+ if (resourceType.startsWith('azuread:'))
12
+ return false;
13
+ if (resourceType.startsWith('random:'))
14
+ return false;
15
+ if (resourceType.startsWith('pulumi:'))
16
+ return false;
10
17
  // Extract the resource name from the type (e.g., 'ResourceGroup' from 'azure-native:resources:ResourceGroup')
11
18
  const resourceName = resourceType.split(':').pop() || '';
12
19
  // Check if this resource is in the exclusion list
@@ -266,6 +266,7 @@ export class AzureRestApiFunction extends AzureFunctionApp {
266
266
  <inbound>
267
267
  <base />
268
268
  ${this.api.corsPolicyXmlContent ?? ''}
269
+ ${this.api.validateJwtPolicyXmlContent ?? ''}
269
270
  <set-backend-service backend-id="${this.api.backend.name}" />
270
271
  <set-header name="traceparent" exists-action="override">
271
272
  <value>@(context.Request.Headers.GetValueOrDefault("traceparent", ""))</value>
@@ -23,11 +23,12 @@ export interface AzureRestApiFunctionProps extends AzureRestApiProps, AzureFunct
23
23
  }
24
24
  /** @category Interface */
25
25
  export interface AzureApiFunction extends AzureApi {
26
- corsPolicyXmlContent?: string;
27
26
  apiOperations: {
28
27
  [operation: string]: ApiOperation;
29
28
  };
30
- managementApi: Api;
31
29
  backend: Backend;
30
+ corsPolicyXmlContent?: string;
31
+ managementApi: Api;
32
32
  namedValue: NamedValue;
33
+ validateJwtPolicyXmlContent?: string;
33
34
  }
@@ -75,9 +75,7 @@ export class AzureStorageManager {
75
75
  createStorageContainer(id, scope, props, resourceOptions) {
76
76
  if (!props)
77
77
  throw new Error(`Props undefined for ${id}`);
78
- const resourceGroupName = scope.props.resourceGroupName
79
- ? scope.resourceNameFormatter.format(scope.props.resourceGroupName)
80
- : `${props.resourceGroupName}`;
78
+ const resourceGroupName = props.resourceGroupName ?? scope.resourceNameFormatter.format(scope.props.resourceGroupName);
81
79
  return new BlobContainer(`${id}-sc`, {
82
80
  ...props,
83
81
  containerName: scope.resourceNameFormatter.format(props.containerName?.toString(), scope.props.resourceNameOptions?.storageContainer),
@@ -97,9 +95,7 @@ export class AzureStorageManager {
97
95
  createStorageBlob(id, scope, props, resourceOptions) {
98
96
  if (!props)
99
97
  throw new Error(`Props undefined for ${id}`);
100
- const resourceGroupName = scope.props.resourceGroupName
101
- ? scope.resourceNameFormatter.format(scope.props.resourceGroupName)
102
- : `${props.resourceGroupName}`;
98
+ const resourceGroupName = props.resourceGroupName ?? scope.resourceNameFormatter.format(scope.props.resourceGroupName);
103
99
  return new Blob(`${id}-sb`, {
104
100
  ...props,
105
101
  blobName: scope.resourceNameFormatter.format(props.blobName?.toString(), scope.props.resourceNameOptions?.storageBlob),
@@ -126,9 +122,7 @@ export class AzureStorageManager {
126
122
  * @see https://www.pulumi.com/registry/packages/azure-native/api-docs/storage/liststorageaccountsas/
127
123
  */
128
124
  generateContainerSasToken(id, scope, props, storageAccount) {
129
- const resourceGroupName = scope.props.resourceGroupName
130
- ? scope.resourceNameFormatter.format(scope.props.resourceGroupName)
131
- : `${props.resourceGroupName}`;
125
+ const resourceGroupName = props.resourceGroupName ?? scope.resourceNameFormatter.format(scope.props.resourceGroupName);
132
126
  return pulumi
133
127
  .all([storageAccount.name])
134
128
  .apply(([accountName]) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils-azure",
3
- "version": "2.16.0",
3
+ "version": "2.18.0",
4
4
  "description": "Azure Pulumi utilities for @gradientedge/cdk-utils",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",
@@ -16,6 +16,7 @@
16
16
  "dependencies": {
17
17
  "@pulumi/archive": "0.3.7",
18
18
  "@pulumi/azure-native": "3.16.0",
19
+ "@pulumi/azuread": "6.9.0",
19
20
  "@pulumi/pulumi": "3.230.0",
20
21
  "@types/lodash": "4.17.24",
21
22
  "app-root-path": "3.1.0",