Skip to content

Commit

Permalink
micronaut OperationApiController (#20270)
Browse files Browse the repository at this point in the history
* micronaut OperationApiController

* pass micronaut client to OperationApi
  • Loading branch information
colesnodgrass authored Dec 9, 2022
1 parent d50555d commit ce9127e
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
* This class is meant to consolidate all our API endpoints into a fluent-ish client. Currently, all
* open API generators create a separate class per API "root-route". For example, if our API has two
* routes "/v1/First/get" and "/v1/Second/get", OpenAPI generates (essentially) the following files:
*
* <p>
* ApiClient.java, FirstApi.java, SecondApi.java
*
* <p>
* To call the API type-safely, we'd do new FirstApi(new ApiClient()).get() or new SecondApi(new
* ApiClient()).get(), which can get cumbersome if we're interacting with many pieces of the API.
*
* <p>
* This is currently manually maintained. We could look into autogenerating it if needed.
*/
public class AirbyteApiClient {
Expand Down Expand Up @@ -67,7 +67,7 @@ public AirbyteApiClient(final ApiClient apiClient, final ApiClient micronautApiC
destinationSpecificationApi = new DestinationDefinitionSpecificationApi(apiClient);
jobsApi = new JobsApi(apiClient);
logsApi = new PatchedLogsApi(apiClient);
operationApi = new OperationApi(apiClient);
operationApi = new OperationApi(micronautApiClient);
sourceDefinitionApi = new SourceDefinitionApi(apiClient);
sourceApi = new SourceApi(apiClient);
sourceDefinitionSpecificationApi = new SourceDefinitionSpecificationApi(apiClient);
Expand Down
34 changes: 34 additions & 0 deletions airbyte-proxy/nginx-auth.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ http {
auth_basic off;
}
}

location /api/v1/operations {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

auth_basic "Welcome to Airbyte";
auth_basic_user_file /etc/nginx/.htpasswd;

proxy_pass "${PROXY_PASS_MICRONAUT_API}";

error_page 401 /etc/nginx/401.html;
location ~ (401.html)$ {
alias /etc/nginx/$1;
auth_basic off;
}
}
}

server {
Expand Down Expand Up @@ -75,6 +92,23 @@ http {
auth_basic off;
}
}

location /api/v1/operations {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

auth_basic "Welcome to Airbyte";
auth_basic_user_file /etc/nginx/.htpasswd;

proxy_pass "${PROXY_PASS_MICRONAUT_API}";

error_page 401 /etc/nginx/401.html;
location ~ (401.html)$ {
alias /etc/nginx/$1;
auth_basic off;
}
}
}

server {
Expand Down
16 changes: 16 additions & 0 deletions airbyte-proxy/nginx-no-auth.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ http {

proxy_pass "${PROXY_PASS_MICRONAUT_API}";
}

location /api/v1/operations {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass "${PROXY_PASS_MICRONAUT_API}";
}
}

server {
Expand All @@ -39,6 +47,14 @@ http {

proxy_pass "${PROXY_PASS_MICRONAUT_API}";
}

location /api/v1/operations {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass "${PROXY_PASS_MICRONAUT_API}";
}
}

