Skip to content

Commit

Permalink
fix: adjustments in the domain and firewall processing transform conf…
Browse files Browse the repository at this point in the history
…ig (#101)

* fix: conditionally include MTLS configuration in domain process strategy

* fix: update firewall schema validation and improve transformToConfig handling
  • Loading branch information
jcbsfilho authored Feb 6, 2025
1 parent ca3d2d7 commit a455143
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
8 changes: 2 additions & 6 deletions packages/config/src/configProcessor/helpers/schemaManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,9 @@ const schemaFirewallManifest = {
errorMessage: "The 'rules' field must be an array of firewall rules.",
},
},
required: ['main_settings'],
additionalProperties: false,
errorMessage: {
additionalProperties: 'No additional properties are allowed in firewall items.',
required: "The 'main_settings' field is required in each firewall item.",
additionalProperties: 'No additional properties are allowed in firewall object.',
},
};

Expand Down Expand Up @@ -797,9 +795,7 @@ const schemaManifest = {
errorMessage: "The 'domains' field must be an array of domain items.",
},
firewall: {
type: 'array',
items: schemaFirewallManifest,
errorMessage: "The 'firewall' field must be an array of firewall items.",
...schemaFirewallManifest,
},
application: {
type: 'array',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ class DomainProcessConfigStrategy extends ProcessConfigStrategy {
digitalCertificateId: domain.digital_certificate_id,
edgeApplicationId: domain.edge_application_id,
edgeFirewallId: domain.edge_firewall_id,
mtls: {
verification: domain.mtls_verification,
trustedCaCertificateId: domain.mtls_trusted_ca_certificate_id,
crlList: domain.crl_list,
},
mtls: domain.mtls_verification
? {
verification: domain.mtls_verification,
trustedCaCertificateId: domain.mtls_trusted_ca_certificate_id,
crlList: domain.crl_list,
}
: undefined,
};
return transformedPayload.domain;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ describe('FirewallProcessConfigStrategy', () => {
const manifest = {};
const config = {};
const result = strategy.transformToConfig(manifest, config);
expect(result).toBeUndefined();
expect(result).toStrictEqual(expect.objectContaining({}));
});

it('should transform all behavior types from manifest to config', () => {
Expand Down Expand Up @@ -299,7 +299,8 @@ describe('FirewallProcessConfigStrategy', () => {
};

const config = {};
const result = strategy.transformToConfig(manifest, config);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const result: any = strategy.transformToConfig(manifest, config);
expect(result?.rules?.[0].behavior).toEqual({
runFunction: {
path: '/edge/function.js',
Expand Down Expand Up @@ -336,7 +337,8 @@ describe('FirewallProcessConfigStrategy', () => {
};

const config = {};
const result = strategy.transformToConfig(manifest, config);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const result: any = strategy.transformToConfig(manifest, config);
expect(result?.rules?.[0].behavior).toEqual({});
});

Expand All @@ -360,7 +362,8 @@ describe('FirewallProcessConfigStrategy', () => {
};

const config = {};
const result = strategy.transformToConfig(manifest, config);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const result: any = strategy.transformToConfig(manifest, config);
expect(result?.rules?.[0].behavior).toEqual({});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ class FirewallProcessConfigStrategy extends ProcessConfigStrategy {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
transformToConfig(payload: any, transformedPayload: AzionConfig) {
const firewall = payload.firewall;
if (!firewall) {
return;
if (!firewall || Object.keys(firewall).length === 0) {
return {};
}

const firewallConfig: AzionFirewall = {
Expand Down

0 comments on commit a455143

Please sign in to comment.