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

Extract OAuth API #18818

Merged
merged 57 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
4ebf4ec
Tmp
benmoriceau Oct 21, 2022
6d8e907
Merge branch 'master' of github.com:airbytehq/airbyte into bmoric/con…
benmoriceau Oct 24, 2022
d930c98
Extract the Attempt API from the V1 API
benmoriceau Oct 24, 2022
2dba567
Add comments
benmoriceau Oct 24, 2022
7c36975
Move Connection API out of configuration API
benmoriceau Oct 24, 2022
0d87509
format
benmoriceau Oct 24, 2022
cf61847
Merge branch 'bmoric/convert-server-to-micronaut' of github.com:airby…
benmoriceau Oct 24, 2022
04e9bb2
format
benmoriceau Oct 24, 2022
c74db48
Rename to Controller
benmoriceau Oct 25, 2022
433dfe5
Merge branch 'bmoric/convert-server-to-micronaut' of github.com:airby…
benmoriceau Oct 25, 2022
415e0c7
Rename to Controller
benmoriceau Oct 25, 2022
7211da6
Add values to the factory
benmoriceau Oct 25, 2022
f503b4c
Change the constructor to use hadler instead of objects needed by the…
benmoriceau Oct 25, 2022
70ce157
Merge branch 'master' of github.com:airbytehq/airbyte into bmoric/ext…
benmoriceau Oct 25, 2022
688f812
Merge branch 'master' of github.com:airbytehq/airbyte into bmoric/ext…
benmoriceau Oct 25, 2022
2103e7d
Update with new tags.
benmoriceau Oct 25, 2022
a5c8522
tmp
benmoriceau Oct 25, 2022
c5aee8f
Fix PMD errors
benmoriceau Oct 25, 2022
50fc3ae
Extract DB migrator
benmoriceau Oct 25, 2022
6b11154
Merge branch 'bmoric/extract-connection-api' of github.com:airbytehq/…
benmoriceau Oct 25, 2022
4e8051e
Add something that I forgot
benmoriceau Oct 26, 2022
99d9d4b
Merge branch 'master' of github.com:airbytehq/airbyte into bmoric/ext…
benmoriceau Oct 26, 2022
aca18c9
Merge branch 'master' of github.com:airbytehq/airbyte into bmoric/ext…
benmoriceau Oct 26, 2022
7254ebb
extract destination definition api
benmoriceau Oct 26, 2022
4d748af
restore destination factory initialization
benmoriceau Oct 26, 2022
e6a56a2
extract destination definition specification api
benmoriceau Oct 26, 2022
709cdc4
format
benmoriceau Oct 26, 2022
aa06c20
Merge branch 'bmoric/extract-db-migration-api' of github.com:airbyteh…
benmoriceau Oct 26, 2022
82360dc
format
benmoriceau Oct 26, 2022
82ccd82
Merge branch 'bmoric/extract-destination-definition-api' of github.co…
benmoriceau Oct 26, 2022
6ecdb17
format
benmoriceau Oct 26, 2022
187c9ea
extract health check api
benmoriceau Oct 26, 2022
f6a5e9b
extract jobs api
benmoriceau Oct 26, 2022
8023bc9
fix test
benmoriceau Oct 27, 2022
bd206a9
Merge branch 'master' of github.com:airbytehq/airbyte into bmoric/ext…
benmoriceau Oct 27, 2022
293c187
format
benmoriceau Oct 27, 2022
89308f5
Merge branch 'master' into bmoric/extract-healt-api
benmoriceau Oct 28, 2022
60fa570
Merge branch 'bmoric/extract-healt-api' of github.com:airbytehq/airby…
benmoriceau Oct 28, 2022
7accc25
Extract logs api
benmoriceau Oct 28, 2022
5151909
Add missing declaration
benmoriceau Oct 28, 2022
0eb77e1
Merge branch 'bmoric/extract-jobs-api' of github.com:airbytehq/airbyt…
benmoriceau Oct 28, 2022
ffb770b
Fix build
benmoriceau Oct 28, 2022
c3cd08e
Merge branch 'master' into bmoric/extract-healt-api
benmoriceau Oct 28, 2022
c65a79b
Merge branch 'bmoric/extract-healt-api' into bmoric/extract-jobs-api
benmoriceau Oct 28, 2022
2142e26
Tmp
benmoriceau Oct 28, 2022
3ed2fee
format and PR comments
benmoriceau Oct 28, 2022
cef5c58
Merge branch 'bmoric/extract-jobs-api' of github.com:airbytehq/airbyt…
benmoriceau Oct 28, 2022
bfaf6b5
Merge branch 'master' of github.com:airbytehq/airbyte into bmoric/ext…
benmoriceau Nov 1, 2022
9b00d89
Extract notification API
benmoriceau Nov 1, 2022
8d07282
Merge branch 'bmoric/extract-jobs-api' of github.com:airbytehq/airbyt…
benmoriceau Nov 1, 2022
4b2361d
Merge branch 'bmoric/extract-logs-api' of github.com:airbytehq/airbyt…
benmoriceau Nov 1, 2022
23d908a
re-organize tags
benmoriceau Nov 1, 2022
24de278
Extract all Oauth
benmoriceau Nov 1, 2022
fa4761d
Fix PMD
benmoriceau Nov 2, 2022
c41a1f9
Merge branch 'bmoric/extract-logs-api' of github.com:airbytehq/airbyt…
benmoriceau Nov 2, 2022
fabfe7d
Merge branch 'bmoric/extract-notification-api' of github.com:airbyteh…
benmoriceau Nov 2, 2022
be863fa
Merge branch 'master' of github.com:airbytehq/airbyte into bmoric/fix…
benmoriceau Nov 2, 2022
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
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 @@ -300,6 +301,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 @@ -356,6 +359,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 @@ -213,7 +209,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 @@ -377,40 +372,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")
Copy link
Contributor

Choose a reason for hiding this comment

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

Double checking that oauths should be plural in the path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, it comes from the generated file:

@Path("/v1/source_oauths")
@Api(description = "the SourceOauth API")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", date = "2022-11-02T15:07:06.363568-04:00[America/New_York]")
public interface SourceOauthApi {

@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