-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎉 Source smartsheets: oauth support (#9792)
* Added SAT, fixed tests, fixed schema validation error * Added Oauth support for smartsheets source * minor changes after review * added advanced_auth property instead of authSpecification * Updated connector version * removed empty unittests * updated version in source_specs.yaml
- Loading branch information
Showing
13 changed files
with
272 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
airbyte-integrations/connectors/source-smartsheets/acceptance-test-docker.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Build latest connector image | ||
docker build . -t $(cat acceptance-test-config.yml | grep "connector_image" | head -n 1 | cut -d: -f2-) | ||
|
||
# Pull latest acctest image | ||
docker pull airbyte/source-acceptance-test:latest | ||
|
||
# Run | ||
docker run --rm -it \ | ||
-v /var/run/docker.sock:/var/run/docker.sock \ | ||
-v /tmp:/tmp \ | ||
-v $(pwd):/test_input \ | ||
airbyte/source-acceptance-test \ | ||
--acceptance-test-config /test_input | ||
|
43 changes: 43 additions & 0 deletions
43
airbyte-integrations/connectors/source-smartsheets/sample_files/catalog.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"streams": [ | ||
{ | ||
"stream": { | ||
"name": "aws_s3_sample", | ||
"supported_sync_modes": ["full_refresh"], | ||
"source_defined_cursor": false, | ||
"source_defined_primary_key": [["id"]], | ||
"json_schema": { | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "string" | ||
}, | ||
"first_name": { | ||
"type": "string" | ||
}, | ||
"last_name": { | ||
"type": "string" | ||
}, | ||
"email": { | ||
"type": "string" | ||
}, | ||
"gender": { | ||
"type": "string" | ||
}, | ||
"ip_address": { | ||
"type": "string" | ||
}, | ||
"dob": { | ||
"type": "string", | ||
"format": "date" | ||
} | ||
} | ||
} | ||
}, | ||
"sync_mode": "full_refresh", | ||
"cursor_field": null, | ||
"destination_sync_mode": "overwrite" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
airbyte-integrations/connectors/source-smartsheets/unit_tests/unit_test.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
airbyte-oauth/src/main/java/io/airbyte/oauth/flows/SmartsheetsOAuthFlow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.oauth.flows; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.ImmutableMap; | ||
import io.airbyte.config.persistence.ConfigRepository; | ||
import io.airbyte.oauth.BaseOAuth2Flow; | ||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.net.http.HttpClient; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.function.Supplier; | ||
import org.apache.http.client.utils.URIBuilder; | ||
|
||
public class SmartsheetsOAuthFlow extends BaseOAuth2Flow { | ||
|
||
private static final String AUTHORIZE_URL = "https://app.smartsheet.com/b/authorize"; | ||
private static final String ACCESS_TOKEN_URL = "https://api.smartsheet.com/2.0/token"; | ||
|
||
public SmartsheetsOAuthFlow(final ConfigRepository configRepository, final HttpClient httpClient) { | ||
super(configRepository, httpClient); | ||
} | ||
|
||
@VisibleForTesting | ||
public SmartsheetsOAuthFlow(final ConfigRepository configRepository, final HttpClient httpClient, final Supplier<String> stateSupplier) { | ||
super(configRepository, httpClient, stateSupplier); | ||
} | ||
|
||
@Override | ||
protected String formatConsentUrl(final UUID definitionId, | ||
final String clientId, | ||
final String redirectUrl, | ||
final JsonNode inputOAuthConfiguration) | ||
throws IOException { | ||
try { | ||
return new URIBuilder(AUTHORIZE_URL) | ||
.addParameter("client_id", clientId) | ||
.addParameter("response_type", "code") | ||
.addParameter("state", getState()) | ||
.addParameter("scope", "READ_SHEETS") | ||
.build().toString(); | ||
} catch (final URISyntaxException e) { | ||
throw new IOException("Failed to format Consent URL for OAuth flow", e); | ||
} | ||
} | ||
|
||
@Override | ||
protected String getAccessTokenUrl(final JsonNode inputOAuthConfiguration) { | ||
return ACCESS_TOKEN_URL; | ||
} | ||
|
||
@Override | ||
protected Map<String, Object> extractOAuthOutput(final JsonNode data, final String accessTokenUrl) { | ||
Preconditions.checkArgument(data.has("access_token"), "Missing 'access_token' in query params from %s", ACCESS_TOKEN_URL); | ||
return Map.of("access_token", data.get("access_token").asText()); | ||
} | ||
|
||
@Override | ||
public List<String> getDefaultOAuthOutputPath() { | ||
return List.of(); | ||
} | ||
|
||
@Override | ||
protected Map<String, String> getAccessTokenQueryParameters(final String clientId, | ||
final String clientSecret, | ||
final String authCode, | ||
final String redirectUrl) { | ||
return ImmutableMap.<String, String>builder() | ||
// required | ||
.put("grant_type", "authorization_code") | ||
.put("client_id", clientId) | ||
.put("client_secret", clientSecret) | ||
.put("code", authCode) | ||
.build(); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
airbyte-oauth/src/test/java/io/airbyte/oauth/flows/SmartsheetsOAuthFlowTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.oauth.flows; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.airbyte.oauth.BaseOAuthFlow; | ||
import io.airbyte.oauth.MoreOAuthParameters; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class SmartsheetsOAuthFlowTest extends BaseOAuthFlowTest { | ||
|
||
@Override | ||
protected BaseOAuthFlow getOAuthFlow() { | ||
return new SmartsheetsOAuthFlow(getConfigRepository(), getHttpClient(), this::getConstantState); | ||
} | ||
|
||
@Override | ||
protected List<String> getExpectedOutputPath() { | ||
return List.of(); | ||
} | ||
|
||
@Override | ||
protected String getExpectedConsentUrl() { | ||
return "https://app.smartsheet.com/b/authorize?client_id=test_client_id&response_type=code&state=state&scope=READ_SHEETS"; | ||
} | ||
|
||
@Override | ||
protected Map<String, String> getExpectedOutput() { | ||
return Map.of( | ||
"access_token", "access_token_response", | ||
"client_id", MoreOAuthParameters.SECRET_MASK, | ||
"client_secret", MoreOAuthParameters.SECRET_MASK); | ||
} | ||
|
||
@Override | ||
protected JsonNode getCompleteOAuthOutputSpecification() { | ||
return getJsonSchema(Map.of("access_token", Map.of("type", "string"))); | ||
} | ||
|
||
@Override | ||
protected Map<String, String> getExpectedFilteredOutput() { | ||
return Map.of( | ||
"access_token", "access_token_response", | ||
"client_id", MoreOAuthParameters.SECRET_MASK); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters