-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
SourceApiController.java
131 lines (112 loc) · 4.81 KB
/
SourceApiController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* Copyright (c) 2022 Airbyte, Inc., all rights reserved.
*/
package io.airbyte.server.apis;
import static io.airbyte.commons.auth.AuthRoleConstants.EDITOR;
import static io.airbyte.commons.auth.AuthRoleConstants.READER;
import io.airbyte.api.generated.SourceApi;
import io.airbyte.api.model.generated.ActorCatalogWithUpdatedAt;
import io.airbyte.api.model.generated.CheckConnectionRead;
import io.airbyte.api.model.generated.DiscoverCatalogResult;
import io.airbyte.api.model.generated.SourceCloneRequestBody;
import io.airbyte.api.model.generated.SourceCreate;
import io.airbyte.api.model.generated.SourceDiscoverSchemaRead;
import io.airbyte.api.model.generated.SourceDiscoverSchemaRequestBody;
import io.airbyte.api.model.generated.SourceDiscoverSchemaWriteRequestBody;
import io.airbyte.api.model.generated.SourceIdRequestBody;
import io.airbyte.api.model.generated.SourceRead;
import io.airbyte.api.model.generated.SourceReadList;
import io.airbyte.api.model.generated.SourceSearch;
import io.airbyte.api.model.generated.SourceUpdate;
import io.airbyte.api.model.generated.WorkspaceIdRequestBody;
import io.airbyte.server.handlers.SchedulerHandler;
import io.airbyte.server.handlers.SourceHandler;
import io.micronaut.context.annotation.Requires;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Post;
import io.micronaut.security.annotation.Secured;
import io.micronaut.security.rules.SecurityRule;
@Controller("/api/v1/sources")
@Requires(property = "airbyte.deployment-mode",
value = "OSS")
@Secured(SecurityRule.IS_AUTHENTICATED)
public class SourceApiController implements SourceApi {
private final SchedulerHandler schedulerHandler;
private final SourceHandler sourceHandler;
public SourceApiController(final SchedulerHandler schedulerHandler, final SourceHandler sourceHandler) {
this.schedulerHandler = schedulerHandler;
this.sourceHandler = sourceHandler;
}
@Post("/check_connection")
@Secured({EDITOR})
@Override
public CheckConnectionRead checkConnectionToSource(final SourceIdRequestBody sourceIdRequestBody) {
return ApiHelper.execute(() -> schedulerHandler.checkSourceConnectionFromSourceId(sourceIdRequestBody));
}
@Post("/check_connection_for_update")
@Secured({EDITOR})
@Override
public CheckConnectionRead checkConnectionToSourceForUpdate(final SourceUpdate sourceUpdate) {
return ApiHelper.execute(() -> schedulerHandler.checkSourceConnectionFromSourceIdForUpdate(sourceUpdate));
}
@Post("/clone")
@Override
public SourceRead cloneSource(final SourceCloneRequestBody sourceCloneRequestBody) {
return ApiHelper.execute(() -> sourceHandler.cloneSource(sourceCloneRequestBody));
}
@Post("/create")
@Secured({EDITOR})
@Override
public SourceRead createSource(final SourceCreate sourceCreate) {
return ApiHelper.execute(() -> sourceHandler.createSource(sourceCreate));
}
@Post("/delete")
@Secured({EDITOR})
@Override
public void deleteSource(final SourceIdRequestBody sourceIdRequestBody) {
ApiHelper.execute(() -> {
sourceHandler.deleteSource(sourceIdRequestBody);
return null;
});
}
@Post("/discover_schema")
@Secured({EDITOR})
@Override
public SourceDiscoverSchemaRead discoverSchemaForSource(final SourceDiscoverSchemaRequestBody sourceDiscoverSchemaRequestBody) {
return ApiHelper.execute(() -> schedulerHandler.discoverSchemaForSourceFromSourceId(sourceDiscoverSchemaRequestBody));
}
@Post("/get")
@Secured({READER})
@Override
public SourceRead getSource(final SourceIdRequestBody sourceIdRequestBody) {
return ApiHelper.execute(() -> sourceHandler.getSource(sourceIdRequestBody));
}
@Post("/most_recent_source_actor_catalog")
@Secured({READER})
@Override
public ActorCatalogWithUpdatedAt getMostRecentSourceActorCatalog(final SourceIdRequestBody sourceIdRequestBody) {
return ApiHelper.execute(() -> sourceHandler.getMostRecentSourceActorCatalogWithUpdatedAt(sourceIdRequestBody));
}
@Post("/list")
@Secured({READER})
@Override
public SourceReadList listSourcesForWorkspace(final WorkspaceIdRequestBody workspaceIdRequestBody) {
return ApiHelper.execute(() -> sourceHandler.listSourcesForWorkspace(workspaceIdRequestBody));
}
@Post("/search")
@Override
public SourceReadList searchSources(final SourceSearch sourceSearch) {
return ApiHelper.execute(() -> sourceHandler.searchSources(sourceSearch));
}
@Post("/update")
@Secured({EDITOR})
@Override
public SourceRead updateSource(final SourceUpdate sourceUpdate) {
return ApiHelper.execute(() -> sourceHandler.updateSource(sourceUpdate));
}
@Post("/write_discover_catalog_result")
@Override
public DiscoverCatalogResult writeDiscoverCatalogResult(final SourceDiscoverSchemaWriteRequestBody request) {
return ApiHelper.execute(() -> sourceHandler.writeDiscoverCatalogResult(request));
}
}