-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[type:fix] configs import and export refactor (#5827)
Co-authored-by: aias00 <liuhongyu@apache.org>
- Loading branch information
Showing
43 changed files
with
1,149 additions
and
352 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...src/main/java/org/apache/shenyu/admin/service/configs/AuthConfigsExportImportHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.shenyu.admin.service.configs; | ||
|
||
import org.apache.commons.collections4.CollectionUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.shenyu.admin.model.dto.AppAuthDTO; | ||
import org.apache.shenyu.admin.model.result.ConfigImportResult; | ||
import org.apache.shenyu.admin.model.vo.AppAuthVO; | ||
import org.apache.shenyu.admin.service.AppAuthService; | ||
import org.apache.shenyu.common.constant.ExportImportConstants; | ||
import org.apache.shenyu.common.utils.GsonUtils; | ||
import org.apache.shenyu.common.utils.JsonUtils; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
|
||
@Component | ||
public class AuthConfigsExportImportHandler implements ConfigsExportImportHandler { | ||
|
||
private final AppAuthService appAuthService; | ||
|
||
public AuthConfigsExportImportHandler(final AppAuthService appAuthService) { | ||
this.appAuthService = appAuthService; | ||
} | ||
|
||
@Override | ||
public ConfigsExportImportEnum configsEnum() { | ||
return ConfigsExportImportEnum.Auth; | ||
} | ||
|
||
@Override | ||
public Optional<String> configsExport(final String namespaceId) { | ||
List<AppAuthVO> authDataList = appAuthService.listAllDataByNamespace(namespaceId); | ||
if (CollectionUtils.isNotEmpty(authDataList)) { | ||
authDataList.forEach(appAuthVO -> appAuthVO.setNamespaceId(null)); | ||
return Optional.of(JsonUtils.toJson(authDataList)); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public void configsImport(final String namespaceId, final String data, final ConfigsImportContext context) { | ||
List<AppAuthDTO> authDataList = GsonUtils.getInstance().fromList(data, AppAuthDTO.class); | ||
ConfigImportResult configImportResult = appAuthService.importData(namespaceId, authDataList); | ||
context.getResult().put(ExportImportConstants.AUTH_IMPORT_SUCCESS_COUNT, configImportResult.getSuccessCount()); | ||
if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) { | ||
context.getResult().put(ExportImportConstants.AUTH_IMPORT_FAIL_MESSAGE, configImportResult.getFailMessage()); | ||
} | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
...-admin/src/main/java/org/apache/shenyu/admin/service/configs/ConfigsExportImportEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.shenyu.admin.service.configs; | ||
|
||
public enum ConfigsExportImportEnum { | ||
|
||
/** | ||
* auth. | ||
*/ | ||
Auth("auth.json", 0), | ||
|
||
/** | ||
* meta. | ||
*/ | ||
Meta("meta.json", 1), | ||
|
||
/** | ||
* plugin template. | ||
*/ | ||
PluginTemplate("plugin_template.json", 2), | ||
|
||
/** | ||
* plugin handle. | ||
*/ | ||
PluginHandle("plugin_handle.json", 3), | ||
|
||
/** | ||
* namespace plugin. | ||
*/ | ||
NamespacePlugin("namespace_plugin.json", 4), | ||
|
||
/** | ||
* selector. | ||
*/ | ||
Selector("selector.json", 5), | ||
|
||
/** | ||
* rule. | ||
*/ | ||
Rule("rule.json", 6), | ||
|
||
/** | ||
* dict. | ||
*/ | ||
Dict("dict.json", 7), | ||
|
||
/** | ||
* proxy selector. | ||
*/ | ||
ProxySelector("proxy_selector.json", 8), | ||
|
||
/** | ||
* discovery. | ||
*/ | ||
Discovery("discovery.json", 9), | ||
|
||
/** | ||
* discovery upstream. | ||
*/ | ||
DiscoveryUpstream("discovery_upstream.json", 10); | ||
|
||
/** | ||
* zip item name. | ||
*/ | ||
private String configName; | ||
|
||
/** | ||
* the import order. | ||
* | ||
* @return The smaller, the earlier it will be executed | ||
*/ | ||
private int importOrder; | ||
|
||
ConfigsExportImportEnum(final String configName, final int importOrder) { | ||
this.configName = configName; | ||
this.importOrder = importOrder; | ||
} | ||
|
||
public String getConfigName() { | ||
return configName; | ||
} | ||
|
||
public int getImportOrder() { | ||
return importOrder; | ||
} | ||
} |
Oops, something went wrong.