fix: ssh key, template test
This commit is contained in:
@@ -1,55 +1,35 @@
|
||||
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 const GPU_SERVICE_PUBLIC_KEY_API = '/gpu-instance-ssh-public-keys/data';
|
||||
|
||||
export async function queryGPUServicePublicKeys(
|
||||
params: Global.K8sSearchParams,
|
||||
params: Global.SearchParams,
|
||||
options?: any
|
||||
) {
|
||||
return request<Global.K8sPageResponse<ListItem>>(
|
||||
GPU_SERVICE_PUBLIC_KEY_API(params.namespace || ''),
|
||||
{
|
||||
method: 'GET',
|
||||
params,
|
||||
cancelToken: options?.token
|
||||
}
|
||||
);
|
||||
return request<ListItem>(GPU_SERVICE_PUBLIC_KEY_API, {
|
||||
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), {
|
||||
export async function createGPUServicePublicKey(params: { data: FormData }) {
|
||||
return request<ListItem>(GPU_SERVICE_PUBLIC_KEY_API, {
|
||||
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 updateGPUServicePublicKey(params: { data: FormData }) {
|
||||
return request<ListItem>(`${GPU_SERVICE_PUBLIC_KEY_API}`, {
|
||||
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'
|
||||
}
|
||||
);
|
||||
export async function deleteGPUServicePublicKey(id: number) {
|
||||
return request(`${GPU_SERVICE_PUBLIC_KEY_API}/${id}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,31 +1,42 @@
|
||||
import { INPUT_WIDTH } from '@/constants';
|
||||
import { Textarea } from '@gpustack/core-ui';
|
||||
import { Input as CInput, Textarea, useAppUtils } from '@gpustack/core-ui';
|
||||
import { useIntl } from '@umijs/max';
|
||||
import { Button, Form, message } from 'antd';
|
||||
import React from 'react';
|
||||
import { Button, Form } from 'antd';
|
||||
import React, { useEffect } 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`;
|
||||
import useGetSshkey from './services/use-get-sshkey';
|
||||
import useUpdateSshkey from './services/use-update-sshkey';
|
||||
import { FormData } from './types';
|
||||
|
||||
const GPUServicePublicKeys: React.FC = () => {
|
||||
const intl = useIntl();
|
||||
const [form] = Form.useForm<PublicKeyFormData>();
|
||||
const [form] = Form.useForm<FormData>();
|
||||
const { getRuleMessage } = useAppUtils();
|
||||
const { fetchData: fetchSshkey } = useGetSshkey();
|
||||
const { fetchData: updateSshkey, loading: updating } = useUpdateSshkey();
|
||||
|
||||
useEffect(() => {
|
||||
fetchSshkey({ page: 1, perPage: 100 }).then((res) => {
|
||||
const data = res?.spec?.data || '';
|
||||
form.setFieldsValue({
|
||||
name: res?.name,
|
||||
spec: {
|
||||
data
|
||||
}
|
||||
});
|
||||
});
|
||||
}, []);
|
||||
|
||||
const handleSave = async () => {
|
||||
form.submit();
|
||||
};
|
||||
|
||||
const onFinish = async (values: FormData) => {
|
||||
try {
|
||||
await form.validateFields();
|
||||
message.success('操作成功');
|
||||
} catch {
|
||||
await updateSshkey({
|
||||
data: values
|
||||
});
|
||||
} catch (error) {
|
||||
// ignore
|
||||
}
|
||||
};
|
||||
@@ -36,12 +47,32 @@ const GPUServicePublicKeys: React.FC = () => {
|
||||
style={{ width: INPUT_WIDTH.large }}
|
||||
name="gpuServicePublicKeyForm"
|
||||
form={form}
|
||||
onFinish={onFinish}
|
||||
initialValues={{
|
||||
name: 'SSHPublicKey',
|
||||
spec: {
|
||||
data: ''
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Form.Item<PublicKeyFormData> name="public_key">
|
||||
<Form.Item<FormData> name="name" hidden>
|
||||
<CInput.Input />
|
||||
</Form.Item>
|
||||
<Form.Item<FormData>
|
||||
name={['spec', 'data']}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: getRuleMessage('input', 'gpuservice.publicKey.label')
|
||||
}
|
||||
]}
|
||||
>
|
||||
<Textarea
|
||||
required
|
||||
label="SSH Public Key"
|
||||
placeholder={PLACEHOLDER}
|
||||
label={intl.formatMessage({ id: 'gpuservice.publicKey.label' })}
|
||||
placeholder={intl.formatMessage({
|
||||
id: 'gpuservice.publicKey.placeholder'
|
||||
})}
|
||||
trim={false}
|
||||
alwaysFocus
|
||||
autoSize={{ minRows: 8, maxRows: 16 }}
|
||||
@@ -50,6 +81,7 @@ const GPUServicePublicKeys: React.FC = () => {
|
||||
</Form.Item>
|
||||
<Button
|
||||
type="primary"
|
||||
loading={updating}
|
||||
style={{ width: 120, marginTop: 24 }}
|
||||
onClick={handleSave}
|
||||
>
|
||||
|
||||
@@ -1,34 +1,17 @@
|
||||
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';
|
||||
import { FormData, ListItem } from '../types';
|
||||
|
||||
interface CreateSshkeyParams {
|
||||
name: string;
|
||||
data: string;
|
||||
data: FormData;
|
||||
}
|
||||
|
||||
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]
|
||||
createGPUServicePublicKey({ data: params.data }),
|
||||
[]
|
||||
);
|
||||
|
||||
const { detailData, loading, cancelRequest, fetchData } = useQueryData<
|
||||
|
||||
@@ -1,26 +1,20 @@
|
||||
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]
|
||||
(params: Global.SearchParams = { page: 1, perPage: 100 }, options?: any) =>
|
||||
queryGPUServicePublicKeys(params, options),
|
||||
[]
|
||||
);
|
||||
|
||||
const { detailData, loading, cancelRequest, fetchData } = useQueryData<
|
||||
Global.K8sPageResponse<ListItem>,
|
||||
Global.K8sSearchParams
|
||||
>({
|
||||
fetchDetail,
|
||||
key: 'sshkey'
|
||||
});
|
||||
const { detailData, loading, cancelRequest, fetchData } =
|
||||
useQueryData<ListItem>({
|
||||
fetchDetail,
|
||||
key: 'sshkey'
|
||||
});
|
||||
|
||||
return {
|
||||
detailData,
|
||||
|
||||
@@ -1,36 +1,17 @@
|
||||
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';
|
||||
import { FormData, ListItem } from '../types';
|
||||
|
||||
interface UpdateSshkeyParams {
|
||||
id: number;
|
||||
name: string;
|
||||
data: string;
|
||||
data: FormData;
|
||||
}
|
||||
|
||||
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]
|
||||
updateGPUServicePublicKey({ data: params.data }),
|
||||
[]
|
||||
);
|
||||
|
||||
const { detailData, loading, cancelRequest, fetchData } = useQueryData<
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
export interface FormData extends Global.K8sCommonData {
|
||||
data: string;
|
||||
export interface FormData {
|
||||
name: string;
|
||||
description: string;
|
||||
spec: {
|
||||
data: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ListItem extends FormData {
|
||||
|
||||
Reference in New Issue
Block a user