-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
ConnectionApiController.java
118 lines (102 loc) · 4.45 KB
/
ConnectionApiController.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
/*
* 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.ConnectionApi;
import io.airbyte.api.model.generated.ConnectionCreate;
import io.airbyte.api.model.generated.ConnectionIdRequestBody;
import io.airbyte.api.model.generated.ConnectionRead;
import io.airbyte.api.model.generated.ConnectionReadList;
import io.airbyte.api.model.generated.ConnectionSearch;
import io.airbyte.api.model.generated.ConnectionUpdate;
import io.airbyte.api.model.generated.JobInfoRead;
import io.airbyte.api.model.generated.WorkspaceIdRequestBody;
import io.airbyte.server.handlers.ConnectionsHandler;
import io.airbyte.server.handlers.OperationsHandler;
import io.airbyte.server.handlers.SchedulerHandler;
import io.micronaut.context.annotation.Context;
import io.micronaut.context.annotation.Requires;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.annotation.Body;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Post;
import io.micronaut.http.annotation.Status;
import io.micronaut.security.annotation.Secured;
import io.micronaut.security.rules.SecurityRule;
@Controller("/api/v1/connections")
@Context()
@Requires(property = "airbyte.deployment-mode",
value = "OSS")
@Secured(SecurityRule.IS_AUTHENTICATED)
public class ConnectionApiController implements ConnectionApi {
private final ConnectionsHandler connectionsHandler;
private final OperationsHandler operationsHandler;
private final SchedulerHandler schedulerHandler;
public ConnectionApiController(final ConnectionsHandler connectionsHandler,
final OperationsHandler operationsHandler,
final SchedulerHandler schedulerHandler) {
this.connectionsHandler = connectionsHandler;
this.operationsHandler = operationsHandler;
this.schedulerHandler = schedulerHandler;
}
@Override
@Post(uri = "/create")
@Secured({EDITOR})
public ConnectionRead createConnection(@Body final ConnectionCreate connectionCreate) {
return ApiHelper.execute(() -> connectionsHandler.createConnection(connectionCreate));
}
@Override
@Post(uri = "/update")
@Secured({EDITOR})
public ConnectionRead updateConnection(@Body final ConnectionUpdate connectionUpdate) {
return ApiHelper.execute(() -> connectionsHandler.updateConnection(connectionUpdate));
}
@Override
@Post(uri = "/list")
@Secured({READER})
public ConnectionReadList listConnectionsForWorkspace(@Body final WorkspaceIdRequestBody workspaceIdRequestBody) {
return ApiHelper.execute(() -> connectionsHandler.listConnectionsForWorkspace(workspaceIdRequestBody));
}
@Override
@Post(uri = "/list_all")
@Secured({READER})
public ConnectionReadList listAllConnectionsForWorkspace(@Body final WorkspaceIdRequestBody workspaceIdRequestBody) {
return ApiHelper.execute(() -> connectionsHandler.listAllConnectionsForWorkspace(workspaceIdRequestBody));
}
@Override
@Post(uri = "/search")
public ConnectionReadList searchConnections(@Body final ConnectionSearch connectionSearch) {
return ApiHelper.execute(() -> connectionsHandler.searchConnections(connectionSearch));
}
@Override
@Post(uri = "/get")
@Secured({READER})
public ConnectionRead getConnection(@Body final ConnectionIdRequestBody connectionIdRequestBody) {
return ApiHelper.execute(() -> connectionsHandler.getConnection(connectionIdRequestBody.getConnectionId()));
}
@Override
@Post(uri = "/delete")
@Status(HttpStatus.NO_CONTENT)
@Secured({EDITOR})
public void deleteConnection(@Body final ConnectionIdRequestBody connectionIdRequestBody) {
ApiHelper.execute(() -> {
operationsHandler.deleteOperationsForConnection(connectionIdRequestBody);
connectionsHandler.deleteConnection(connectionIdRequestBody.getConnectionId());
return null;
});
}
@Override
@Post(uri = "/sync")
@Secured({EDITOR})
public JobInfoRead syncConnection(@Body final ConnectionIdRequestBody connectionIdRequestBody) {
return ApiHelper.execute(() -> schedulerHandler.syncConnection(connectionIdRequestBody));
}
@Override
@Post(uri = "/reset")
@Secured({EDITOR})
public JobInfoRead resetConnection(@Body final ConnectionIdRequestBody connectionIdRequestBody) {
return ApiHelper.execute(() -> schedulerHandler.resetConnection(connectionIdRequestBody));
}
}