Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add repo secret key validate #514

Merged
merged 2 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/Base/Modal/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
height: 32px;
border-radius: 2px;
background-color: $N0;
box-shadow: 0 1px 2px 0 rgba(109, 53, 195, 0.15);
// box-shadow: 0 1px 2px 0 rgba(109, 53, 195, 0.15);
}
& > textarea{
box-sizing: border-box;
Expand Down
3 changes: 3 additions & 0 deletions src/config/translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const tsObj = {
'Runtime Selector missing value': '环境选择器缺失值',
'Invalid s3 url, should be like s3://s3.pek3a.qingstor.com/op-repo':
'无效的s3网址,应该是这样: s3://s3.pek3a.qingstor.com/op-repo',
'Information to be verified is incomplete!': '验证要求输入的信息不完整!',
'Access key verification successfully': '访问密钥验证成功',
'Access key verification fail': '访问密钥验证失败',
'Create repo successfully': '创建仓库成功',
'Modify repo successfully': '修改仓库成功',
'Delete repo successfully.': '删除仓库成功',
Expand Down
15 changes: 9 additions & 6 deletions src/pages/Admin/Repos/Add/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ export default class RepoAdd extends Component {
}
}

componentDidUpdate() {
if (get(this.store, 'repoCreated.repo_id') && !this.store.isLoading) {
history.back();
handleSubmit = async e => {
const { repoCreateStore } = this.props;
const result = await repoCreateStore.handleSubmit(e);

if (!(result && result.err)) {
setTimeout(() => history.back(), 1000);
}
}
};

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

return (
<form className={styles.createForm} onSubmit={this.store.handleSubmit}>
<form className={styles.createForm} onSubmit={this.handleSubmit}>
<div>
<label className={styles.name}>{t('Name')}</label>
<Input
Expand Down Expand Up @@ -156,7 +159,7 @@ export default class RepoAdd extends Component {
value={secretKey}
onChange={this.store.changeSecretKey}
/>
<Button className={styles.add} onClick={this.store.handleValidateCredential}>
<Button className={styles.add} onClick={this.store.validateRepoCredential}>
{t('Validate')}
</Button>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Admin/Users/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component } from 'react';
import { observer, inject } from 'mobx-react';
import { toJS } from 'mobx';
import { Link } from 'react-router-dom';
import { translate } from 'react-i18next';
import classnames from 'classnames';
Expand Down Expand Up @@ -111,8 +112,7 @@ export default class Users extends Component {
if (operateType === 'modify') {
title = t('Modify User');
}
const emailRegexp =
"[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)[\\w](?:[\\w-]*[\\w])?";
const emailRegexp = '^[A-Za-z0-9._%-]+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}$';

return (
<Modal
Expand Down Expand Up @@ -236,7 +236,7 @@ export default class Users extends Component {
selectName
} = userStore;

const data = userStore.users.toJSON();
const data = toJS(userStore.users);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toJS is deprecated in mobx, recommend to use toJSON

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If use toJSON, modify user name will also change table list data. Becase observable lead to data bidirectional binding.


const columns = [
{
Expand Down
3 changes: 1 addition & 2 deletions src/pages/Home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ export default class Home extends Component {
} else {
rootStore.setNavFix(false);
}

window.scroll({ top: 0 });
}

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

window.scroll({ top: 0 });
await categoryStore.fetchAll();

if (!(category || search)) {
Expand Down
7 changes: 0 additions & 7 deletions src/scss/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,6 @@
pointer-events: none;
}

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
box-shadow:0 0 0 60px white inset;
-webkit-text-fill-color: #878787;
}

.CodeMirror {
font-family: "roboto monospace", monospace, sans-serif;
}
Expand Down
5 changes: 4 additions & 1 deletion src/stores/app/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ ${this.yamlStr}`;

@action
async fetchSubnets(runtimeId) {
const result = await this.request.get(`clusters/subnets`, { runtime_id: runtimeId });
const result = await this.request.get(`clusters/subnets`, {
runtime_id: runtimeId,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is add parameter limit, for fix query result more 10 datas.

limit: this.maxLimit
});
this.subnets = get(result, 'subnet_set', []);
this.subnetId = this.subnets[0] ? this.subnets[0].subnet_id : '';
}
Expand Down
52 changes: 45 additions & 7 deletions src/stores/repo/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,34 @@ export default class RepoCreateStore extends Store {
.join('&');
}

@action
validateRepoCredential = async () => {
if (!this.url || !this.accessKey || !this.secretKey) {
return this.info(ts('Information to be verified is incomplete!'));
}

// format s3 url
const url = this.url.startsWith('s3://') ? this.url : `s3://${this.url}`;
if (!s3UrlPattern.test(url)) {
return this.info(ts('Invalid s3 url, should be like s3://s3.pek3a.qingstor.com/op-repo'));
}

const params = {
type: this.protocolType,
url: url,
credential: JSON.stringify({
access_key_id: this.accessKey,
secret_access_key: this.secretKey
})
};
const result = await this.request.get('repos/validate', params);
if (result && result.ok) {
this.success(ts('Access key verification successfully'));
} else {
this.error(ts('Access key verification fail'));
}
};

@action
handleSubmit = async e => {
e.preventDefault();
Expand Down Expand Up @@ -216,10 +244,17 @@ export default class RepoCreateStore extends Store {

this.isLoading = true;
if (this.repoId) {
delete data.url;
if (!accessKey) {
if (!accessKey || !secretKey) {
delete data.url;
delete data.credential;
} else {
data.url = this.url;
data.credential = JSON.stringify({
access_key_id: accessKey,
secret_access_key: secretKey
});
}

_.extend(data, { repo_id: this.repoId });
await this.modifyRepo(data);
} else {
Expand All @@ -230,24 +265,23 @@ export default class RepoCreateStore extends Store {
this.success(ts('Modify repo successfully'));
} else if (_.get(this, 'repoCreated.repo_id')) {
this.success(ts('Create repo successfully'));
} else {
return this.repoCreated;
}

// disable re-submit form in 1 sec
setTimeout(() => {
this.isLoading = false;
}, 1000);
};

@action
async create(params) {
params = typeof params === 'object' ? params : JSON.stringify(params);
this.repoCreated = await this.request.post('repos', params);
this.isLoading = false;
}

@action
async modifyRepo(params) {
params = typeof params === 'object' ? params : JSON.stringify(params);
this.repoCreated = await this.request.patch('repos', params);
this.isLoading = false;
}

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

@action
setRepo = detail => {
this.repoCreated = null;

if (detail) {
this.repoId = detail.repo_id;
this.name = detail.name;
this.description = detail.description;
this.url = detail.url;
this.protocolType = detail.type;
this.accessKey = '';
this.secretKey = '';
this.providers = detail.providers;
this.visibility = detail.visibility;
this.labels = detail.labels || [{ label_key: '', label_value: '' }];
Expand Down
6 changes: 3 additions & 3 deletions src/stores/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class UserStore extends Store {
username: '',
email: '',
password: '',
role: 'user',
role: '',
description: ''
};
@observable userId = '';
Expand Down Expand Up @@ -297,7 +297,7 @@ export default class UserStore extends Store {
username: '',
email: '',
password: '',
role: 'user',
role: '',
description: ''
};
};
Expand Down Expand Up @@ -347,7 +347,7 @@ export default class UserStore extends Store {
username: '',
email: '',
password: '',
role: 'user',
role: '',
description: ''
};
};
Expand Down
3 changes: 2 additions & 1 deletion test/pages/Home.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ describe('Home', () => {
categoryStore: {
getCategoryApps: () => {},
categories: []
}
},
setNavFix: () => {}
});
});

Expand Down
19 changes: 10 additions & 9 deletions test/pages/__snapshots__/Home.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ Array [
/>
</div>
<div
class="appList apps"
class="apps"
>
<div
class="title"
/>
<div
class="appsRow"
/>
<div
class="noData"
/>
class="appList"
>
<div
class="title"
/>
<div
class="noData"
/>
</div>
</div>
</div>,
]
Expand Down