mirror of
https://github.com/nextcloud/spreed.git
synced 2025-12-17 21:12:20 +01:00
Merge pull request #13876 from nextcloud/fix/noid/certificate-service-ts
This commit is contained in:
commit
9815309a80
4 changed files with 59 additions and 54 deletions
|
|
@ -89,7 +89,7 @@ import NcPasswordField from '@nextcloud/vue/dist/Components/NcPasswordField.js'
|
|||
import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js'
|
||||
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
|
||||
|
||||
import { isCertificateValid } from '../../services/certificateService.js'
|
||||
import { isCertificateValid } from '../../services/certificateService.ts'
|
||||
|
||||
export default {
|
||||
name: 'TurnServer',
|
||||
|
|
|
|||
|
|
@ -1,53 +0,0 @@
|
|||
/**
|
||||
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
import axios from '@nextcloud/axios'
|
||||
import { generateOcsUrl } from '@nextcloud/router'
|
||||
|
||||
/**
|
||||
* Retrieves the certificate expiration of the specified host
|
||||
*
|
||||
* @param {string} host The host to check the certificate
|
||||
* @return {number|null} Null if unable to retrieve the certificates expiration, otherwise the expiration in days (negative if already expired)
|
||||
*/
|
||||
const getCertificateExpiration = async (host) => {
|
||||
try {
|
||||
const response = await axios.get(generateOcsUrl('apps/spreed/api/v1/certificate/expiration'), {
|
||||
params: {
|
||||
host,
|
||||
},
|
||||
})
|
||||
|
||||
return response.data.ocs.data.expiration_in_days
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the certificate of a host is valid
|
||||
*
|
||||
* @param {string} host The host to check the certificate
|
||||
* @return {boolean} true if the certificate is valid, false otherwise
|
||||
*/
|
||||
const isCertificateValid = async (host) => {
|
||||
const expiration = await getCertificateExpiration(host)
|
||||
|
||||
if (expiration == null) {
|
||||
console.warn('Unable to check certificate of', host)
|
||||
} else if (expiration < 0) {
|
||||
console.error('Certificate of', host, 'expired')
|
||||
} else {
|
||||
console.info('Certificate of', host, 'is valid for', expiration, 'days')
|
||||
}
|
||||
|
||||
return expiration > 0
|
||||
}
|
||||
|
||||
export {
|
||||
getCertificateExpiration,
|
||||
isCertificateValid,
|
||||
}
|
||||
54
src/services/certificateService.ts
Normal file
54
src/services/certificateService.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
import axios from '@nextcloud/axios'
|
||||
import { generateOcsUrl } from '@nextcloud/router'
|
||||
|
||||
import type { certificateExpirationParams, certificateExpirationResponse } from '../types/index.ts'
|
||||
|
||||
/**
|
||||
* Retrieves the certificate expiration of the specified host
|
||||
*
|
||||
* @param host The host to check the certificate
|
||||
*/
|
||||
const getCertificateExpiration = async (host: certificateExpirationParams['host']): certificateExpirationResponse => {
|
||||
return axios.get(generateOcsUrl('apps/spreed/api/v1/certificate/expiration'), {
|
||||
params: {
|
||||
host,
|
||||
} as certificateExpirationParams,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the certificate of a host is valid
|
||||
*
|
||||
* @param host The host to check the certificate
|
||||
* @return {boolean} true if the certificate is valid, false otherwise
|
||||
*/
|
||||
const isCertificateValid = async (host: certificateExpirationParams['host']): Promise<boolean> => {
|
||||
try {
|
||||
const response = await getCertificateExpiration(host)
|
||||
|
||||
// Null if unable to retrieve the certificates expiration, otherwise the expiration in days (negative if already expired)
|
||||
const expiration = response.data.ocs.data.expiration_in_days
|
||||
|
||||
if (expiration == null) {
|
||||
console.warn('Unable to check certificate of', host)
|
||||
return false
|
||||
} else if (expiration < 0) {
|
||||
console.error('Certificate of', host, 'expired')
|
||||
} else {
|
||||
console.info('Certificate of', host, 'is valid for', expiration, 'days')
|
||||
}
|
||||
return expiration > 0
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
getCertificateExpiration,
|
||||
isCertificateValid,
|
||||
}
|
||||
|
|
@ -177,6 +177,10 @@ export type getBotsAdminResponse = ApiResponse<operations['bot-admin-list-bots']
|
|||
export type enableBotResponse = ApiResponse<operations['bot-enable-bot']['responses'][201]['content']['application/json']>
|
||||
export type disableBotResponse = ApiResponse<operations['bot-disable-bot']['responses'][200]['content']['application/json']>
|
||||
|
||||
// Certificate
|
||||
export type certificateExpirationParams = operations['certificate-get-certificate-expiration']['parameters']['query']
|
||||
export type certificateExpirationResponse = ApiResponse<operations['certificate-get-certificate-expiration']['responses'][200]['content']['application/json']>
|
||||
|
||||
// Federations
|
||||
export type FederationInvite = components['schemas']['FederationInvite']
|
||||
type FederationInviteRichParameters = {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue