From f3e9f7b793607e0c347669959584ab2f7a3f856c Mon Sep 17 00:00:00 2001 From: Cole Snodgrass Date: Mon, 12 Dec 2022 12:37:28 -0800 Subject: [PATCH 1/2] convert SourceOauthApiController to Micronaut --- airbyte-proxy/nginx-auth.conf.template | 5 ++-- airbyte-proxy/nginx-no-auth.conf.template | 4 +-- .../java/io/airbyte/server/ServerFactory.java | 5 ---- .../server/apis/SourceOauthApiController.java | 14 ++++++--- .../apis/binders/SourceOauthApiBinder.java | 21 -------------- .../apis/factories/SourceOauthApiFactory.java | 29 ------------------- 6 files changed, 14 insertions(+), 64 deletions(-) delete mode 100644 airbyte-server/src/main/java/io/airbyte/server/apis/binders/SourceOauthApiBinder.java delete mode 100644 airbyte-server/src/main/java/io/airbyte/server/apis/factories/SourceOauthApiFactory.java diff --git a/airbyte-proxy/nginx-auth.conf.template b/airbyte-proxy/nginx-auth.conf.template index 02e75bbf8438..ef79ab533d2d 100644 --- a/airbyte-proxy/nginx-auth.conf.template +++ b/airbyte-proxy/nginx-auth.conf.template @@ -43,7 +43,7 @@ http { } } - location ~ ^/api/v1/(connections|destinations|destination_definitions|destination_definition_specifications|destination_oauths|operations|scheduler|sources|source_definitions|state)/.* { + location ~ ^/api/v1/(connections|destinations|destination_definitions|destination_definition_specifications|destination_oauths|operations|scheduler|source_oauths|sources|source_definitions|state)/.* { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -103,8 +103,7 @@ http { } } - location ~ ^/api/v1/(connections|destinations|destination_definitions|destination_definition_specifications|destination_oauths|operations|source_definitions|sources|scheduler|state)/.* { - location ~ ^/api/v1/(connections|destinations|destination_definitions|destination_definition_specifications|destination_oauths|operations + location ~ ^/api/v1/(connections|destinations|destination_definitions|destination_definition_specifications|destination_oauths|operations|scheduler|source_oauths|sources|source_definitions|state)/.* { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; diff --git a/airbyte-proxy/nginx-no-auth.conf.template b/airbyte-proxy/nginx-no-auth.conf.template index 841333391ae1..b64f7b96689e 100644 --- a/airbyte-proxy/nginx-no-auth.conf.template +++ b/airbyte-proxy/nginx-no-auth.conf.template @@ -25,7 +25,7 @@ http { proxy_pass "${PROXY_PASS_MICRONAUT_API}"; } - location ~ ^/api/v1/(connections|destinations|destination_definitions|destination_definition_specifications|destination_oauths|operations|scheduler|sources|source_definitions|state)/.* { + location ~ ^/api/v1/(connections|destinations|destination_definitions|destination_definition_specifications|destination_oauths|operations|scheduler|source_oauths|sources|source_definitions|state)/.* { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -58,7 +58,7 @@ http { proxy_pass "${PROXY_PASS_MICRONAUT_API}"; } - location ~ ^/api/v1/(connections|destinations|destination_definitions|destination_definition_specifications|destination_oauths|operations|scheduler|sources|source_definitions|state)/.* { + location ~ ^/api/v1/(connections|destinations|destination_definitions|destination_definition_specifications|destination_oauths|operations|scheduler|source_oauths|sources|source_definitions|state)/.* { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; diff --git a/airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java b/airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java index 3ccafceff53b..decadf5d6313 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java +++ b/airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java @@ -17,7 +17,6 @@ import io.airbyte.server.apis.LogsApiController; import io.airbyte.server.apis.NotificationsApiController; import io.airbyte.server.apis.SourceDefinitionSpecificationApiController; -import io.airbyte.server.apis.SourceOauthApiController; import io.airbyte.server.apis.StateApiController; import io.airbyte.server.apis.WebBackendApiController; import io.airbyte.server.apis.WorkspaceApiController; @@ -25,14 +24,12 @@ import io.airbyte.server.apis.binders.LogsApiBinder; import io.airbyte.server.apis.binders.NotificationApiBinder; import io.airbyte.server.apis.binders.SourceDefinitionSpecificationApiBinder; -import io.airbyte.server.apis.binders.SourceOauthApiBinder; import io.airbyte.server.apis.binders.WebBackendApiBinder; import io.airbyte.server.apis.binders.WorkspaceApiBinder; import io.airbyte.server.apis.factories.JobsApiFactory; import io.airbyte.server.apis.factories.LogsApiFactory; import io.airbyte.server.apis.factories.NotificationsApiFactory; import io.airbyte.server.apis.factories.SourceDefinitionSpecificationApiFactory; -import io.airbyte.server.apis.factories.SourceOauthApiFactory; import io.airbyte.server.apis.factories.WebBackendApiFactory; import io.airbyte.server.apis.factories.WorkspaceApiFactory; import io.airbyte.server.handlers.AttemptHandler; @@ -149,7 +146,6 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul LogsApiController.class, NotificationsApiController.class, SourceDefinitionSpecificationApiController.class, - SourceOauthApiController.class, StateApiController.class, WebBackendApiController.class, WorkspaceApiController.class); @@ -159,7 +155,6 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul new LogsApiBinder(), new NotificationApiBinder(), new SourceDefinitionSpecificationApiBinder(), - new SourceOauthApiBinder(), new WebBackendApiBinder(), new WorkspaceApiBinder()); diff --git a/airbyte-server/src/main/java/io/airbyte/server/apis/SourceOauthApiController.java b/airbyte-server/src/main/java/io/airbyte/server/apis/SourceOauthApiController.java index 84e0782a3020..087f759330fb 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/apis/SourceOauthApiController.java +++ b/airbyte-server/src/main/java/io/airbyte/server/apis/SourceOauthApiController.java @@ -10,26 +10,32 @@ import io.airbyte.api.model.generated.SetInstancewideSourceOauthParamsRequestBody; import io.airbyte.api.model.generated.SourceOauthConsentRequest; import io.airbyte.server.handlers.OAuthHandler; +import io.micronaut.http.annotation.Controller; +import io.micronaut.http.annotation.Post; import java.util.Map; -import javax.ws.rs.Path; -import lombok.AllArgsConstructor; -@Path("/v1/source_oauths") -@AllArgsConstructor +@Controller("/api/v1/source_oauths") public class SourceOauthApiController implements SourceOauthApi { private final OAuthHandler oAuthHandler; + public SourceOauthApiController(final OAuthHandler oAuthHandler) { + this.oAuthHandler = oAuthHandler; + } + + @Post("/complete_oauth") @Override public Map completeSourceOAuth(final CompleteSourceOauthRequest completeSourceOauthRequest) { return ApiHelper.execute(() -> oAuthHandler.completeSourceOAuth(completeSourceOauthRequest)); } + @Post("/get_consent_url") @Override public OAuthConsentRead getSourceOAuthConsent(final SourceOauthConsentRequest sourceOauthConsentRequest) { return ApiHelper.execute(() -> oAuthHandler.getSourceOAuthConsent(sourceOauthConsentRequest)); } + @Post("/oauth_params/create") @Override public void setInstancewideSourceOauthParams(final SetInstancewideSourceOauthParamsRequestBody setInstancewideSourceOauthParamsRequestBody) { ApiHelper.execute(() -> { diff --git a/airbyte-server/src/main/java/io/airbyte/server/apis/binders/SourceOauthApiBinder.java b/airbyte-server/src/main/java/io/airbyte/server/apis/binders/SourceOauthApiBinder.java deleted file mode 100644 index 744099e4cf80..000000000000 --- a/airbyte-server/src/main/java/io/airbyte/server/apis/binders/SourceOauthApiBinder.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 Airbyte, Inc., all rights reserved. - */ - -package io.airbyte.server.apis.binders; - -import io.airbyte.server.apis.SourceOauthApiController; -import io.airbyte.server.apis.factories.SourceOauthApiFactory; -import org.glassfish.hk2.utilities.binding.AbstractBinder; -import org.glassfish.jersey.process.internal.RequestScoped; - -public class SourceOauthApiBinder extends AbstractBinder { - - @Override - protected void configure() { - bindFactory(SourceOauthApiFactory.class) - .to(SourceOauthApiController.class) - .in(RequestScoped.class); - } - -} diff --git a/airbyte-server/src/main/java/io/airbyte/server/apis/factories/SourceOauthApiFactory.java b/airbyte-server/src/main/java/io/airbyte/server/apis/factories/SourceOauthApiFactory.java deleted file mode 100644 index a5aef45948ec..000000000000 --- a/airbyte-server/src/main/java/io/airbyte/server/apis/factories/SourceOauthApiFactory.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2022 Airbyte, Inc., all rights reserved. - */ - -package io.airbyte.server.apis.factories; - -import io.airbyte.server.apis.SourceOauthApiController; -import io.airbyte.server.handlers.OAuthHandler; -import org.glassfish.hk2.api.Factory; - -public class SourceOauthApiFactory implements Factory { - - private static OAuthHandler oAuthHandler; - - public static void setValues(final OAuthHandler oAuthHandler) { - SourceOauthApiFactory.oAuthHandler = oAuthHandler; - } - - @Override - public SourceOauthApiController provide() { - return new SourceOauthApiController(SourceOauthApiFactory.oAuthHandler); - } - - @Override - public void dispose(final SourceOauthApiController instance) { - /* no op */ - } - -} From c2b3f56be07ec479c2bc1840835a4bc17ef151a0 Mon Sep 17 00:00:00 2001 From: Cole Snodgrass Date: Mon, 12 Dec 2022 12:38:54 -0800 Subject: [PATCH 2/2] remove SourceOauthApi reference --- .../src/main/java/io/airbyte/server/ServerFactory.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java b/airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java index decadf5d6313..a3b7f1153d67 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java +++ b/airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java @@ -125,9 +125,6 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul final WebBackendConnectionsHandler webBackendConnectionsHandler, final WebBackendGeographiesHandler webBackendGeographiesHandler, final WebBackendCheckUpdatesHandler webBackendCheckUpdatesHandler) { - - SourceOauthApiFactory.setValues(oAuthHandler); - JobsApiFactory.setValues(jobHistoryHandler, schedulerHandler); LogsApiFactory.setValues(logsHandler);