mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 15:59:41 +02:00
63 lines
1.4 KiB
TypeScript
63 lines
1.4 KiB
TypeScript
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
|
|
|
import { PublicSettingsResponse, DefaultRegistry, Settings } from './types';
|
|
|
|
export async function getPublicSettings() {
|
|
try {
|
|
const { data } = await axios.get<PublicSettingsResponse>(
|
|
buildUrl('public')
|
|
);
|
|
return data;
|
|
} catch (e) {
|
|
throw parseAxiosError(
|
|
e as Error,
|
|
'Unable to retrieve application settings'
|
|
);
|
|
}
|
|
}
|
|
|
|
export async function getSettings() {
|
|
try {
|
|
const { data } = await axios.get<Settings>(buildUrl());
|
|
return data;
|
|
} catch (e) {
|
|
throw parseAxiosError(
|
|
e as Error,
|
|
'Unable to retrieve application settings'
|
|
);
|
|
}
|
|
}
|
|
|
|
export async function updateSettings(settings: Partial<Settings>) {
|
|
try {
|
|
await axios.put(buildUrl(), settings);
|
|
} catch (e) {
|
|
throw parseAxiosError(e as Error, 'Unable to update application settings');
|
|
}
|
|
}
|
|
|
|
export async function updateDefaultRegistry(
|
|
defaultRegistry: Partial<DefaultRegistry>
|
|
) {
|
|
try {
|
|
await axios.put(buildUrl('default_registry'), defaultRegistry);
|
|
} catch (e) {
|
|
throw parseAxiosError(
|
|
e as Error,
|
|
'Unable to update default registry settings'
|
|
);
|
|
}
|
|
}
|
|
|
|
function buildUrl(subResource?: string, action?: string) {
|
|
let url = 'settings';
|
|
if (subResource) {
|
|
url += `/${subResource}`;
|
|
}
|
|
|
|
if (action) {
|
|
url += `/${action}`;
|
|
}
|
|
|
|
return url;
|
|
}
|