server {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import io.airbyte.server.apis.binders.LogsApiBinder;
import io.airbyte.server.apis.binders.NotificationApiBinder;
import io.airbyte.server.apis.binders.OpenapiApiBinder;
import io.airbyte.server.apis.binders.OperationApiBinder;
import io.airbyte.server.apis.binders.SchedulerApiBinder;
import io.airbyte.server.apis.binders.SourceApiBinder;
import io.airbyte.server.apis.binders.SourceDefinitionApiBinder;
Expand All @@ -58,7 +57,6 @@
import io.airbyte.server.apis.factories.LogsApiFactory;
import io.airbyte.server.apis.factories.NotificationsApiFactory;
import io.airbyte.server.apis.factories.OpenapiApiFactory;
import io.airbyte.server.apis.factories.OperationApiFactory;
import io.airbyte.server.apis.factories.SchedulerApiFactory;
import io.airbyte.server.apis.factories.SourceApiFactory;
import io.airbyte.server.apis.factories.SourceDefinitionApiFactory;
Expand Down Expand Up @@ -192,8 +190,6 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul

NotificationsApiFactory.setValues(workspacesHandler);

OperationApiFactory.setValues(operationsHandler);

OpenapiApiFactory.setValues(openApiConfigHandler);

SchedulerApiFactory.setValues(schedulerHandler);
Expand Down Expand Up @@ -242,7 +238,6 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
new LogsApiBinder(),
new NotificationApiBinder(),
new OpenapiApiBinder(),
new OperationApiBinder(),
new SchedulerApiBinder(),
new SourceApiBinder(),
new SourceDefinitionApiBinder(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,55 @@
import io.airbyte.api.model.generated.OperationUpdate;
import io.airbyte.api.model.generated.OperatorConfiguration;
import io.airbyte.server.handlers.OperationsHandler;
import javax.ws.rs.Path;
import lombok.AllArgsConstructor;
import io.micronaut.http.annotation.Body;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Post;

@Path("/v1/operations")
@AllArgsConstructor
@Controller("/api/v1/operations")
public class OperationApiController implements OperationApi {

private final OperationsHandler operationsHandler;

public OperationApiController(final OperationsHandler operationsHandler) {
this.operationsHandler = operationsHandler;
}

@Post("/check")
@Override
public CheckOperationRead checkOperation(final OperatorConfiguration operatorConfiguration) {
public CheckOperationRead checkOperation(@Body final OperatorConfiguration operatorConfiguration) {
return ApiHelper.execute(() -> operationsHandler.checkOperation(operatorConfiguration));
}

@Post("/create")
@Override
public OperationRead createOperation(final OperationCreate operationCreate) {
public OperationRead createOperation(@Body final OperationCreate operationCreate) {
return ApiHelper.execute(() -> operationsHandler.createOperation(operationCreate));
}

@Post("/delete")
@Override
public void deleteOperation(final OperationIdRequestBody operationIdRequestBody) {
public void deleteOperation(@Body final OperationIdRequestBody operationIdRequestBody) {
ApiHelper.execute(() -> {
operationsHandler.deleteOperation(operationIdRequestBody);
return null;
});
}

@Post("/get")
@Override
public OperationRead getOperation(final OperationIdRequestBody operationIdRequestBody) {
public OperationRead getOperation(@Body final OperationIdRequestBody operationIdRequestBody) {
return ApiHelper.execute(() -> operationsHandler.getOperation(operationIdRequestBody));
}

@Post("/list")
@Override
public OperationReadList listOperationsForConnection(final ConnectionIdRequestBody connectionIdRequestBody) {
public OperationReadList listOperationsForConnection(@Body final ConnectionIdRequestBody connectionIdRequestBody) {
return ApiHelper.execute(() -> operationsHandler.listOperationsForConnection(connectionIdRequestBody));
}

@Post("/update")
@Override
public OperationRead updateOperation(final OperationUpdate operationUpdate) {
public OperationRead updateOperation(@Body final OperationUpdate operationUpdate) {
return ApiHelper.execute(() -> operationsHandler.updateOperation(operationUpdate));
}

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,32 @@
import io.airbyte.config.persistence.ConfigRepository;
import io.airbyte.server.converters.OperationsConverter;
import io.airbyte.validation.json.JsonValidationException;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import java.util.function.Supplier;

@Singleton
public class OperationsHandler {

private final ConfigRepository configRepository;
private final Supplier<UUID> uuidGenerator;

@Inject
public OperationsHandler(final ConfigRepository configRepository) {
this(configRepository, UUID::randomUUID);
}

@VisibleForTesting
OperationsHandler(final ConfigRepository configRepository, final Supplier<UUID> uuidGenerator) {
this.configRepository = configRepository;
this.uuidGenerator = uuidGenerator;
}

public OperationsHandler(final ConfigRepository configRepository) {
this(configRepository, UUID::randomUUID);
}

public CheckOperationRead checkOperation(final OperatorConfiguration operationCheck) {
try {
validateOperation(operationCheck);
Expand Down

0 comments on commit ce9127e

Please sign in to comment.