Skip to content

Commit

Permalink
Merge pull request #624 from aziontech/dev
Browse files Browse the repository at this point in the history
DEPLOY 2024.01.25
  • Loading branch information
csfeijo authored Jan 25, 2024
2 parents 07f46a2 + b2293f4 commit 0522f81
Show file tree
Hide file tree
Showing 50 changed files with 1,928 additions and 96 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azion-platform-kit",
"version": "1.8.0",
"version": "1.8.1",
"private": true,
"type": "module",
"repository": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Custom SelectButton
.p-selectbutton {
background: var(--surface-300) !important;
padding-inline: 0.75rem !important;
padding: 0.3rem;
border-radius: $borderRadius !important;

.p-button {
Expand All @@ -19,7 +19,6 @@
}

&.p-highlight {
padding-inline: 0.75rem !important;
background: var(--surface-0) !important;
border-color: none !important;
font-weight: 600 !important;
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/azion-documentation-catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const documentationCatalog = {
records: () => openSearchResult('records'),
waf: () => openSearchResult('waf'),
wafAllowed: () => openSearchResult('Allowed Rules'),
wafTuning: () => openSearchResult('Tuning')
wafTuning: () => openSearchResult('Tune')
}

export const documentationGuideProducts = {
Expand Down
12 changes: 10 additions & 2 deletions src/router/routes/waf-rules-routes/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Helpers from '@/helpers'
import * as WafRulesService from '@/services/waf-rules-services'
import { listCountriesService } from '@/services/network-lists-services'

/** @type {import('vue-router').RouteRecordRaw} */
export const wafRulesRoutes = {
Expand Down Expand Up @@ -55,14 +56,21 @@ export const wafRulesRoutes = {
loadWafRulesAllowedService: WafRulesService.loadWafRulesAllowedService,
editWafRulesAllowedService: WafRulesService.editWafRulesAllowedService,
documentationServiceAllowed: Helpers.documentationCatalog.wafAllowed,
listWafRulesAllowedService: WafRulesService.listWafRulesAllowedService
listWafRulesAllowedService: WafRulesService.listWafRulesAllowedService,
optionsRuleIds: WafRulesService.optionsRuleIds
},
wafServices: {
editWafRulesService: WafRulesService.editWafRulesService,
loadWafRulesService: WafRulesService.loadWafRulesService
},
wafTuning: {
documentationServiceTuning: Helpers.documentationCatalog.wafTuning
documentationServiceTuning: Helpers.documentationCatalog.wafTuning,
listWafRulesTuningService: WafRulesService.listWafRulesTuningService,
listNetworkListService: WafRulesService.listNetworkListService,
listCountriesService: listCountriesService,
listWafRulesDomainsService: WafRulesService.listWafRulesDomainsService,
createWafRulesAllowedTuningService: WafRulesService.createWafRulesAllowedTuningService,
listWafRulesTuningAttacksService: WafRulesService.listWafRulesTuningAttacksService
}
},
meta: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ const adapt = (payload) => {
return {
name: payload.name,
description: payload.description,
status: true
status: payload.status
}
}
26 changes: 23 additions & 3 deletions src/services/domains-services/list-domains-service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { AxiosHttpClientAdapter, parseHttpResponse } from '../axios/AxiosHttpClientAdapter'
import { makeDomainsBaseUrl } from './make-domains-base-url'
import { listEdgeApplicationsService } from '@/services/edge-application-services/list-edge-applications-service'

export const listDomainsService = async ({
orderBy = 'name',
sort = 'asc',
Expand All @@ -12,12 +14,14 @@ export const listDomainsService = async ({
method: 'GET'
})

httpResponse = adapt(httpResponse)
httpResponse = await adapt(httpResponse)

return parseHttpResponse(httpResponse)
}

const adapt = (httpResponse) => {
const adapt = async (httpResponse) => {
const edgeApplications = await listEdgeApplications()

const parsedDomains = httpResponse.body.results?.map((domain) => {
const cnames = domain.cnames.map((cname) => cname)?.join(',')
return {
Expand All @@ -32,12 +36,13 @@ const adapt = (httpResponse) => {
content: 'Inactive',
severity: 'danger'
},
activeSort: domain.is_active,
domainName: {
content: domain.domain_name
},
cnames: cnames,
edgeFirewallId: domain.edge_firewall_id,
edgeApplicationName: domain.name,
edgeApplicationName: getEdgeApplication(edgeApplications, domain.edge_application_id),
digitalCertificateId: domain.digital_certificate_id
}
})
Expand All @@ -57,3 +62,18 @@ const makeSearchParams = ({ orderBy, sort, page, pageSize }) => {

return searchParams
}

const listEdgeApplications = async () => {
const edgeApplications = await listEdgeApplicationsService({})

return edgeApplications.map((edgeApp) => ({ name: edgeApp.name, id: edgeApp.id }))
}

const getEdgeApplication = (edgeApplications, edge_application_id) => {
const edgeApplication = edgeApplications.filter((edgeapp) => edgeapp.id === edge_application_id)

if (edgeApplication.length > 0) {
return edgeApplication[0].name
}
return ''
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const adapt = (httpResponse) => {
return {
value: edgeFunction.id,
label: edgeFunction.name,
args: edgeFunction.json_args,
initiatorType: edgeFunction.initiator_type,
args: JSON.stringify(edgeFunction.json_args, null, '\t'),
initiatorType: edgeFunction.initiator_type
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const adapt = (httpResponse) => {
return {
value: edgeFunction.id,
label: edgeFunction.name,
args: edgeFunction.json_args,
initiatorType: edgeFunction.initiator_type,
args: JSON.stringify(edgeFunction.json_args, null, '\t'),
initiatorType: edgeFunction.initiator_type
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ const adapt = (payload) => {
const parseHttpResponse = (httpResponse) => {
switch (httpResponse.statusCode) {
case 202:
return 'Your waf rule allowed has been created'
return {
feedback: 'Your waf rule allowed has been created'
}

case 400:
const apiError = extractApiError(httpResponse)
throw new Error(apiError).message
Expand All @@ -62,8 +65,19 @@ const parseHttpResponse = (httpResponse) => {
* @returns {string|undefined} The result message based on the status code.
*/
const extractErrorKey = (errorSchema, key) => {
const [keyError] = Object.keys(errorSchema[key]?.[0])
return errorSchema[key]?.[0][keyError][0]
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}`
}

/**
Expand Down
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const deleteWafRulesAllowedService = async ({ wafId, allowedId }) => {
*/
const parseHttpResponse = (httpResponse) => {
switch (httpResponse.statusCode) {
case 200:
case 202:
return 'Waf rule allowed successfully deleted'
case 400:
throw new Errors.NotFoundError().message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const adapt = (payload) => {
*/
const parseHttpResponse = (httpResponse) => {
switch (httpResponse.statusCode) {
case 200:
case 202:
return 'Your waf rule allowed has been updated'
case 400:
const apiError = extractApiError(httpResponse)
Expand Down
15 changes: 13 additions & 2 deletions src/services/waf-rules-services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { deleteWafRulesAllowedService } from './delete-waf-rules-allowed-service
import { createWafRulesAllowedService } from './create-waf-rules-allowed-service'
import { loadWafRulesAllowedService } from './load-waf-rules-allowed-service'
import { editWafRulesAllowedService } from './edit-waf-rules-allowed-service'

import { listWafRulesTuningService } from './list-waf-rules-tuning-service'
import { listNetworkListService } from './list-network-list-service'
import { listWafRulesDomainsService } from './list-waf-rules-domain-service'
import { createWafRulesAllowedTuningService } from './create-waf-rules-allowed-tuning-service'
import { listWafRulesTuningAttacksService } from './list-waf-rules-tuning-attacks-service'
import { optionsRuleIds } from './ruleIdOptions'
export {
listWafRulesService,
deleteWafRulesService,
Expand All @@ -19,5 +24,11 @@ export {
deleteWafRulesAllowedService,
createWafRulesAllowedService,
loadWafRulesAllowedService,
editWafRulesAllowedService
editWafRulesAllowedService,
listWafRulesTuningService,
listNetworkListService,
listWafRulesDomainsService,
createWafRulesAllowedTuningService,
listWafRulesTuningAttacksService,
optionsRuleIds
}
28 changes: 28 additions & 0 deletions src/services/waf-rules-services/list-network-list-service.js
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
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AxiosHttpClientAdapter, parseHttpResponse } from '../axios/AxiosHttpClientAdapter'
import { makeWafRulesAllowedBaseUrl } from './make-waf-rules-allowed-base-url'

import { optionsRuleIds } from './ruleIdOptions'
export const listWafRulesAllowedService = async ({ wafId }) => {
let httpResponse = await AxiosHttpClientAdapter.request({
url: `${makeWafRulesAllowedBaseUrl()}/${wafId}/allowed_rules?page=1&page_size=100`,
url: `${makeWafRulesAllowedBaseUrl()}/${wafId}/allowed_rules?page=1&page_size=200`,
method: 'GET'
})

Expand Down Expand Up @@ -75,6 +75,7 @@ const adapt = (httpResponse) => {

const parsedWafRulesAllowed = isArray
? httpResponse.body.results.map((waf) => {
const ruleId = optionsRuleIds.find((rule) => rule.value === waf.rule_id).text
const parsedAllowed = {
id: waf.id,
lastEditor: waf.last_editor,
Expand All @@ -84,7 +85,7 @@ const adapt = (httpResponse) => {
matchZones: parseMatchZone(waf.match_zones),
path: waf.path,
reason: waf.reason,
ruleId: waf.rule_id === 0 ? '0 - All Rules' : waf.rule_id,
ruleId,
status: parseStatusData(waf.status),
useRegex: waf.use_regex
}
Expand Down
Loading

0 comments on commit 0522f81

Please sign in to comment.