fix: storage api alignment
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import { request } from '@umijs/max';
|
||||
import { FormData, ListItem } from '../types';
|
||||
|
||||
export const GPU_SERVICE_PUBLIC_KEY_API = (namespace: string) =>
|
||||
`/proxy/apis/worker.gpustack.ai/v1/namespaces/${namespace}/instancesshpublickeys`;
|
||||
|
||||
export async function queryGPUServicePublicKeys(
|
||||
params: Global.K8sSearchParams,
|
||||
options?: any
|
||||
) {
|
||||
return request<Global.K8sPageResponse<ListItem>>(
|
||||
GPU_SERVICE_PUBLIC_KEY_API(params.namespace || ''),
|
||||
{
|
||||
method: 'GET',
|
||||
params,
|
||||
cancelToken: options?.token
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export async function createGPUServicePublicKey(params: {
|
||||
namespace: string;
|
||||
data: FormData;
|
||||
}) {
|
||||
return request<ListItem>(GPU_SERVICE_PUBLIC_KEY_API(params.namespace), {
|
||||
method: 'POST',
|
||||
data: params.data
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateGPUServicePublicKey(params: {
|
||||
namespace: string;
|
||||
id: number;
|
||||
data: FormData;
|
||||
}) {
|
||||
return request<ListItem>(
|
||||
`${GPU_SERVICE_PUBLIC_KEY_API(params.namespace)}/${params.id}`,
|
||||
{
|
||||
method: 'PUT',
|
||||
data: params.data
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export async function deleteGPUServicePublicKey(params: {
|
||||
namespace: string;
|
||||
id: number;
|
||||
}) {
|
||||
return request(
|
||||
`${GPU_SERVICE_PUBLIC_KEY_API(params.namespace)}/${params.id}`,
|
||||
{
|
||||
method: 'DELETE'
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { INPUT_WIDTH } from '@/constants';
|
||||
import { Textarea } from '@gpustack/core-ui';
|
||||
import { useIntl } from '@umijs/max';
|
||||
import { Button, Form, message } from 'antd';
|
||||
import React from 'react';
|
||||
import PageBox from '../../_components/page-box';
|
||||
|
||||
interface PublicKeyFormData {
|
||||
public_key?: string;
|
||||
}
|
||||
|
||||
const PLACEHOLDER = `以 ssh-rsa 或 ssh-ed25519 开头,每个 Public Key 单独一行
|
||||
|
||||
查看 Public Key:
|
||||
- RSA
|
||||
cat ~/.ssh/id_rsa.pub
|
||||
- Ed25519
|
||||
cat ~/.ssh/id_ed25519.pub`;
|
||||
|
||||
const GPUServicePublicKeys: React.FC = () => {
|
||||
const intl = useIntl();
|
||||
const [form] = Form.useForm<PublicKeyFormData>();
|
||||
|
||||
const handleSave = async () => {
|
||||
try {
|
||||
await form.validateFields();
|
||||
message.success('操作成功');
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<PageBox>
|
||||
<Form
|
||||
style={{ width: INPUT_WIDTH.large }}
|
||||
name="gpuServicePublicKeyForm"
|
||||
form={form}
|
||||
>
|
||||
<Form.Item<PublicKeyFormData> name="public_key">
|
||||
<Textarea
|
||||
required
|
||||
label="SSH Public Key"
|
||||
placeholder={PLACEHOLDER}
|
||||
trim={false}
|
||||
alwaysFocus
|
||||
autoSize={{ minRows: 8, maxRows: 16 }}
|
||||
style={{ width: INPUT_WIDTH.large }}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Button
|
||||
type="primary"
|
||||
style={{ width: 120, marginTop: 24 }}
|
||||
onClick={handleSave}
|
||||
>
|
||||
{intl.formatMessage({ id: 'common.button.save' })}
|
||||
</Button>
|
||||
</Form>
|
||||
</PageBox>
|
||||
);
|
||||
};
|
||||
|
||||
export default GPUServicePublicKeys;
|
||||
@@ -0,0 +1,48 @@
|
||||
import { useModel } from '@@/plugin-model';
|
||||
import { useQueryData } from '@gpustack/core-ui';
|
||||
import { useCallback } from 'react';
|
||||
import { apiVersion, KindMapping } from '../../constants';
|
||||
import { createGPUServicePublicKey } from '../apis';
|
||||
import { ListItem } from '../types';
|
||||
|
||||
interface CreateSshkeyParams {
|
||||
name: string;
|
||||
data: string;
|
||||
}
|
||||
|
||||
export default function useCreateSshkey() {
|
||||
const { initialState } = useModel('@@initialState');
|
||||
const namespace = initialState?.currentUser?.org_name || 'default';
|
||||
|
||||
const fetchDetail = useCallback(
|
||||
(params: CreateSshkeyParams) =>
|
||||
createGPUServicePublicKey({
|
||||
namespace,
|
||||
data: {
|
||||
apiVersion,
|
||||
kind: KindMapping.sshPublicKey,
|
||||
metadata: {
|
||||
name: params.name,
|
||||
namespace
|
||||
},
|
||||
data: params.data
|
||||
}
|
||||
}),
|
||||
[namespace]
|
||||
);
|
||||
|
||||
const { detailData, loading, cancelRequest, fetchData } = useQueryData<
|
||||
ListItem,
|
||||
CreateSshkeyParams
|
||||
>({
|
||||
fetchDetail,
|
||||
key: 'createSshkey'
|
||||
});
|
||||
|
||||
return {
|
||||
detailData,
|
||||
loading,
|
||||
cancelRequest,
|
||||
fetchData
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { useModel } from '@@/plugin-model';
|
||||
import { useQueryData } from '@gpustack/core-ui';
|
||||
import { useCallback } from 'react';
|
||||
import { queryGPUServicePublicKeys } from '../apis';
|
||||
import { ListItem } from '../types';
|
||||
|
||||
export default function useGetSshkey() {
|
||||
const { initialState } = useModel('@@initialState');
|
||||
const namespace = initialState?.currentUser?.org_name || 'default';
|
||||
|
||||
const fetchDetail = useCallback(
|
||||
(params: Global.K8sSearchParams = {}, options?: any) =>
|
||||
queryGPUServicePublicKeys({ ...params, namespace }, options),
|
||||
[namespace]
|
||||
);
|
||||
|
||||
const { detailData, loading, cancelRequest, fetchData } = useQueryData<
|
||||
Global.K8sPageResponse<ListItem>,
|
||||
Global.K8sSearchParams
|
||||
>({
|
||||
fetchDetail,
|
||||
key: 'sshkey'
|
||||
});
|
||||
|
||||
return {
|
||||
detailData,
|
||||
loading,
|
||||
cancelRequest,
|
||||
fetchData
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import { useModel } from '@@/plugin-model';
|
||||
import { useQueryData } from '@gpustack/core-ui';
|
||||
import { useCallback } from 'react';
|
||||
import { apiVersion, KindMapping } from '../../constants';
|
||||
import { updateGPUServicePublicKey } from '../apis';
|
||||
import { ListItem } from '../types';
|
||||
|
||||
interface UpdateSshkeyParams {
|
||||
id: number;
|
||||
name: string;
|
||||
data: string;
|
||||
}
|
||||
|
||||
export default function useUpdateSshkey() {
|
||||
const { initialState } = useModel('@@initialState');
|
||||
const namespace = initialState?.currentUser?.org_name || 'default';
|
||||
|
||||
const fetchDetail = useCallback(
|
||||
(params: UpdateSshkeyParams) =>
|
||||
updateGPUServicePublicKey({
|
||||
namespace,
|
||||
id: params.id,
|
||||
data: {
|
||||
apiVersion,
|
||||
kind: KindMapping.sshPublicKey,
|
||||
metadata: {
|
||||
name: params.name,
|
||||
namespace
|
||||
},
|
||||
data: params.data
|
||||
}
|
||||
}),
|
||||
[namespace]
|
||||
);
|
||||
|
||||
const { detailData, loading, cancelRequest, fetchData } = useQueryData<
|
||||
ListItem,
|
||||
UpdateSshkeyParams
|
||||
>({
|
||||
fetchDetail,
|
||||
key: 'updateSshkey'
|
||||
});
|
||||
|
||||
return {
|
||||
detailData,
|
||||
loading,
|
||||
cancelRequest,
|
||||
fetchData
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
export interface FormData extends Global.K8sCommonData {
|
||||
data: string;
|
||||
}
|
||||
|
||||
export interface ListItem extends FormData {
|
||||
id: number;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user