87 lines
2.3 KiB
JavaScript
87 lines
2.3 KiB
JavaScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import merge from 'merge-deep';
|
|
|
|
import testConfig from '@support/test_config';
|
|
|
|
import client from './client';
|
|
import {getResponseFromError} from './common';
|
|
import defaultServerConfig from './default_config.json';
|
|
|
|
// ****************************************************************
|
|
// System
|
|
// See https://api.mattermost.com/#tag/system
|
|
//
|
|
// Exported API function should have the following:
|
|
// - documented using JSDoc
|
|
// - meaningful description
|
|
// - match the referenced API endpoints
|
|
// - parameter/s defined by `@param`
|
|
// - return value defined by `@return`
|
|
// ****************************************************************
|
|
|
|
/**
|
|
* Check system health.
|
|
* See https://api.mattermost.com/#tag/system/paths/~1system~1ping/get
|
|
* @return {Object} returns {data} on success or {error, status} on error
|
|
*/
|
|
export const apiCheckSystemHealth = async () => {
|
|
try {
|
|
const response = await client.get('/api/v4/system/ping?get_server_status=true');
|
|
return {data: response.data};
|
|
} catch (err) {
|
|
return getResponseFromError(err);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Get configuration.
|
|
* See https://api.mattermost.com/#tag/system/paths/~1config/get
|
|
*/
|
|
export const apiGetConfig = async () => {
|
|
try {
|
|
const response = await client.get('/api/v4/config');
|
|
|
|
return {config: response.data};
|
|
} catch (err) {
|
|
return getResponseFromError(err);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Update configuration.
|
|
* See https://api.mattermost.com/#tag/system/paths/~1config/put
|
|
* @param {Object} newConfig - specific config to update
|
|
*/
|
|
export const apiUpdateConfig = async (newConfig = {}) => {
|
|
try {
|
|
const {config: currentConfig} = await apiGetConfig();
|
|
const config = merge(currentConfig, getDefaultConfig(), newConfig);
|
|
|
|
const response = await client.put(
|
|
'/api/v4/config',
|
|
config,
|
|
);
|
|
|
|
return {config: response.data};
|
|
} catch (err) {
|
|
return getResponseFromError(err);
|
|
}
|
|
};
|
|
|
|
const getDefaultConfig = () => {
|
|
const fromEnv = {
|
|
ServiceSettings: {SiteURL: testConfig.siteUrl},
|
|
};
|
|
|
|
return merge(defaultServerConfig, fromEnv);
|
|
};
|
|
|
|
export const System = {
|
|
apiCheckSystemHealth,
|
|
apiGetConfig,
|
|
apiUpdateConfig,
|
|
};
|
|
|
|
export default System;
|