Skip to content

Commit

Permalink
Extract OAuth API (#18818)
Browse files Browse the repository at this point in the history
* Tmp

* Extract the Attempt API from the V1 API

* Add comments

* Move Connection API out of configuration API

* format

* format

* Rename to Controller

* Rename to Controller

* Add values to the factory

* Change the constructor to use hadler instead of objects needed by the handler

* Update with new tags.

* tmp

* Fix PMD errors

* Extract DB migrator

* Add something that I forgot

* extract destination definition api

* restore destination factory initialization

* extract destination definition specification api

* format

* format

* format

* extract health check api

* extract jobs api

* fix test

* format

* Extract logs api

* Add missing declaration

* Fix build

* Tmp

* format and PR comments

* Extract notification API

* re-organize tags

* Extract all Oauth

* Fix PMD
  • Loading branch information
benmoriceau authored Nov 2, 2022
1 parent 9c081fb commit 589f6ef
Show file tree
Hide file tree
Showing 12 changed files with 602 additions and 384 deletions.
18 changes: 10 additions & 8 deletions airbyte-api/src/main/openapi/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ tags:
description: Destination related resources.
- name: connection
description: Connection between sources and destinations.
- name: oauth
description: OAuth related resources to delegate access from user.
- name: destination_oauth
description: Source OAuth related resources to delegate access from user.
- name: source_oauth
description: Source OAuth related resources to delegate access from user.
- name: db_migration
description: Database migration related resources.
- name: web_backend
Expand Down Expand Up @@ -1762,7 +1764,7 @@ paths:
/v1/source_oauths/oauth_params/create:
post:
tags:
- oauth
- source_oauth
summary: >
Sets instancewide variables to be used for the oauth flow when creating this source. When set, these variables will be injected
into a connector's configuration before any interaction with the connector image itself. This enables running oauth flows with
Expand All @@ -1785,7 +1787,7 @@ paths:
/v1/source_oauths/get_consent_url:
post:
tags:
- oauth
- source_oauth
summary: Given a source connector definition ID, return the URL to the consent screen where to redirect the user to.
operationId: getSourceOAuthConsent
requestBody:
Expand All @@ -1808,7 +1810,7 @@ paths:
/v1/source_oauths/complete_oauth:
post:
tags:
- oauth
- source_oauth
summary: Given a source def ID generate an access/refresh token etc.
operationId: completeSourceOAuth
requestBody:
Expand All @@ -1831,7 +1833,7 @@ paths:
/v1/destination_oauths/get_consent_url:
post:
tags:
- oauth
- destination_oauth
summary: Given a destination connector definition ID, return the URL to the consent screen where to redirect the user to.
operationId: getDestinationOAuthConsent
requestBody:
Expand All @@ -1854,7 +1856,7 @@ paths:
/v1/destination_oauths/complete_oauth:
post:
tags:
- oauth
- destination_oauth
summary: Given a destination def ID generate an access/refresh token etc.
operationId: completeDestinationOAuth
requestBody:
Expand All @@ -1877,7 +1879,7 @@ paths:
/v1/destination_oauths/oauth_params/create:
post:
tags:
- oauth
- destination_oauth
summary: >
Sets instancewide variables to be used for the oauth flow when creating this destination. When set, these variables will be injected
into a connector's configuration before any interaction with the connector image itself. This enables running oauth flows with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class ConfigurationApiFactory implements Factory<ConfigurationApi> {
private static WorkerEnvironment workerEnvironment;
private static LogConfigs logConfigs;
private static AirbyteVersion airbyteVersion;
private static HttpClient httpClient;
private static EventRunner eventRunner;

public static void setValues(
Expand Down Expand Up @@ -69,7 +68,6 @@ public static void setValues(
ConfigurationApiFactory.workerEnvironment = workerEnvironment;
ConfigurationApiFactory.logConfigs = logConfigs;
ConfigurationApiFactory.airbyteVersion = airbyteVersion;
ConfigurationApiFactory.httpClient = httpClient;
ConfigurationApiFactory.eventRunner = eventRunner;
ConfigurationApiFactory.statePersistence = statePersistence;
}
Expand All @@ -89,7 +87,6 @@ public ConfigurationApi provide() {
ConfigurationApiFactory.workerEnvironment,
ConfigurationApiFactory.logConfigs,
ConfigurationApiFactory.airbyteVersion,
ConfigurationApiFactory.httpClient,
ConfigurationApiFactory.eventRunner);
}

Expand Down
4 changes: 4 additions & 0 deletions airbyte-server/src/main/java/io/airbyte/server/ServerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import io.airbyte.server.handlers.HealthCheckHandler;
import io.airbyte.server.handlers.JobHistoryHandler;
import io.airbyte.server.handlers.LogsHandler;
import io.airbyte.server.handlers.OAuthHandler;
import io.airbyte.server.handlers.OperationsHandler;
import io.airbyte.server.handlers.SchedulerHandler;
import io.airbyte.server.handlers.SourceDefinitionsHandler;
Expand Down Expand Up @@ -301,6 +302,8 @@ public static ServerRunnable getServer(final ServerFactory apiFactory,

final HealthCheckHandler healthCheckHandler = new HealthCheckHandler(configRepository);

final OAuthHandler oAuthHandler = new OAuthHandler(configRepository, httpClient, trackingClient);

final SourceHandler sourceHandler = new SourceHandler(
configRepository,
secretsRepositoryReader,
Expand Down Expand Up @@ -357,6 +360,7 @@ public static ServerRunnable getServer(final ServerFactory apiFactory,
healthCheckHandler,
jobHistoryHandler,
logsHandler,
oAuthHandler,
operationsHandler,
schedulerHandler,
workspacesHandler);
Expand Down
20 changes: 18 additions & 2 deletions airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.airbyte.server.apis.DestinationApiController;
import io.airbyte.server.apis.DestinationDefinitionApiController;
import io.airbyte.server.apis.DestinationDefinitionSpecificationApiController;
import io.airbyte.server.apis.DestinationOauthApiController;
import io.airbyte.server.apis.HealthApiController;
import io.airbyte.server.apis.JobsApiController;
import io.airbyte.server.apis.LogsApiController;
Expand All @@ -31,20 +32,24 @@
import io.airbyte.server.apis.binders.DestinationApiBinder;
import io.airbyte.server.apis.binders.DestinationDefinitionApiBinder;
import io.airbyte.server.apis.binders.DestinationDefinitionSpecificationApiBinder;
import io.airbyte.server.apis.binders.DestinationOauthApiBinder;
import io.airbyte.server.apis.binders.HealthApiBinder;
import io.airbyte.server.apis.binders.JobsApiBinder;
import io.airbyte.server.apis.binders.LogsApiBinder;
import io.airbyte.server.apis.binders.NotificationApiBinder;
import io.airbyte.server.apis.binders.SourceOauthApiBinder;
import io.airbyte.server.apis.factories.AttemptApiFactory;
import io.airbyte.server.apis.factories.ConnectionApiFactory;
import io.airbyte.server.apis.factories.DbMigrationApiFactory;
import io.airbyte.server.apis.factories.DestinationApiFactory;
import io.airbyte.server.apis.factories.DestinationDefinitionApiFactory;
import io.airbyte.server.apis.factories.DestinationDefinitionSpecificationApiFactory;
import io.airbyte.server.apis.factories.DestinationOauthApiFactory;
import io.airbyte.server.apis.factories.HealthApiFactory;
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.SourceOauthApiFactory;
import io.airbyte.server.handlers.AttemptHandler;
import io.airbyte.server.handlers.ConnectionsHandler;
import io.airbyte.server.handlers.DbMigrationHandler;
Expand All @@ -53,6 +58,7 @@
import io.airbyte.server.handlers.HealthCheckHandler;
import io.airbyte.server.handlers.JobHistoryHandler;
import io.airbyte.server.handlers.LogsHandler;
import io.airbyte.server.handlers.OAuthHandler;
import io.airbyte.server.handlers.OperationsHandler;
import io.airbyte.server.handlers.SchedulerHandler;
import io.airbyte.server.handlers.WorkspacesHandler;
Expand Down Expand Up @@ -91,6 +97,7 @@ ServerRunnable create(final SynchronousSchedulerClient synchronousSchedulerClien
final HealthCheckHandler healthCheckHandler,
final JobHistoryHandler jobHistoryHandler,
final LogsHandler logsHandler,
final OAuthHandler oAuthHandler,
final OperationsHandler operationsHandler,
final SchedulerHandler schedulerHandler,
final WorkspacesHandler workspacesHandler);
Expand Down Expand Up @@ -122,6 +129,7 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
final HealthCheckHandler healthCheckHandler,
final JobHistoryHandler jobHistoryHandler,
final LogsHandler logsHandler,
final OAuthHandler oAuthHandler,
final OperationsHandler operationsHandler,
final SchedulerHandler schedulerHandler,
final WorkspacesHandler workspacesHandler) {
Expand Down Expand Up @@ -166,6 +174,10 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul

HealthApiFactory.setValues(healthCheckHandler);

DestinationOauthApiFactory.setValues(oAuthHandler);

SourceOauthApiFactory.setValues(oAuthHandler);

JobsApiFactory.setValues(jobHistoryHandler, schedulerHandler);

LogsApiFactory.setValues(logsHandler);
Expand All @@ -181,10 +193,12 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
DestinationApiController.class,
DestinationDefinitionApiController.class,
DestinationDefinitionSpecificationApiController.class,
DestinationOauthApiController.class,
HealthApiController.class,
JobsApiController.class,
LogsApiController.class,
NotificationsApiController.class);
NotificationsApiController.class,
SourceOauthApiFactory.class);

final Set<Object> components = Set.of(
new CorsFilter(),
Expand All @@ -195,10 +209,12 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
new DestinationApiBinder(),
new DestinationDefinitionApiBinder(),
new DestinationDefinitionSpecificationApiBinder(),
new DestinationOauthApiBinder(),
new HealthApiBinder(),
new JobsApiBinder(),
new LogsApiBinder(),
new NotificationApiBinder());
new NotificationApiBinder(),
new SourceOauthApiBinder());

// construct server
return new ServerApp(airbyteVersion, componentClasses, components);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
import io.airbyte.server.handlers.DestinationDefinitionsHandler;
import io.airbyte.server.handlers.DestinationHandler;
import io.airbyte.server.handlers.JobHistoryHandler;
import io.airbyte.server.handlers.OAuthHandler;
import io.airbyte.server.handlers.OpenApiConfigHandler;
import io.airbyte.server.handlers.OperationsHandler;
import io.airbyte.server.handlers.SchedulerHandler;
Expand All @@ -133,7 +132,6 @@
import io.airbyte.validation.json.JsonValidationException;
import java.io.File;
import java.io.IOException;
import java.net.http.HttpClient;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.NotImplementedException;
Expand All @@ -155,7 +153,6 @@ public class ConfigurationApi implements io.airbyte.api.generated.V1Api {
private final WebBackendConnectionsHandler webBackendConnectionsHandler;
private final WebBackendGeographiesHandler webBackendGeographiesHandler;
private final OpenApiConfigHandler openApiConfigHandler;
private final OAuthHandler oAuthHandler;

public ConfigurationApi(final ConfigRepository configRepository,
final JobPersistence jobPersistence,
Expand All @@ -167,7 +164,6 @@ public ConfigurationApi(final ConfigRepository configRepository,
final WorkerEnvironment workerEnvironment,
final LogConfigs logConfigs,
final AirbyteVersion airbyteVersion,
final HttpClient httpClient,
final EventRunner eventRunner) {

final JsonSchemaValidator schemaValidator = new JsonSchemaValidator();
Expand Down Expand Up @@ -215,7 +211,6 @@ public ConfigurationApi(final ConfigRepository configRepository,
sourceHandler);
jobHistoryHandler = new JobHistoryHandler(jobPersistence, workerEnvironment, logConfigs, connectionsHandler, sourceHandler,
sourceDefinitionsHandler, destinationHandler, destinationDefinitionsHandler, airbyteVersion);
oAuthHandler = new OAuthHandler(configRepository, httpClient, trackingClient);
webBackendConnectionsHandler = new WebBackendConnectionsHandler(
connectionsHandler,
stateHandler,
Expand Down Expand Up @@ -379,40 +374,58 @@ public SourceDefinitionSpecificationRead getSourceDefinitionSpecification(final

// OAUTH

/**
* This implementation has been moved to {@link SourceOauthApiController}. Since the path of
* {@link SourceOauthApiController} is more granular, it will override this implementation
*/
@Override
public OAuthConsentRead getSourceOAuthConsent(final SourceOauthConsentRequest sourceOauthConsentRequest) {
return execute(() -> oAuthHandler.getSourceOAuthConsent(sourceOauthConsentRequest));
throw new NotImplementedException();
}

/**
* This implementation has been moved to {@link SourceOauthApiController}. Since the path of
* {@link SourceOauthApiController} is more granular, it will override this implementation
*/
@Override
public Map<String, Object> completeSourceOAuth(final CompleteSourceOauthRequest completeSourceOauthRequest) {
return execute(() -> oAuthHandler.completeSourceOAuth(completeSourceOauthRequest));
throw new NotImplementedException();
}

/**
* This implementation has been moved to {@link DestinationOauthApiController}. Since the path of
* {@link DestinationOauthApiController} is more granular, it will override this implementation
*/
@Override
public OAuthConsentRead getDestinationOAuthConsent(final DestinationOauthConsentRequest destinationOauthConsentRequest) {
return execute(() -> oAuthHandler.getDestinationOAuthConsent(destinationOauthConsentRequest));
throw new NotImplementedException();
}

/**
* This implementation has been moved to {@link DestinationOauthApiController}. Since the path of
* {@link DestinationOauthApiController} is more granular, it will override this implementation
*/
@Override
public Map<String, Object> completeDestinationOAuth(final CompleteDestinationOAuthRequest requestBody) {
return execute(() -> oAuthHandler.completeDestinationOAuth(requestBody));
throw new NotImplementedException();
}

/**
* This implementation has been moved to {@link DestinationOauthApiController}. Since the path of
* {@link DestinationOauthApiController} is more granular, it will override this implementation
*/
@Override
public void setInstancewideDestinationOauthParams(final SetInstancewideDestinationOauthParamsRequestBody requestBody) {
execute(() -> {
oAuthHandler.setDestinationInstancewideOauthParams(requestBody);
return null;
});
throw new NotImplementedException();
}

/**
* This implementation has been moved to {@link SourceOauthApiController}. Since the path of
* {@link SourceOauthApiController} is more granular, it will override this implementation
*/
@Override
public void setInstancewideSourceOauthParams(final SetInstancewideSourceOauthParamsRequestBody requestBody) {
execute(() -> {
oAuthHandler.setSourceInstancewideOauthParams(requestBody);
return null;
});
throw new NotImplementedException();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2022 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.server.apis;

import io.airbyte.api.generated.DestinationOauthApi;
import io.airbyte.api.model.generated.CompleteDestinationOAuthRequest;
import io.airbyte.api.model.generated.DestinationOauthConsentRequest;
import io.airbyte.api.model.generated.OAuthConsentRead;
import io.airbyte.api.model.generated.SetInstancewideDestinationOauthParamsRequestBody;
import io.airbyte.server.handlers.OAuthHandler;
import java.util.Map;
import javax.ws.rs.Path;
import lombok.AllArgsConstructor;

@Path("/v1/destination_oauths")
@AllArgsConstructor
public class DestinationOauthApiController implements DestinationOauthApi {

private final OAuthHandler oAuthHandler;

@Override
public Map<String, Object> completeDestinationOAuth(final CompleteDestinationOAuthRequest completeDestinationOAuthRequest) {
return ConfigurationApi.execute(() -> oAuthHandler.completeDestinationOAuth(completeDestinationOAuthRequest));
}

@Override
public OAuthConsentRead getDestinationOAuthConsent(final DestinationOauthConsentRequest destinationOauthConsentRequest) {
return ConfigurationApi.execute(() -> oAuthHandler.getDestinationOAuthConsent(destinationOauthConsentRequest));
}

@Override
public void setInstancewideDestinationOauthParams(final SetInstancewideDestinationOauthParamsRequestBody setInstancewideDestinationOauthParamsRequestBody) {
ConfigurationApi.execute(() -> {
oAuthHandler.setDestinationInstancewideOauthParams(setInstancewideDestinationOauthParamsRequestBody);
return null;
});
}

}
Loading

0 comments on commit 589f6ef

Please sign in to comment.