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

[AMORO-3038] Unify the API set for dashboard and open API #3244

Merged
merged 1 commit into from
Oct 14, 2024
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 @@ -74,6 +74,8 @@ public class DashboardServer {
public static final Logger LOG = LoggerFactory.getLogger(DashboardServer.class);

private static final String AUTH_TYPE_BASIC = "basic";
private static final String X_REQUEST_SOURCE_HEADER = "X-Request-Source";
private static final String X_REQUEST_SOURCE_WEB = "Web";

private final CatalogController catalogController;
private final HealthCheckController healthCheckController;
Expand Down Expand Up @@ -189,14 +191,13 @@ public EndpointGroup endpoints() {

// for dashboard api
path(
"/ams/v1",
"/api/ams/v1",
() -> {
// login controller
get("/login/current", loginController::getCurrent);
post("/login", loginController::login);
post("/logout", loginController::logout);
});
path("ams/v1", apiGroup());

// for open api
path("/api/ams/v1", apiGroup());
Expand Down Expand Up @@ -356,7 +357,8 @@ private EndpointGroup apiGroup() {

public void preHandleRequest(Context ctx) {
String uriPath = ctx.path();
if (needApiKeyCheck(uriPath)) {
String requestSource = ctx.header(X_REQUEST_SOURCE_HEADER);
if (needApiKeyCheck(uriPath) && !X_REQUEST_SOURCE_WEB.equalsIgnoreCase(requestSource)) {
if (AUTH_TYPE_BASIC.equalsIgnoreCase(authType)) {
BasicAuthCredentials cred = ctx.basicAuthCredentials();
if (!(basicAuthUser.equals(cred.component1())
Expand Down Expand Up @@ -392,10 +394,10 @@ public void handleException(Exception e, Context ctx) {
}

private static final String[] urlWhiteList = {
"/ams/v1/versionInfo",
"/ams/v1/login",
"/ams/v1/health/status",
"/ams/v1/login/current",
"/api/ams/v1/versionInfo",
"/api/ams/v1/login",
"/api/ams/v1/health/status",
"/api/ams/v1/login/current",
"/",
"/overview",
"/introduce",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ public void deleteCatalog(Context ctx) {
/** Construct a url */
private String constructCatalogConfigFileUrl(String catalogName, String type, String key) {
return String.format(
"/ams/v1/catalogs/%s/config/%s/%s", catalogName, type, key.replaceAll("\\.", "-"));
"/api/ams/v1/catalogs/%s/config/%s/%s", catalogName, type, key.replaceAll("\\.", "-"));
}

/** Get the config file content uri("/catalogs/{catalogName}/config/{type}/{key} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void uploadFile(Context ctx) throws IOException {
Integer fid = platformFileInfoService.addFile(name, content);
Map<String, String> result = new HashMap<>();
result.put("id", String.valueOf(fid));
result.put("url", "/ams/v1/files/" + fid);
result.put("url", "/api/ams/v1/files/" + fid);
ctx.json(OkResponse.of(result));
}

Expand Down
26 changes: 13 additions & 13 deletions amoro-web/mock/modules/catalogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

export default [
{
url: '/mock/ams/v1/catalogs',
url: '/mock/api/ams/v1/catalogs',
method: 'get',
response: () => ({
"message": "success",
Expand Down Expand Up @@ -56,27 +56,27 @@ export default [
}),
},
{
url: '/mock/ams/v1/catalogs',
url: '/mock/api/ams/v1/catalogs',
method: 'post',
response: () => ({"message":"success","code":200,"result":""}),
},

{
url: '/mock/ams/v1/catalogs/test_catalog/databases',
url: '/mock/api/ams/v1/catalogs/test_catalog/databases',
method: 'get',
response: () => {
return { "message": "success", "code": 200, "result": ["db", "test", "acc"] }
},
},
{
url: '/mock/ams/v1/catalogs/test_catalog/databases/db/tables',
url: '/mock/api/ams/v1/catalogs/test_catalog/databases/db/tables',
method: 'get',
response: () => {
return { "message": "success", "code": 200, "result": [{ "name": "user", "type": "ICEBERG" },{ "name": "wf", "type": "ICEBERG" }, { "name": "xcvz", "type": "ICEBERG" }] };
},
},
{
url: '/mock/ams/v1/catalogs/:id',
url: '/mock/api/ams/v1/catalogs/:id',
method: 'get',
response: () => ({
"message": "success",
Expand All @@ -92,15 +92,15 @@ export default [
"storage.type": "Hadoop",
"hive.site": {
"fileName": "hive-site.xml",
"fileUrl": "/ams/v1/catalogs/test_catalog/config/storage-config/hive-site"
"fileUrl": "/api/ams/v1/catalogs/test_catalog/config/storage-config/hive-site"
},
"hadoop.core.site": {
"fileName": "core-site.xml",
"fileUrl": "/ams/v1/catalogs/test_catalog/config/storage-config/hadoop-core-site"
"fileUrl": "/api/ams/v1/catalogs/test_catalog/config/storage-config/hadoop-core-site"
},
"hadoop.hdfs.site": {
"fileName": "hdfs-site.xml",
"fileUrl": "/ams/v1/catalogs/test_catalog/config/storage-config/hadoop-hdfs-site"
"fileUrl": "/api/ams/v1/catalogs/test_catalog/config/storage-config/hadoop-hdfs-site"
}
},
"authConfig": {
Expand All @@ -116,22 +116,22 @@ export default [
}),
},
{
url: '/mock/ams/v1/catalogs/:id',
url: '/mock/api/ams/v1/catalogs/:id',
method: 'put',
response: () => ({ "message": "success", "code": 200, "result": null }),
},
{
url: '/mock/ams/v1/catalogs/:id',
url: '/mock/api/ams/v1/catalogs/:id',
method: 'delete',
response: () => ({ "message": "success", "code": 200, "result": true }),
},
{
url: '/mock/ams/v1/catalogs/:id/delete/check',
url: '/mock/api/ams/v1/catalogs/:id/delete/check',
method: 'get',
response: () => ({ "message": "success", "code": 200, "result": true }),
},
{
url: '/mock/ams/v1/catalogs/metastore/types',
url: '/mock/api/ams/v1/catalogs/metastore/types',
method: 'get',
response: () => ({
"message": "success",
Expand Down Expand Up @@ -161,7 +161,7 @@ export default [
}),
},
{
url: '/mock/ams/v1/tables/catalogs/:catalog/dbs/:dbId/tables/:tableName/optimizing-processes/:processesId/tasks',
url: '/mock/api/ams/v1/tables/catalogs/:catalog/dbs/:dbId/tables/:tableName/optimizing-processes/:processesId/tasks',
method: 'get',
response: () => ({
"message": "success",
Expand Down
10 changes: 5 additions & 5 deletions amoro-web/mock/modules/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

export default [
{
url: '/mock/ams/v1/login/current',
url: '/mock/api/ams/v1/login/current',
method: 'get',
response: () => ({
code: 200,
Expand All @@ -30,7 +30,7 @@ export default [
}),
},
{
url: '/mock/ams/v1/login',
url: '/mock/api/ams/v1/login',
method: 'post',
response: () => ({
code: 200,
Expand All @@ -39,7 +39,7 @@ export default [
}),
},
{
url: '/mock/ams/v1/versionInfo',
url: '/mock/api/ams/v1/versionInfo',
method: 'get',
response: () => ({
code: 200,
Expand All @@ -51,7 +51,7 @@ export default [
}),
},
{
url: '/mock/ams/v1/upgrade/properties',
url: '/mock/api/ams/v1/upgrade/properties',
method: 'get',
response: () => ({
code: 200,
Expand All @@ -63,7 +63,7 @@ export default [
})
},
{
url: '/mock/ams/v1/logout',
url: '/mock/api/ams/v1/logout',
method: 'post',
response: () => ({
code: 200,
Expand Down
22 changes: 11 additions & 11 deletions amoro-web/mock/modules/optimize.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

export default [
{
url: '/mock/ams/v1/optimize/resourceGroups/get',
url: '/mock/api/ams/v1/optimize/resourceGroups/get',
method: 'get',
response: () => ({
code: 200,
Expand All @@ -29,7 +29,7 @@ export default [
}),
},
{
url: '/mock/ams/v1/optimize/containers/get',
url: '/mock/api/ams/v1/optimize/containers/get',
method: 'get',
response: () => ({
code: 200,
Expand All @@ -38,7 +38,7 @@ export default [
}),
},
{
url: '/mock/ams/v1/optimize/actions',
url: '/mock/api/ams/v1/optimize/actions',
method: 'get',
response: () => ({
code: 200,
Expand All @@ -47,7 +47,7 @@ export default [
}),
},
{
url: '/mock/ams/v1/optimize/optimizerGroups/:groups/tables',
url: '/mock/api/ams/v1/optimize/optimizerGroups/:groups/tables',
method: 'get',
response: () => ({
"message": "success",
Expand Down Expand Up @@ -85,12 +85,12 @@ export default [
}),
},
{
url: '/mock/ams/v1/optimize/optimizerGroups/local/optimizers',
url: '/mock/api/ams/v1/optimize/optimizerGroups/local/optimizers',
method: 'post',
response: () => ({ "message": "success", "code": 200, "result": "success to scaleOut optimizer" }),
},
{
url: '/mock/ams/v1/optimize/resourceGroups',
url: '/mock/api/ams/v1/optimize/resourceGroups',
method: 'get',
response: () => ({
"message": "success",
Expand Down Expand Up @@ -133,7 +133,7 @@ export default [
}),
},
{
url: '/mock/ams/v1/optimize/resourceGroups',
url: '/mock/api/ams/v1/optimize/resourceGroups',
method: 'put',
response: () => ({
"message": "success",
Expand All @@ -142,7 +142,7 @@ export default [
}),
},
{
url: '/mock/ams/v1/optimize/resourceGroups',
url: '/mock/api/ams/v1/optimize/resourceGroups',
method: 'post',
response: () => ({
"message": "success",
Expand All @@ -151,12 +151,12 @@ export default [
}),
},
{
url: '/mock/ams/v1/optimize/resourceGroups/:id/delete/check',
url: '/mock/api/ams/v1/optimize/resourceGroups/:id/delete/check',
method: 'get',
response: () => ({ "message": "success", "code": 200, "result": true }),
},
{
url: '/mock/ams/v1/optimize/resourceGroups/:id',
url: '/mock/api/ams/v1/optimize/resourceGroups/:id',
method: 'delete',
response: () => ({
"message": "success",
Expand All @@ -165,7 +165,7 @@ export default [
}),
},
{
url: '/mock/ams/v1/optimize/optimizerGroups/all/optimizers',
url: '/mock/api/ams/v1/optimize/optimizerGroups/all/optimizers',
method: 'get',
response: () => ({
"message": "success",
Expand Down
10 changes: 5 additions & 5 deletions amoro-web/mock/modules/overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

export default [
{
url: '/mock/ams/v1/overview/summary',
url: '/mock/api/ams/v1/overview/summary',
method: 'get',
response: () => ({
code: 200,
Expand All @@ -33,7 +33,7 @@ export default [
}),
},
{
url: '/mock/ams/v1/overview/optimizing',
url: '/mock/api/ams/v1/overview/optimizing',
method: 'get',
response: () => ({
code: 200,
Expand All @@ -48,7 +48,7 @@ export default [
}),
},
{
url: '/mock/ams/v1/overview/top',
url: '/mock/api/ams/v1/overview/top',
method: 'get',
response: () => ({
code: 200,
Expand All @@ -68,7 +68,7 @@ export default [
}),
},
{
url: '/mock/ams/v1/overview/resource',
url: '/mock/api/ams/v1/overview/resource',
method: 'get',
response: () => ({
code: 200,
Expand Down Expand Up @@ -97,7 +97,7 @@ export default [
}),
},
{
url: '/mock/ams/v1/overview/dataSize',
url: '/mock/api/ams/v1/overview/dataSize',
method: 'get',
response: () => ({
code: 200,
Expand Down
4 changes: 2 additions & 2 deletions amoro-web/mock/modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

export default [
{
url: '/mock/ams/v1/settings/system',
url: '/mock/api/ams/v1/settings/system',
method: 'get',
response: () => ({
code: 200,
Expand All @@ -30,7 +30,7 @@ export default [
}),
},
{
url: '/mock/ams/v1/settings/containers',
url: '/mock/api/ams/v1/settings/containers',
method: 'get',
response: () => ({
code: 200,
Expand Down
Loading
Loading