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

Summer ospp#12017 refactor controller #12813

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
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void getConfig(HttpServletRequest request, HttpServletResponse response,
@Secured(action = ActionTypes.WRITE, signType = SignType.CONFIG)
public Result<Boolean> publishConfig(ConfigForm configForm, HttpServletRequest request) throws NacosException {
// check required field
configForm.validate();
configForm.validateWithContent();
String encryptedDataKeyFinal = configForm.getEncryptedDataKey();
if (StringUtils.isBlank(encryptedDataKeyFinal)) {
// encrypted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@
import com.alibaba.nacos.api.exception.api.NacosApiException;
import com.alibaba.nacos.api.model.v2.ErrorCode;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.core.model.form.NacosForm;
import org.springframework.http.HttpStatus;

import java.io.Serializable;
import java.util.Objects;

/**
* ConfigForm.
*
* @author dongyafei
* @date 2022/7/24
* @author xiweng.yy
*/
public class ConfigForm implements Serializable {
public class ConfigForm implements NacosForm {

private static final long serialVersionUID = 4124932564086863921L;

Expand Down Expand Up @@ -197,51 +195,24 @@ public void setEncryptedDataKey(String encryptedDataKey) {
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ConfigForm configForm = (ConfigForm) o;
return dataId.equals(configForm.dataId) && group.equals(configForm.group) && Objects.equals(namespaceId, configForm.namespaceId)
&& content.equals(configForm.content) && Objects.equals(tag, configForm.tag) && Objects
.equals(appName, configForm.appName) && Objects.equals(srcUser, configForm.srcUser) && Objects
.equals(configTags, configForm.configTags) && Objects.equals(desc, configForm.desc) && Objects.equals(
use, configForm.use) && Objects.equals(effect, configForm.effect) && Objects.equals(type,
configForm.type) && Objects.equals(schema, configForm.schema) && Objects.equals(encryptedDataKey,
configForm.encryptedDataKey);
}

@Override
public int hashCode() {
return Objects.hash(dataId, group, namespaceId, content, tag, appName, srcUser, configTags, desc, use, effect, type,
schema, encryptedDataKey);
}

@Override
public String toString() {
return "ConfigVo{" + "dataId='" + dataId + '\'' + ", group='" + group + '\'' + ", namespaceId='" + namespaceId + '\''
+ ", content='" + content + '\'' + ", tag='" + tag + '\'' + ", appName='" + appName + '\''
+ ", srcUser='" + srcUser + '\'' + ", configTags='" + configTags + '\'' + ", desc='" + desc + '\''
+ ", use='" + use + '\'' + ", effect='" + effect + '\'' + ", type='" + type + '\'' + ", schema='"
+ schema + '\'' + ", encryptedDataKey='" + encryptedDataKey + '\'' + '}';
}

/**
* Validate.
*
* @throws NacosApiException NacosApiException.
*/
public void validate() throws NacosApiException {
if (StringUtils.isBlank(dataId)) {
throw new NacosApiException(HttpStatus.BAD_REQUEST.value(), ErrorCode.PARAMETER_MISSING,
"Required parameter 'dataId' type String is not present");
} else if (StringUtils.isBlank(group)) {
throw new NacosApiException(HttpStatus.BAD_REQUEST.value(), ErrorCode.PARAMETER_MISSING,
"Required parameter 'group' type String is not present");
} else if (StringUtils.isBlank(content)) {
}
}

/**
* Validate form parameter and include validate `content` parameters.
*
* @throws NacosApiException NacosApiException
*/
public void validateWithContent() throws NacosApiException {
validate();
if (StringUtils.isBlank(content)) {
throw new NacosApiException(HttpStatus.BAD_REQUEST.value(), ErrorCode.PARAMETER_MISSING,
"Required parameter 'content' type String is not present");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 1999-2023 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.config.server.model.form;

import com.alibaba.nacos.api.exception.api.NacosApiException;
import com.alibaba.nacos.api.model.v2.ErrorCode;
import com.alibaba.nacos.common.utils.StringUtils;
import org.springframework.http.HttpStatus;

/**
* Nacos HTTP config form v3, use `groupName` replace `group`.
*
* @author xiweng.yy
*/
public class ConfigFormV3 extends ConfigForm {

private static final long serialVersionUID = 1105715502736280287L;

private String groupName;

public String getGroupName() {
return groupName;
}

public void setGroupName(String groupName) {
this.groupName = groupName;
}

@Override
public void validate() throws NacosApiException {
if (StringUtils.isBlank(groupName)) {
throw new NacosApiException(HttpStatus.BAD_REQUEST.value(), ErrorCode.PARAMETER_MISSING,
"Required parameter 'groupName' type String is not present");
}
super.setGroup(groupName);
super.validate();
}

/**
* Validate for blur search API, which allow user input empty groupName and dataId to search all configs.
*
* @throws NacosApiException when form parameters is invalid.
*/
public void blurSearchValidate() throws NacosApiException {
if (null == groupName) {
groupName = StringUtils.EMPTY;
super.setGroup(groupName);
}
if (null == getDataId()) {
setDataId(StringUtils.EMPTY);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class ConfigBlurSearchHttpParamExtractor extends AbstractHttpParamExtract
public List<ParamInfo> extractParam(HttpServletRequest request) {
String searchMode = request.getParameter("search");
ArrayList<ParamInfo> paramInfos = new ArrayList<>();
// TODO might replace '*' to empty char '' and still do check.
if (StringUtils.equals(searchMode, BLUR_SEARCH_MODE)) {
return paramInfos;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ private String getAliasDataId(HttpServletRequest request) {
}

private String getAliasGroup(HttpServletRequest request) {
String group = request.getParameter("group");
String group = request.getParameter("groupName");
if (StringUtils.isBlank(group)) {
group = request.getParameter("group");
}
return group;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class EditorNameSpace extends React.Component {
url: 'v3/console/core/namespace',
contentType: 'application/x-www-form-urlencoded',
data: {
customNamespaceId: values.namespace,
namespaceId: values.namespace,
namespaceName: values.namespaceShowName,
namespaceDesc: values.namespaceDesc,
},
Expand Down
4 changes: 2 additions & 2 deletions console-ui/src/locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ const I18N_CONF = {
queryResults: 'Found',
articleMeetRequirements: 'configuration items',
fuzzydMode: 'Default fuzzy query mode',
fuzzyd: "Add wildcard '*' for fuzzy query",
fuzzyd: 'Accurate query mode opened',
defaultFuzzyd: 'Default fuzzy query mode opened',
fuzzyg: "Add wildcard '*' for fuzzy query",
fuzzyg: 'Accurate query mode opened',
defaultFuzzyg: 'Default fuzzy query mode opened',
query: 'Search',
advancedQuery9: 'Advanced Query',
Expand Down
4 changes: 2 additions & 2 deletions console-ui/src/locales/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ const I18N_CONF = {
queryResults: '查询到',
articleMeetRequirements: '条满足要求的配置。',
fuzzydMode: '默认模糊匹配',
fuzzyd: "添加通配符'*'进行模糊查询",
fuzzyd: '已关闭模糊搜索',
defaultFuzzyd: '已开启默认模糊查询',
fuzzyg: "添加通配符'*'进行模糊查询",
fuzzyg: '已关闭模糊搜索',
defaultFuzzyg: '已开启默认模糊查询',
query: '查询',
advancedQuery9: '高级查询',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class ConfigDetail extends React.Component {
this.namespaceId = getParams('namespace') || '';
this.edasAppName = getParams('edasAppName') || '';
this.inApp = this.edasAppName;
const url = `v3/console/cs/config?&dataId=${this.dataId}&group=${this.group}`;
const url = `v3/console/cs/config?&dataId=${this.dataId}&groupName=${this.group}`;
request({
url,
beforeSend() {
Expand Down Expand Up @@ -226,7 +226,7 @@ class ConfigDetail extends React.Component {
let self = this;
const { locale = {} } = this.props;
let leftvalue = this.monacoEditor.getValue();
let url = `v3/console/cs/history/previous?id=${this.valueMap.normal.id}&dataId=${this.dataId}&group=${this.group}`;
let url = `v3/console/cs/history/previous?id=${this.valueMap.normal.id}&dataId=${this.dataId}&groupName=${this.group}`;
request({
url,
beforeSend() {
Expand Down Expand Up @@ -254,7 +254,7 @@ class ConfigDetail extends React.Component {
let leftvalue = this.monacoEditor.getValue();
const params = {
// show: 'all',
group,
groupName: group,
dataId,
namespaceId,
};
Expand All @@ -265,7 +265,7 @@ class ConfigDetail extends React.Component {
rightvalue = rightvalue.replace(/\r\n/g, '\n').replace(/\n/g, '\r\n');
self.compareEditorDialog.current.getInstance().openDialog(leftvalue, rightvalue);
} else {
Dialog.alert({ title: locale.error, content: locale.configNotFind });
Dialog.alert({ title: locale.error, content: locale.configNotFind });
}
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ class ConfigEditor extends React.Component {
this.serverId = getParams('serverId') || '';
this.tenant = getParams('namespace') || ''; // 为当前实例保存tenant参数
this.props.history.push(
`${url}?serverId=${this.serverId || ''}&dataId=${this.dataId}&group=${this.group}&namespace=${
this.tenant
}`
`${url}?serverId=${this.serverId || ''}&dataId=${this.dataId}&groupName=${
this.group
}&namespace=${this.tenant}`
);
}

Expand All @@ -184,7 +184,7 @@ class ConfigEditor extends React.Component {
const self = this;
this.tenant = getParams('namespace') || '';
this.serverId = getParams('serverId') || 'center';
const url = `v3/console/cs/config?dataId=${this.dataId}&group=${this.group}`;
const url = `v3/console/cs/config?dataId=${this.dataId}&groupName=${this.group}`;
request({
url,
beforeSend() {
Expand Down Expand Up @@ -367,7 +367,7 @@ class ConfigEditor extends React.Component {
const payload = {
dataId: this.field.getValue('dataId'),
appName: this.inApp ? this.edasAppId : this.field.getValue('appName'),
group: this.field.getValue('group'),
groupName: this.field.getValue('group'),
desc: this.field.getValue('desc'),
configTags: this.state.config_tags.join(','),
type: this.state.configType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,10 @@ class ConfigEditor extends React.Component {
Object.keys(form).forEach(key => {
payload[key] = form[key];
});
payload.groupName = form.group;
let configTags = this.state.form.config_tags;
if (configTags.length > 0) {
payload.config_tags = configTags.join(',');
payload.configTags = configTags.join(',');
}
// #12046 console-ui should not offer encryptedDataKey field to API
payload.encryptedDataKey = '';
Expand Down Expand Up @@ -319,7 +320,7 @@ class ConfigEditor extends React.Component {
.delete('v3/console/cs/config/beta', {
params: {
dataId,
group,
groupName: group,
namespaceId,
},
})
Expand Down Expand Up @@ -390,7 +391,7 @@ class ConfigEditor extends React.Component {
const { dataId, group } = this.state.form;
const params = {
dataId,
group,
groupName: group,
namespaceId: namespace,
tenant: namespace,
};
Expand All @@ -416,7 +417,7 @@ class ConfigEditor extends React.Component {
const { dataId, group } = this.state.form;
const params = {
dataId,
group,
groupName: group,
namespaceId: namespace,
tenant: namespace,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ConfigRollback extends React.Component {
const self = this;
this.namespaceId = getParams('namespace') || '';
this.serverId = getParams('serverId') || 'center';
const url = `v3/console/cs/history?dataId=${this.dataId}&group=${this.group}&nid=${this.nid}`;
const url = `v3/console/cs/history?dataId=${this.dataId}&groupName=${this.group}&nid=${this.nid}`;
request({
url,
success(result) {
Expand Down Expand Up @@ -141,14 +141,14 @@ class ConfigRollback extends React.Component {
let postData = {
appName: self.field.getValue('appName'),
dataId: self.dataId,
group: self.group,
groupName: self.group,
content: self.field.getValue('content'),
namespaceId: self.tenant,
};

let url = 'v3/console/cs/config';
if (self.opType.trim() === 'I') {
url = `v3/console/cs/config?dataId=${self.dataId}&group=${self.group}`;
url = `v3/console/cs/config?dataId=${self.dataId}&groupName=${self.group}`;
postData = {};
}

Expand Down
Loading
Loading