Skip to content

Commit cd18ff9

Browse files
authored
fix: Add repo secret key validate (#514)
* fix: Create user remove default role * fix: The vxnet list is incomplete
1 parent c02c8bf commit cd18ff9

11 files changed

Lines changed: 81 additions & 40 deletions

File tree

src/components/Base/Modal/index.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
height: 32px;
5555
border-radius: 2px;
5656
background-color: $N0;
57-
box-shadow: 0 1px 2px 0 rgba(109, 53, 195, 0.15);
57+
// box-shadow: 0 1px 2px 0 rgba(109, 53, 195, 0.15);
5858
}
5959
& > textarea{
6060
box-sizing: border-box;

src/config/translation.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ const tsObj = {
5050
'Runtime Selector missing value': '环境选择器缺失值',
5151
'Invalid s3 url, should be like s3://s3.pek3a.qingstor.com/op-repo':
5252
'无效的s3网址,应该是这样: s3://s3.pek3a.qingstor.com/op-repo',
53+
'Information to be verified is incomplete!': '验证要求输入的信息不完整!',
54+
'Access key verification successfully': '访问密钥验证成功',
55+
'Access key verification fail': '访问密钥验证失败',
5356
'Create repo successfully': '创建仓库成功',
5457
'Modify repo successfully': '修改仓库成功',
5558
'Delete repo successfully.': '删除仓库成功',

src/pages/Admin/Repos/Add/index.jsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ export default class RepoAdd extends Component {
3737
}
3838
}
3939

40-
componentDidUpdate() {
41-
if (get(this.store, 'repoCreated.repo_id') && !this.store.isLoading) {
42-
history.back();
40+
handleSubmit = async e => {
41+
const { repoCreateStore } = this.props;
42+
const result = await repoCreateStore.handleSubmit(e);
43+
44+
if (!(result && result.err)) {
45+
setTimeout(() => history.back(), 1000);
4346
}
44-
}
47+
};
4548

4649
renderForm() {
4750
const { t } = this.props;
@@ -61,7 +64,7 @@ export default class RepoAdd extends Component {
6164
} = this.store;
6265

6366
return (
64-
<form className={styles.createForm} onSubmit={this.store.handleSubmit}>
67+
<form className={styles.createForm} onSubmit={this.handleSubmit}>
6568
<div>
6669
<label className={styles.name}>{t('Name')}</label>
6770
<Input
@@ -156,7 +159,7 @@ export default class RepoAdd extends Component {
156159
value={secretKey}
157160
onChange={this.store.changeSecretKey}
158161
/>
159-
<Button className={styles.add} onClick={this.store.handleValidateCredential}>
162+
<Button className={styles.add} onClick={this.store.validateRepoCredential}>
160163
{t('Validate')}
161164
</Button>
162165
</div>

src/pages/Admin/Users/index.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { Component } from 'react';
22
import { observer, inject } from 'mobx-react';
3+
import { toJS } from 'mobx';
34
import { Link } from 'react-router-dom';
45
import { translate } from 'react-i18next';
56
import classnames from 'classnames';
@@ -111,8 +112,7 @@ export default class Users extends Component {
111112
if (operateType === 'modify') {
112113
title = t('Modify User');
113114
}
114-
const emailRegexp =
115-
"[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)[\\w](?:[\\w-]*[\\w])?";
115+
const emailRegexp = '^[A-Za-z0-9._%-]+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}$';
116116

117117
return (
118118
<Modal
@@ -236,7 +236,7 @@ export default class Users extends Component {
236236
selectName
237237
} = userStore;
238238

239-
const data = userStore.users.toJSON();
239+
const data = toJS(userStore.users);
240240

241241
const columns = [
242242
{

src/pages/Home/index.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@ export default class Home extends Component {
2828
} else {
2929
rootStore.setNavFix(false);
3030
}
31-
32-
window.scroll({ top: 0 });
3331
}
3432

3533
async componentDidMount() {
3634
const { rootStore, appStore, categoryStore, match } = this.props;
3735
const { category, search } = match.params;
3836
const filterParams = { status: 'active', noLimit: true };
3937

38+
window.scroll({ top: 0 });
4039
await categoryStore.fetchAll();
4140

4241
if (!(category || search)) {

src/scss/index.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,6 @@
163163
pointer-events: none;
164164
}
165165

166-
input:-webkit-autofill,
167-
input:-webkit-autofill:hover,
168-
input:-webkit-autofill:focus {
169-
box-shadow:0 0 0 60px white inset;
170-
-webkit-text-fill-color: #878787;
171-
}
172-
173166
.CodeMirror {
174167
font-family: "roboto monospace", monospace, sans-serif;
175168
}

src/stores/app/deploy.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ ${this.yamlStr}`;
203203

204204
@action
205205
async fetchSubnets(runtimeId) {
206-
const result = await this.request.get(`clusters/subnets`, { runtime_id: runtimeId });
206+
const result = await this.request.get(`clusters/subnets`, {
207+
runtime_id: runtimeId,
208+
limit: this.maxLimit
209+
});
207210
this.subnets = get(result, 'subnet_set', []);
208211
this.subnetId = this.subnets[0] ? this.subnets[0].subnet_id : '';
209212
}

src/stores/repo/create.js

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,34 @@ export default class RepoCreateStore extends Store {
144144
.join('&');
145145
}
146146

147+
@action
148+
validateRepoCredential = async () => {
149+
if (!this.url || !this.accessKey || !this.secretKey) {
150+
return this.info(ts('Information to be verified is incomplete!'));
151+
}
152+
153+
// format s3 url
154+
const url = this.url.startsWith('s3://') ? this.url : `s3://${this.url}`;
155+
if (!s3UrlPattern.test(url)) {
156+
return this.info(ts('Invalid s3 url, should be like s3://s3.pek3a.qingstor.com/op-repo'));
157+
}
158+
159+
const params = {
160+
type: this.protocolType,
161+
url: url,
162+
credential: JSON.stringify({
163+
access_key_id: this.accessKey,
164+
secret_access_key: this.secretKey
165+
})
166+
};
167+
const result = await this.request.get('repos/validate', params);
168+
if (result && result.ok) {
169+
this.success(ts('Access key verification successfully'));
170+
} else {
171+
this.error(ts('Access key verification fail'));
172+
}
173+
};
174+
147175
@action
148176
handleSubmit = async e => {
149177
e.preventDefault();
@@ -216,10 +244,17 @@ export default class RepoCreateStore extends Store {
216244

217245
this.isLoading = true;
218246
if (this.repoId) {
219-
delete data.url;
220-
if (!accessKey) {
247+
if (!accessKey || !secretKey) {
248+
delete data.url;
221249
delete data.credential;
250+
} else {
251+
data.url = this.url;
252+
data.credential = JSON.stringify({
253+
access_key_id: accessKey,
254+
secret_access_key: secretKey
255+
});
222256
}
257+
223258
_.extend(data, { repo_id: this.repoId });
224259
await this.modifyRepo(data);
225260
} else {
@@ -230,24 +265,23 @@ export default class RepoCreateStore extends Store {
230265
this.success(ts('Modify repo successfully'));
231266
} else if (_.get(this, 'repoCreated.repo_id')) {
232267
this.success(ts('Create repo successfully'));
268+
} else {
269+
return this.repoCreated;
233270
}
234-
235-
// disable re-submit form in 1 sec
236-
setTimeout(() => {
237-
this.isLoading = false;
238-
}, 1000);
239271
};
240272

241273
@action
242274
async create(params) {
243275
params = typeof params === 'object' ? params : JSON.stringify(params);
244276
this.repoCreated = await this.request.post('repos', params);
277+
this.isLoading = false;
245278
}
246279

247280
@action
248281
async modifyRepo(params) {
249282
params = typeof params === 'object' ? params : JSON.stringify(params);
250283
this.repoCreated = await this.request.patch('repos', params);
284+
this.isLoading = false;
251285
}
252286

253287
@action
@@ -273,12 +307,16 @@ export default class RepoCreateStore extends Store {
273307

274308
@action
275309
setRepo = detail => {
310+
this.repoCreated = null;
311+
276312
if (detail) {
277313
this.repoId = detail.repo_id;
278314
this.name = detail.name;
279315
this.description = detail.description;
280316
this.url = detail.url;
281317
this.protocolType = detail.type;
318+
this.accessKey = '';
319+
this.secretKey = '';
282320
this.providers = detail.providers;
283321
this.visibility = detail.visibility;
284322
this.labels = detail.labels || [{ label_key: '', label_value: '' }];

src/stores/user/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default class UserStore extends Store {
4444
username: '',
4545
email: '',
4646
password: '',
47-
role: 'user',
47+
role: '',
4848
description: ''
4949
};
5050
@observable userId = '';
@@ -297,7 +297,7 @@ export default class UserStore extends Store {
297297
username: '',
298298
email: '',
299299
password: '',
300-
role: 'user',
300+
role: '',
301301
description: ''
302302
};
303303
};
@@ -347,7 +347,7 @@ export default class UserStore extends Store {
347347
username: '',
348348
email: '',
349349
password: '',
350-
role: 'user',
350+
role: '',
351351
description: ''
352352
};
353353
};

test/pages/Home.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ describe('Home', () => {
2121
categoryStore: {
2222
getCategoryApps: () => {},
2323
categories: []
24-
}
24+
},
25+
setNavFix: () => {}
2526
});
2627
});
2728

0 commit comments

Comments
 (0)