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

Start airbyte-oauth module #5812

Merged
merged 1 commit into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion airbyte-api/src/main/openapi/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2985,7 +2985,7 @@ components:
required:
- destinationDefinitionId
properties:
sourceDefinitionId:
destinationDefinitionId:
$ref: "#/components/schemas/DestinationDefinitionId"
workspaceId:
$ref: "#/components/schemas/WorkspaceId"
Expand Down
7 changes: 7 additions & 0 deletions airbyte-oauth/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id "java-library"
}

dependencies {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* MIT License
*
* Copyright (c) 2020 Airbyte
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package io.airbyte.oauth;

import java.util.Map;
import java.util.UUID;

public interface OAuthFlowImplementation {

String getConsentUrl();

Map<String, Object> completeOAuth(UUID workspaceId, Map<String, Object> queryParams);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* MIT License
*
* Copyright (c) 2020 Airbyte
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package io.airbyte.oauth;

import com.google.common.collect.ImmutableMap;
import java.util.Map;

public class OAuthImplementationFactory {

static final Map<String, OAuthFlowImplementation> OAUTH_FLOW_MAPPING =
ImmutableMap.<String, OAuthFlowImplementation>builder()
.build();

public static OAuthFlowImplementation create(String imageName) {
if (OAUTH_FLOW_MAPPING.containsKey(imageName)) {
return OAUTH_FLOW_MAPPING.get(imageName);
} else {
throw new IllegalStateException(
String.format("Requested OAuth implementation for %s, but it is not included in the oauth mapping.", imageName));
}
}

}
1 change: 1 addition & 0 deletions airbyte-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ dependencies {
implementation project(":airbyte-json-validation")
implementation project(':airbyte-migration')
implementation project(':airbyte-notification')
implementation project(':airbyte-oauth')
implementation project(':airbyte-protocol:models')
implementation project(':airbyte-scheduler:client')
implementation project(':airbyte-scheduler:models')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ public ConfigurationApi(final ConfigRepository configRepository,
operationsHandler);
webBackendSourceHandler = new WebBackendSourceHandler(sourceHandler, schedulerHandler, workspaceHelper);
webBackendDestinationHandler = new WebBackendDestinationHandler(destinationHandler, schedulerHandler, workspaceHelper);
oAuthHandler = new OAuthHandler(configRepository);
healthCheckHandler = new HealthCheckHandler(configRepository);
archiveHandler = new ArchiveHandler(configs.getAirbyteVersion(), configRepository, jobPersistence, workspaceHelper, archiveTtlManager);
logsHandler = new LogsHandler();
openApiConfigHandler = new OpenApiConfigHandler();
dbMigrationHandler = new DbMigrationHandler(configsDatabase, jobsDatabase);
oAuthHandler = new OAuthHandler();
this.configs = configs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,54 @@
import io.airbyte.api.model.DestinationOauthConsentRequest;
import io.airbyte.api.model.OAuthConsentRead;
import io.airbyte.api.model.SourceOauthConsentRequest;
import io.airbyte.server.errors.ApplicationErrorKnownException;
import io.airbyte.config.StandardDestinationDefinition;
import io.airbyte.config.StandardSourceDefinition;
import io.airbyte.config.persistence.ConfigNotFoundException;
import io.airbyte.config.persistence.ConfigRepository;
import io.airbyte.oauth.OAuthFlowImplementation;
import io.airbyte.oauth.OAuthImplementationFactory;
import io.airbyte.validation.json.JsonValidationException;
import java.io.IOException;
import java.util.Map;

public class OAuthHandler {

public OAuthConsentRead getSourceOAuthConsent(SourceOauthConsentRequest sourceDefinitionIdRequestBody) {
// TODO: Implement OAuth module to be called here https://github.com/airbytehq/airbyte/issues/5641
throw new ApplicationErrorKnownException("Source connector does not supports OAuth yet.");
private final ConfigRepository configRepository;

public OAuthHandler(ConfigRepository configRepository) {
this.configRepository = configRepository;
}

public OAuthConsentRead getSourceOAuthConsent(SourceOauthConsentRequest sourceDefinitionIdRequestBody)
throws JsonValidationException, ConfigNotFoundException, IOException {
final StandardSourceDefinition standardSourceDefinition = configRepository
.getStandardSourceDefinition(sourceDefinitionIdRequestBody.getSourceDefinitionId());
final OAuthFlowImplementation oAuthFlowImplementation = OAuthImplementationFactory.create(standardSourceDefinition.getDockerRepository());
return new OAuthConsentRead().consentUrl(oAuthFlowImplementation.getConsentUrl());
}

public OAuthConsentRead getDestinationOAuthConsent(DestinationOauthConsentRequest destinationDefinitionIdRequestBody) {
// TODO: Implement OAuth module to be called here https://github.com/airbytehq/airbyte/issues/5641
throw new ApplicationErrorKnownException("Destination connector does not supports OAuth yet.");
public OAuthConsentRead getDestinationOAuthConsent(DestinationOauthConsentRequest destinationDefinitionIdRequestBody)
throws JsonValidationException, ConfigNotFoundException, IOException {
final StandardDestinationDefinition standardDestinationDefinition =
configRepository.getStandardDestinationDefinition(destinationDefinitionIdRequestBody.getDestinationDefinitionId());
final OAuthFlowImplementation oAuthFlowImplementation = OAuthImplementationFactory.create(standardDestinationDefinition.getDockerRepository());
return new OAuthConsentRead().consentUrl(oAuthFlowImplementation.getConsentUrl());
}

public Map<String, Object> completeSourceOAuth(CompleteSourceOauthRequest oauthSourceRequestBody) {
// TODO: Implement OAuth module to be called here https://github.com/airbytehq/airbyte/issues/5641
throw new ApplicationErrorKnownException("Source connector does not supports OAuth yet.");
public Map<String, Object> completeSourceOAuth(CompleteSourceOauthRequest oauthSourceRequestBody)
throws JsonValidationException, ConfigNotFoundException, IOException {
final StandardSourceDefinition standardSourceDefinition =
configRepository.getStandardSourceDefinition(oauthSourceRequestBody.getSourceDefinitionId());
final OAuthFlowImplementation oAuthFlowImplementation = OAuthImplementationFactory.create(standardSourceDefinition.getDockerRepository());
return oAuthFlowImplementation.completeOAuth(oauthSourceRequestBody.getWorkspaceId(), oauthSourceRequestBody.getQueryParams());
}

public Map<String, Object> completeDestinationOAuth(CompleteDestinationOAuthRequest oauthDestinationRequestBody) {
// TODO: Implement OAuth module to be called here https://github.com/airbytehq/airbyte/issues/5641
throw new ApplicationErrorKnownException("Destination connector does not supports OAuth yet.");
public Map<String, Object> completeDestinationOAuth(CompleteDestinationOAuthRequest oauthDestinationRequestBody)
throws JsonValidationException, ConfigNotFoundException, IOException {
final StandardDestinationDefinition standardDestinationDefinition =
configRepository.getStandardDestinationDefinition(oauthDestinationRequestBody.getDestinationDefinitionId());
final OAuthFlowImplementation oAuthFlowImplementation = OAuthImplementationFactory.create(standardDestinationDefinition.getDockerRepository());
return oAuthFlowImplementation.completeOAuth(oauthDestinationRequestBody.getWorkspaceId(), oauthDestinationRequestBody.getQueryParams());
}

}
2 changes: 1 addition & 1 deletion docs/reference/api/generated-api-html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6311,7 +6311,7 @@ <h3><a name="DestinationIdRequestBody"><code>DestinationIdRequestBody</code> - <
<h3><a name="DestinationOauthConsentRequest"><code>DestinationOauthConsentRequest</code> - </a> <a class="up" href="#__Models">Up</a></h3>
<div class='model-description'></div>
<div class="field-items">
<div class="param">sourceDefinitionId (optional)</div><div class="param-desc"><span class="param-type"><a href="#UUID">UUID</a></span> format: uuid</div>
<div class="param">destinationDefinitionId </div><div class="param-desc"><span class="param-type"><a href="#UUID">UUID</a></span> format: uuid</div>
<div class="param">workspaceId (optional)</div><div class="param-desc"><span class="param-type"><a href="#UUID">UUID</a></span> format: uuid</div>
</div> <!-- field-items -->
</div>
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ if(!System.getenv().containsKey("SUB_BUILD") || System.getenv().get("SUB_BUILD")
include ':airbyte-e2e-testing'
include ':airbyte-migration'
include ':airbyte-notification'
include ':airbyte-oauth'
include ':airbyte-scheduler:app'
include ':airbyte-scheduler:client'
include ':airbyte-scheduler:models'
Expand Down