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

Modify oauthSpecification to allow working with oneOfs #6456

Merged
merged 7 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
40 changes: 34 additions & 6 deletions airbyte-api/src/main/openapi/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1944,18 +1944,46 @@ components:
OAuth2Specification:
description: An object containing any metadata needed to describe this connector's Oauth flow
type: object
required:
- rootObject
- oauthFlowInitParameters
- oauthFlowOutputParameters
properties:
rootObject:
description:
"A list of strings representing a pointer to the root object which contains any oauth parameters in the ConnectorSpecification.

Examples:

if oauth parameters were contained inside the top level, rootObject=[]
If they were nested inside another object {'credentials': {'app_id' etc...}, rootObject=['credentials']
If they were inside a oneOf {'switch': {oneOf: [{client_id...}, {non_oauth_param]}}, rootObject=['switch', 0]
"
type: array
items:
type: string
oauthFlowInitParameters:
description:
"Pointers to the fields in the ConnectorSpecification which are needed to obtain the initial refresh/access tokens for the OAuth flow.
Each inner array represents the path in the ConnectorSpecification of the referenced field.
"Pointers to the fields in the rootObject needed to obtain the initial refresh/access tokens for the OAuth flow.
Each inner array represents the path in the rootObject of the referenced field.
For example.
Assume the ConnectorSpecification contains params 'app_secret', 'app_id' which are needed to get the initial refresh token.
If they are not nested in the config, then the array would look like this [['app_secret'], ['app_id']]
If they are nested inside, say, an object called 'auth_params' then this array would be [['auth_params', 'app_secret'], ['auth_params', 'app_id']]"
Assume the rootObject contains params 'app_secret', 'app_id' which are needed to get the initial refresh token.
If they are not nested in the rootObject, then the array would look like this [['app_secret'], ['app_id']]
If they are nested inside an object called 'auth_params' then this array would be [['auth_params', 'app_secret'], ['auth_params', 'app_id']]"
type: array
items:
description: A list of strings denoting a pointer into the rootObject for where to find this property
type: array
items:
type: string
oauthFlowOutputParameters:
description:
"Pointers to the fields in the rootObject which can be populated from successfully completing the oauth flow using the init parameters.
This is typically a refresh/access token.
Each inner array represents the path in the rootObject of the referenced field."
type: array
items:
description: A list of strings which describes each parameter's path inside the ConnectionSpecification
description: A list of strings denoting a pointer into the rootObject for where to find this property
type: array
items:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,46 @@ definitions:
OAuth2Specification:
description: An object containing any metadata needed to describe this connector's Oauth flow
type: object
required:
- rootObject
- oauthFlowInitParameters
- oauthFlowOutputParameters
properties:
rootObject:
description:
"A list of strings representing a pointer to the root object which contains any oauth parameters in the ConnectorSpecification.

Examples:

if oauth parameters were contained inside the top level, rootObject=[]
If they were nested inside another object {'credentials': {'app_id' etc...}, rootObject=['credentials']
If they were inside a oneOf {'switch': {oneOf: [{client_id...}, {non_oauth_param]}}, rootObject=['switch', 0]
"
type: array
items:
type: string
oauthFlowInitParameters:
description:
"Pointers to the fields in the ConnectorSpecification which are needed to obtain the initial refresh/access tokens for the OAuth flow.
Each inner array represents the path in the ConnectorSpecification of the referenced field.
"Pointers to the fields in the rootObject needed to obtain the initial refresh/access tokens for the OAuth flow.
Each inner array represents the path in the rootObject of the referenced field.
For example.
Assume the ConnectorSpecification contains params 'app_secret', 'app_id' which are needed to get the initial refresh token.
If they are not nested in the config, then the array would look like this [['app_secret'], ['app_id']]
If they are nested inside, say, an object called 'auth_params' then this array would be [['auth_params', 'app_secret'], ['auth_params', 'app_id']]"
Assume the rootObject contains params 'app_secret', 'app_id' which are needed to get the initial refresh token.
If they are not nested in the rootObject, then the array would look like this [['app_secret'], ['app_id']]
If they are nested inside an object called 'auth_params' then this array would be [['auth_params', 'app_secret'], ['auth_params', 'app_id']]"
type: array
items:
description: A list of strings denoting a pointer into the rootObject for where to find this property
type: array
items:
type: string
oauthFlowOutputParameters:
description:
"Pointers to the fields in the rootObject which can be populated from successfully completing the oauth flow using the init parameters.
This is typically a refresh/access token.
Each inner array represents the path in the rootObject of the referenced field."
type: array
items:
description: A list of strings which describe the path inside a JSON object for finding the
description: A list of strings denoting a pointer into the rootObject for where to find this property
type: array
items:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.airbyte.api.model.AuthSpecification;
import io.airbyte.api.model.OAuth2Specification;
import io.airbyte.protocol.models.ConnectorSpecification;

import java.util.Optional;

public class OauthModelConverter {
Expand All @@ -41,7 +42,10 @@ public static Optional<AuthSpecification> getAuthSpec(ConnectorSpecification spe
if (incomingAuthSpec.getAuthType() == io.airbyte.protocol.models.AuthSpecification.AuthType.OAUTH_2_0) {
authSpecification.authType(AuthSpecification.AuthTypeEnum.OAUTH2_0)
.oauth2Specification(new OAuth2Specification()
.oauthFlowInitParameters(incomingAuthSpec.getOauth2Specification().getOauthFlowInitParameters()));
.rootObject(incomingAuthSpec.getOauth2Specification().getRootObject())
.oauthFlowInitParameters(incomingAuthSpec.getOauth2Specification().getOauthFlowInitParameters())
.oauthFlowOutputParameters(incomingAuthSpec.getOauth2Specification().getOauthFlowOutputParameters())
);
}

return Optional.ofNullable(authSpecification);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package io.airbyte.server.converters;

import io.airbyte.commons.json.Jsons;
import io.airbyte.protocol.models.AuthSpecification;
import io.airbyte.protocol.models.ConnectorSpecification;
import io.airbyte.protocol.models.OAuth2Specification;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.*;

class OauthModelConverterTest {

private static Stream<Arguments> testProvider() {
return Stream.of(
// all fields filled out with nesting
Arguments.of(
List.of(List.of("init1"), List.of("init2-1", "init2-2")),
List.of(List.of("output1"), List.of("output2-1", "output2-2")),
List.of("path")),
// init params only
Arguments.of(
List.of(List.of("init1"), List.of("init2-1", "init2-2")),
List.of(List.of()),
List.of()),
// output params only
Arguments.of(
List.of(List.of()),
List.of(List.of("output1"), List.of("output2-1", "output2-2")),
List.of()),
// rootObject only
Arguments.of(
List.of(List.of()),
List.of(List.of()),
List.of("path"))
);
}

@ParameterizedTest
@MethodSource("testProvider")
public void testIt(List<List<String>> initParams, List<List<String>> outputParams, List<String> rootObject) {
ConnectorSpecification input = new ConnectorSpecification().withAuthSpecification(
new AuthSpecification()
.withAuthType(AuthSpecification.AuthType.OAUTH_2_0)
.withOauth2Specification(new OAuth2Specification()
.withOauthFlowInitParameters(initParams)
.withOauthFlowOutputParameters(outputParams)
.withRootObject(rootObject)
)
);

io.airbyte.api.model.AuthSpecification expected = new io.airbyte.api.model.AuthSpecification()
.authType(io.airbyte.api.model.AuthSpecification.AuthTypeEnum.OAUTH2_0)
.oauth2Specification(
new io.airbyte.api.model.OAuth2Specification()
.oauthFlowInitParameters(initParams)
.oauthFlowOutputParameters(outputParams)
.rootObject(rootObject)
);

Optional<io.airbyte.api.model.AuthSpecification> authSpec = OauthModelConverter.getAuthSpec(input);
assertTrue(authSpec.isPresent());
assertEquals(expected, authSpec.get());
}
}
16 changes: 8 additions & 8 deletions docs/reference/api/generated-api-html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2299,9 +2299,7 @@ <h3 class="field-label">Example data</h3>
"destinationDefinitionId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91",
"authSpecification" : {
"auth_type" : "oauth2.0",
"oauth2Specification" : {
"oauthFlowInitParameters" : [ [ "oauthFlowInitParameters", "oauthFlowInitParameters" ], [ "oauthFlowInitParameters", "oauthFlowInitParameters" ] ]
}
"oauth2Specification" : ""
},
"jobInfo" : {
"createdAt" : 0,
Expand Down Expand Up @@ -4650,9 +4648,7 @@ <h3 class="field-label">Example data</h3>
"sourceDefinitionId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91",
"authSpecification" : {
"auth_type" : "oauth2.0",
"oauth2Specification" : {
"oauthFlowInitParameters" : [ [ "oauthFlowInitParameters", "oauthFlowInitParameters" ], [ "oauthFlowInitParameters", "oauthFlowInitParameters" ] ]
}
"oauth2Specification" : ""
},
"jobInfo" : {
"createdAt" : 0,
Expand Down Expand Up @@ -6462,7 +6458,7 @@ <h3><a name="AuthSpecification"><code>AuthSpecification</code> - </a> <a class="
<div class="param">auth_type (optional)</div><div class="param-desc"><span class="param-type"><a href="#string">String</a></span> </div>
<div class="param-enum-header">Enum:</div>
<div class="param-enum">oauth2.0</div>
<div class="param">oauth2Specification (optional)</div><div class="param-desc"><span class="param-type"><a href="#OAuth2Specification">OAuth2Specification</a></span> </div>
<div class="param">oauth2Specification (optional)</div><div class="param-desc"><span class="param-type"><a href="#">oas_any_type_not_mapped</a></span> If the connector supports OAuth, this field should be non-null. </div>
</div> <!-- field-items -->
</div>
<div class="model">
Expand Down Expand Up @@ -6967,7 +6963,11 @@ <h3><a name="NotificationType"><code>NotificationType</code> - </a> <a class="up
<h3><a name="OAuth2Specification"><code>OAuth2Specification</code> - </a> <a class="up" href="#__Models">Up</a></h3>
<div class='model-description'>An object containing any metadata needed to describe this connector's Oauth flow</div>
<div class="field-items">
<div class="param">oauthFlowInitParameters (optional)</div><div class="param-desc"><span class="param-type"><a href="#array">array[array[String]]</a></span> Pointers to the fields in the ConnectorSpecification which are needed to obtain the initial refresh/access tokens for the OAuth flow. Each inner array represents the path in the ConnectorSpecification of the referenced field. For example. Assume the ConnectorSpecification contains params 'app_secret', 'app_id' which are needed to get the initial refresh token. If they are not nested in the config, then the array would look like this [['app_secret'], ['app_id']] If they are nested inside, say, an object called 'auth_params' then this array would be [['auth_params', 'app_secret'], ['auth_params', 'app_id']] </div>
<div class="param">rootObject </div><div class="param-desc"><span class="param-type"><a href="#string">array[String]</a></span> A list of strings representing a pointer to the root object which contains any oauth parameters in the ConnectorSpecification.
Examples:
if oauth parameters were contained inside the top level, rootObject=[] If they were nested inside another object {'credentials': {'app_id' etc...}, rootObject=['credentials'] If they were inside a oneOf {'switch': {oneOf: [{client_id...}, {non_oauth_param]}}, rootObject=['switch', 0] </div>
<div class="param">oauthFlowInitParameters </div><div class="param-desc"><span class="param-type"><a href="#array">array[array[String]]</a></span> Pointers to the fields in the rootObject needed to obtain the initial refresh/access tokens for the OAuth flow. Each inner array represents the path in the rootObject of the referenced field. For example. Assume the rootObject contains params 'app_secret', 'app_id' which are needed to get the initial refresh token. If they are not nested in the rootObject, then the array would look like this [['app_secret'], ['app_id']] If they are nested inside an object called 'auth_params' then this array would be [['auth_params', 'app_secret'], ['auth_params', 'app_id']] </div>
<div class="param">oauthFlowOutputParameters </div><div class="param-desc"><span class="param-type"><a href="#array">array[array[String]]</a></span> Pointers to the fields in the rootObject which can be populated from successfully completing the oauth flow using the init parameters. This is typically a refresh/access token. Each inner array represents the path in the rootObject of the referenced field. </div>
</div> <!-- field-items -->
</div>
<div class="model">
Expand Down