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

micronaut OperationApiController #20270

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 @@ -36,8 +36,9 @@ public class EventListener {
public void startEmitters(final ApplicationStartupEvent event) {
try {
/*
In order to have a smooth transition to micronaut for the server, we are starting 2 server. One managed by glassfish (legacy), one by
micronaut. Once all the controller are migrated, this will go away.
* In order to have a smooth transition to micronaut for the server, we are starting 2 server. One
* managed by glassfish (legacy), one by micronaut. Once all the controller are migrated, this will
* go away.
*/
final Configs configs = new EnvConfigs();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,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 @@ -61,7 +60,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 @@ -197,8 +195,6 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul

NotificationsApiFactory.setValues(workspacesHandler);

OperationApiFactory.setValues(operationsHandler);

OpenapiApiFactory.setValues(openApiConfigHandler);

SchedulerApiFactory.setValues(schedulerHandler);
Expand Down Expand Up @@ -249,7 +245,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the @Inject needed?

Copy link
Member Author

@colesnodgrass colesnodgrass Dec 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it mostly for documentation purposes as there are two constructors on this class. Technically it isn't needed as

Micronaut supports the following types of dependency injection:

  • Constructor injection (must be one public constructor or a single constructor annotated with @Inject)

and there is only a single public constructor for this class.

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
2 changes: 0 additions & 2 deletions airbyte-webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ public class ApiClientBeanFactory {
@Singleton
@Named("apiClient")
public ApiClient apiClient(
@Value("${airbyte.internal.api.auth-header.name}") final String airbyteApiAuthHeaderName,
@Value("${airbyte.internal.api.host}") final String airbyteApiHost,
@Named("internalApiAuthToken") final BeanProvider<String> internalApiAuthToken,
@Named("internalApiScheme") final String internalApiScheme
) {
@Value("${airbyte.internal.api.auth-header.name}") final String airbyteApiAuthHeaderName,
@Value("${airbyte.internal.api.host}") final String airbyteApiHost,
@Named("internalApiAuthToken") final BeanProvider<String> internalApiAuthToken,
@Named("internalApiScheme") final String internalApiScheme) {
return new io.airbyte.api.client.invoker.generated.ApiClient()
.setScheme(internalApiScheme)
.setHost(parseHostName(airbyteApiHost))
Expand All @@ -63,11 +62,10 @@ public ApiClient apiClient(
@Singleton
@Named("micronautApiClient")
public ApiClient micronautApiClient(
@Value("${airbyte.internal.api.auth-header.name}") final String airbyteApiAuthHeaderName,
@Value("${airbyte.internal.api.micronaut-host}") final String airbyteMicronautApiHost,
@Named("internalApiAuthToken") final BeanProvider<String> internalApiAuthToken,
@Named("internalApiScheme") final String internalApiScheme
) {
@Value("${airbyte.internal.api.auth-header.name}") final String airbyteApiAuthHeaderName,
@Value("${airbyte.internal.api.micronaut-host}") final String airbyteMicronautApiHost,
@Named("internalApiAuthToken") final BeanProvider<String> internalApiAuthToken,
@Named("internalApiScheme") final String internalApiScheme) {
return new io.airbyte.api.client.invoker.generated.ApiClient()
.setScheme(internalApiScheme)
.setHost(parseHostName(airbyteMicronautApiHost))
Expand All @@ -85,7 +83,8 @@ public ApiClient micronautApiClient(
}

@Singleton
public AirbyteApiClient airbyteApiClient(@Named("apiClient") final ApiClient apiClient, @Named("micronautApiClient") final ApiClient micronautApiClient) {
public AirbyteApiClient airbyteApiClient(@Named("apiClient") final ApiClient apiClient,
@Named("micronautApiClient") final ApiClient micronautApiClient) {
return new AirbyteApiClient(apiClient, micronautApiClient);
}

Expand Down