Skip to content

Commit

Permalink
Source TikTok Marketing : Access token is null #14299 (#14461)
Browse files Browse the repository at this point in the history
* Replaced List with Set in order to avoid credentials loosing for case when we have multiple options with the same key on spec

* returned back List to save the order of fields, added distinct() to have a unique path values

* clean up

* [14299] Source TikTok Marketing : Access token is null
added unit tests

* [14299] Source TikTok Marketing : Access token is null
updated javadoc

* Format

Co-authored-by: Tuhai Maksym <kimerinn@gmail.com>
Co-authored-by: Benoit Moriceau <benoit@airbyte.io>
  • Loading branch information
3 people authored Jul 13, 2022
1 parent f412716 commit c308c2f
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ public static SplitSecretConfig splitAndUpdateConfig(final Supplier<UUID> uuidSu
}

/**
* This returns all the path to the airbyte secrets based on a schema spec. The path will be return
* in an ascending alphabetical order.
* This returns all the unique path to the airbyte secrets based on a schema spec. The path will be
* return in an ascending alphabetical order.
*/
public static List<String> getSortedSecretPaths(final JsonNode spec) {
return JsonSchemas.collectPathsThatMeetCondition(
Expand All @@ -178,6 +178,7 @@ public static List<String> getSortedSecretPaths(final JsonNode spec) {
.anyMatch(field -> field.getKey().equals(JsonSecretsProcessor.AIRBYTE_SECRET_FIELD)))
.stream()
.map(JsonPaths::mapJsonSchemaPathToJsonPath)
.distinct()
.sorted()
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ class JsonSecretsProcessorTest {
private static final String ARRAY_OF_ONEOF = "array_of_oneof";
private static final String NESTED_OBJECT = "nested_object";
private static final String NESTED_ONEOF = "nested_oneof";
private static final String ONE_OF_SECRET = "oneof_secret";
private static final String ONE_OF = "oneof";
private static final String OPTIONAL_PASSWORD = "optional_password";
private static final String POSTGRES_SSH_KEY = "postgres_ssh_key";
Expand Down Expand Up @@ -334,6 +335,8 @@ private static Stream<Arguments> scenarioProvider() {
Arguments.of(NESTED_ONEOF, false),
Arguments.of(ONE_OF, true),
Arguments.of(ONE_OF, false),
Arguments.of(ONE_OF_SECRET, true),
Arguments.of(ONE_OF_SECRET, false),
Arguments.of(OPTIONAL_PASSWORD, true),
Arguments.of(OPTIONAL_PASSWORD, false),
Arguments.of(POSTGRES_SSH_KEY, true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.airbyte.config.persistence.split_secrets.test_cases.ArrayTestCase;
import io.airbyte.config.persistence.split_secrets.test_cases.NestedObjectTestCase;
import io.airbyte.config.persistence.split_secrets.test_cases.NestedOneOfTestCase;
import io.airbyte.config.persistence.split_secrets.test_cases.OneOfSecretTestCase;
import io.airbyte.config.persistence.split_secrets.test_cases.OneOfTestCase;
import io.airbyte.config.persistence.split_secrets.test_cases.OptionalPasswordTestCase;
import io.airbyte.config.persistence.split_secrets.test_cases.PostgresSshKeyTestCase;
Expand Down Expand Up @@ -61,6 +62,7 @@ private static Stream<Arguments> provideTestCases() {
new SimpleTestCase(),
new NestedObjectTestCase(),
new OneOfTestCase(),
new OneOfSecretTestCase(),
new ArrayTestCase(),
new ArrayOneOfTestCase(),
new NestedOneOfTestCase(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2022 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.config.persistence.split_secrets.test_cases;

import io.airbyte.config.persistence.split_secrets.SecretCoordinate;
import io.airbyte.config.persistence.split_secrets.SecretPersistence;
import io.airbyte.config.persistence.split_secrets.SecretsHelpersTest;
import io.airbyte.config.persistence.split_secrets.SecretsTestCase;
import java.util.Map;
import java.util.function.Consumer;

public class OneOfSecretTestCase implements SecretsTestCase {

@Override
public String getName() {
return "oneof_secret";
}

@Override
public Map<SecretCoordinate, String> getFirstSecretMap() {
return Map.of(
new SecretCoordinate(PREFIX + SecretsHelpersTest.WORKSPACE_ID + SECRET + SecretsHelpersTest.UUIDS.get(0), 1), "access_token_1",
new SecretCoordinate(PREFIX + SecretsHelpersTest.WORKSPACE_ID + SECRET + SecretsHelpersTest.UUIDS.get(1), 1), "clientId_1",
new SecretCoordinate(PREFIX + SecretsHelpersTest.WORKSPACE_ID + SECRET + SecretsHelpersTest.UUIDS.get(2), 1), "client_secret_1",
new SecretCoordinate(PREFIX + SecretsHelpersTest.WORKSPACE_ID + SECRET + SecretsHelpersTest.UUIDS.get(3), 1), "refresh_token_1");
}

@Override
public Map<SecretCoordinate, String> getSecondSecretMap() {
return Map.of(
new SecretCoordinate(PREFIX + SecretsHelpersTest.WORKSPACE_ID + SECRET + SecretsHelpersTest.UUIDS.get(0), 2), "access_token_2");
}

@Override
public Consumer<SecretPersistence> getPersistenceUpdater() {
return secretPersistence -> {
secretPersistence.write(
new SecretCoordinate(PREFIX + SecretsHelpersTest.WORKSPACE_ID + SECRET + SecretsHelpersTest.UUIDS.get(0), 1),
"access_token_1");
secretPersistence.write(
new SecretCoordinate(PREFIX + SecretsHelpersTest.WORKSPACE_ID + SECRET + SecretsHelpersTest.UUIDS.get(1), 1),
"clientId_1");
secretPersistence.write(
new SecretCoordinate(PREFIX + SecretsHelpersTest.WORKSPACE_ID + SECRET + SecretsHelpersTest.UUIDS.get(2), 1),
"client_secret_1");
secretPersistence.write(
new SecretCoordinate(PREFIX + SecretsHelpersTest.WORKSPACE_ID + SECRET + SecretsHelpersTest.UUIDS.get(3), 1),
"refresh_token_1");
};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"credentials": {
"auth_method": "oauth2.0",
"client_id": "**********",
"client_secret": "**********",
"access_token": "**********",
"refresh_token": "**********"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$.credentials.access_token;$.credentials.client_id;$.credentials.client_secret;$.credentials.refresh_token;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"credentials": {
"auth_method": "oauth2.0",
"client_id": "clientId_1",
"client_secret": "client_secret_1",
"access_token": "access_token_1",
"refresh_token": "refresh_token_1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"credentials": {
"auth_method": "oauth2.0",
"client_id": {
"_secret": "airbyte_workspace_e0eb0554-ffe0-4e9c-9dc0-ed7f52023eb2_secret_2c2ef2b3-259a-4e73-96d1-f56dacee2e5e_v1"
},
"client_secret": {
"_secret": "airbyte_workspace_e0eb0554-ffe0-4e9c-9dc0-ed7f52023eb2_secret_1206db5b-b968-4df1-9a76-f3fcdae7e307_v1"
},
"access_token": {
"_secret": "airbyte_workspace_e0eb0554-ffe0-4e9c-9dc0-ed7f52023eb2_secret_9eba44d8-51e7-48f1-bde2-619af0e42c22_v1"
},
"refresh_token": {
"_secret": "airbyte_workspace_e0eb0554-ffe0-4e9c-9dc0-ed7f52023eb2_secret_c03ef566-79a7-4e77-b6f3-d23d2528f25a_v1"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"type": "object",
"properties": {
"credentials": {
"title": "Authorization Method",
"type": "object",
"oneOf": [
{
"type": "object",
"title": "OAuth2.0",
"required": [
"client_id",
"client_secret",
"access_token",
"refresh_token"
],
"properties": {
"auth_method": {
"type": "string",
"const": "oauth2.0",
"enum": ["oauth2.0"],
"default": "oauth2.0",
"order": 0
},
"client_id": {
"type": "string",
"title": "Client ID",
"description": "The Client ID of your application.",
"airbyte_secret": true
},
"client_secret": {
"type": "string",
"title": "Client Secret",
"description": "The Client Secret of your application.",
"airbyte_secret": true
},
"access_token": {
"type": "string",
"title": "Access Token",
"description": "Access Token for making authenticated requests.",
"airbyte_secret": true
},
"refresh_token": {
"type": "string",
"title": "Refresh Token",
"description": "Refresh Token to renew the expired Access Token.",
"default": "",
"airbyte_secret": true
}
}
},
{
"title": "Access Token",
"type": "object",
"required": ["access_token"],
"properties": {
"auth_method": {
"type": "string",
"const": "access_token",
"enum": ["access_token"],
"default": "access_token",
"order": 0
},
"access_token": {
"type": "string",
"title": "Access Token",
"airbyte_secret": true
}
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"credentials": {
"auth_method": "access_token",
"access_token": "access_token_2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"credentials": {
"auth_method": "access_token",
"access_token": {
"_secret": "airbyte_workspace_e0eb0554-ffe0-4e9c-9dc0-ed7f52023eb2_secret_9eba44d8-51e7-48f1-bde2-619af0e42c22_v2"
}
}
}

0 comments on commit c308c2f

Please sign in to comment.