-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #624 from aziontech/dev
DEPLOY 2024.01.25
- Loading branch information
Showing
50 changed files
with
1,928 additions
and
96 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
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
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
81 changes: 81 additions & 0 deletions
81
src/services/waf-rules-services/create-waf-rules-allowed-tuning-service.js
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,81 @@ | ||
import { AxiosHttpClientAdapter } from '../axios/AxiosHttpClientAdapter' | ||
import * as Errors from '@/services/axios/errors' | ||
import { makeWafRulesAllowedBaseUrl } from './make-waf-rules-allowed-base-url' | ||
|
||
export const createWafRulesAllowedTuningService = async ({ payload, wafId }) => { | ||
let httpResponse = await AxiosHttpClientAdapter.request({ | ||
url: `${makeWafRulesAllowedBaseUrl()}/${wafId}/allowed_rules`, | ||
method: 'POST', | ||
body: adapt(payload) | ||
}) | ||
|
||
return parseHttpResponse(httpResponse) | ||
} | ||
|
||
const adapt = (payload) => { | ||
return { | ||
rule_id: payload.ruleId, | ||
match_zones: payload.matchZone, | ||
reason: payload.reason | ||
} | ||
} | ||
|
||
/** | ||
* @param {Object} httpResponse - The HTTP response object. | ||
* @param {Object} httpResponse.body - The response body. | ||
* @param {String} httpResponse.statusCode - The HTTP status code. | ||
* @returns {string} The result message based on the status code. | ||
* @throws {Error} If there is an error with the response. | ||
*/ | ||
const parseHttpResponse = (httpResponse) => { | ||
switch (httpResponse.statusCode) { | ||
case 202: | ||
return 'Your waf rule allowed has been created' | ||
case 400: | ||
const apiError = extractApiError(httpResponse) | ||
throw new Error(apiError).message | ||
case 401: | ||
throw new Errors.InvalidApiTokenError().message | ||
case 403: | ||
throw new Errors.PermissionError().message | ||
case 404: | ||
throw new Errors.NotFoundError().message | ||
case 500: | ||
throw new Errors.InternalServerError().message | ||
default: | ||
throw new Errors.UnexpectedError().message | ||
} | ||
} | ||
|
||
/** | ||
* @param {Object} errorSchema - The error schema. | ||
* @param {string} key - The error key of error schema. | ||
* @returns {string|undefined} The result message based on the status code. | ||
*/ | ||
const extractErrorKey = (errorSchema, key) => { | ||
if (typeof errorSchema[key][0] === 'string') { | ||
return `${key}: ${errorSchema[key][0]}` | ||
} | ||
const keyValuePair = [] | ||
errorSchema[key].forEach((obj) => { | ||
for (let key in obj) { | ||
// eslint-disable-next-line no-prototype-builtins | ||
if (obj.hasOwnProperty(key)) { | ||
keyValuePair.push({ key, value: obj[key][0] }) | ||
} | ||
} | ||
}) | ||
return `${keyValuePair[0].key}: ${keyValuePair[0].value}` | ||
} | ||
|
||
/** | ||
* @param {Object} httpResponse - The HTTP response object. | ||
* @param {Object} httpResponse.body - The response body. | ||
* @returns {string} The result message based on the status code. | ||
*/ | ||
const extractApiError = (httpResponse) => { | ||
const [firstKey] = Object.keys(httpResponse.body) | ||
const errorMessage = extractErrorKey(httpResponse.body, firstKey) | ||
|
||
return errorMessage | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/services/waf-rules-services/list-network-list-service.js
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,28 @@ | ||
import { AxiosHttpClientAdapter, parseHttpResponse } from '../axios/AxiosHttpClientAdapter' | ||
import { makeNetworkListBaseUrl } from '../network-lists-services/make-network-list-base-url' | ||
|
||
export const listNetworkListService = async () => { | ||
let httpResponse = await AxiosHttpClientAdapter.request({ | ||
url: `${makeNetworkListBaseUrl()}?pagination=false&exclude_azion_lists=true`, | ||
method: 'GET' | ||
}) | ||
|
||
httpResponse = adapt(httpResponse) | ||
return parseHttpResponse(httpResponse) | ||
} | ||
|
||
const adapt = (httpResponse) => { | ||
const isArray = Array.isArray(httpResponse.body.results) | ||
|
||
const networkList = isArray | ||
? httpResponse.body.results.map((networkList) => ({ | ||
id: networkList.id, | ||
name: networkList.name | ||
})) | ||
: [] | ||
|
||
return { | ||
body: networkList, | ||
statusCode: httpResponse.statusCode | ||
} | ||
} |
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.