-
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.
feat: add tab on the edit domain and add workload deployment
- Loading branch information
Showing
15 changed files
with
1,319 additions
and
227 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { AxiosHttpClientAdapter } from '../../axios/AxiosHttpClientAdapter' | ||
import { makeDomainsBaseUrl } from './make-domains-base-url' | ||
import * as Errors from '@/services/axios/errors' | ||
import { extractApiError } from '@/helpers/extract-api-error' | ||
|
||
export const editDomainService = async (payload) => { | ||
let httpResponse = await AxiosHttpClientAdapter.request({ | ||
url: `${makeDomainsBaseUrl()}/${payload.id}`, | ||
method: 'PATCH', | ||
body: adapt(payload) | ||
}) | ||
|
||
return parseHttpResponse(httpResponse) | ||
} | ||
|
||
const handleVersions = (useHttp3) => { | ||
if (useHttp3) { | ||
return ['http1', 'http2', 'http3'] | ||
} | ||
|
||
return ['http1', 'http2'] | ||
} | ||
|
||
const convertPortToInt = (ports) => { | ||
return ports.map((port) => parseInt(port.value)) | ||
} | ||
|
||
const adapt = (payload) => { | ||
payload.domains[0].allow_access = !payload.cnameAccessOnly | ||
const domains = payload.domains | ||
|
||
const dataRequest = { | ||
name: payload.name, | ||
alternate_domains: payload.cnames.split('\n').filter((item) => item !== ''), | ||
active: payload.active, | ||
tls: { | ||
ciphers: payload.supportedCiphers, | ||
minimum_version: payload.minimumTlsVersion | ||
}, | ||
protocols: { | ||
http: { | ||
versions: handleVersions(payload.useHttp3), | ||
http_ports: convertPortToInt(payload.httpPort), | ||
https_ports: payload.useHttps ? convertPortToInt(payload.httpsPort) : null, | ||
quic_ports: payload.useHttp3 ? convertPortToInt(payload.quicPort) : null | ||
} | ||
}, | ||
mtls: { | ||
verification: payload.mtlsVerification, | ||
certificate: payload.mtlsTrustedCertificate | ||
}, | ||
domains, | ||
network_map: payload.environment | ||
} | ||
if (payload.edgeCertificate !== 0) { | ||
dataRequest.tls.certificate = payload.edgeCertificate | ||
} | ||
|
||
return dataRequest | ||
} | ||
|
||
/** | ||
* @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 domain has been edited' | ||
case 500: | ||
throw new Errors.InternalServerError().message | ||
default: | ||
throw new Error(extractApiError(httpResponse)).message | ||
} | ||
} |
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
Oops, something went wrong.