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 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
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
14 changes: 11 additions & 3 deletions airbyte-cdk/python/airbyte_cdk/models/airbyte_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,17 @@ class DestinationSyncMode(Enum):


class OAuth2Specification(BaseModel):
oauthFlowInitParameters: Optional[List[List[str]]] = Field(
None,
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. 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']]",
rootObject: List[str] = Field(
...,
description="A list of strings representing a pointer to the root object which contains any oauth parameters in the ConnectorSpecification.\nExamples:\nif 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] ",
)
oauthFlowInitParameters: List[List[str]] = Field(
...,
description="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']]",
)
oauthFlowOutputParameters: List[List[str]] = Field(
...,
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.",
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,17 @@ class DestinationSyncMode(Enum):


class OAuth2Specification(BaseModel):
oauthFlowInitParameters: Optional[List[List[str]]] = Field(
None,
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. 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']]",
rootObject: List[str] = Field(
...,
description="A list of strings representing a pointer to the root object which contains any oauth parameters in the ConnectorSpecification.\nExamples:\nif 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] ",
)
oauthFlowInitParameters: List[List[str]] = Field(
...,
description="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']]",
)
oauthFlowOutputParameters: List[List[str]] = Field(
...,
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.",
)


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 @@ -41,7 +41,9 @@ 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,89 @@
/*
* 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.server.converters;

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

import io.airbyte.protocol.models.AuthSpecification;
import io.airbyte.protocol.models.ConnectorSpecification;
import io.airbyte.protocol.models.OAuth2Specification;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

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());
}

}
10 changes: 9 additions & 1 deletion docs/reference/api/generated-api-html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2300,6 +2300,8 @@ <h3 class="field-label">Example data</h3>
"authSpecification" : {
"auth_type" : "oauth2.0",
"oauth2Specification" : {
"oauthFlowOutputParameters" : [ [ "oauthFlowOutputParameters", "oauthFlowOutputParameters" ], [ "oauthFlowOutputParameters", "oauthFlowOutputParameters" ] ],
"rootObject" : [ "rootObject", "rootObject" ],
"oauthFlowInitParameters" : [ [ "oauthFlowInitParameters", "oauthFlowInitParameters" ], [ "oauthFlowInitParameters", "oauthFlowInitParameters" ] ]
}
},
Expand Down Expand Up @@ -4651,6 +4653,8 @@ <h3 class="field-label">Example data</h3>
"authSpecification" : {
"auth_type" : "oauth2.0",
"oauth2Specification" : {
"oauthFlowOutputParameters" : [ [ "oauthFlowOutputParameters", "oauthFlowOutputParameters" ], [ "oauthFlowOutputParameters", "oauthFlowOutputParameters" ] ],
"rootObject" : [ "rootObject", "rootObject" ],
"oauthFlowInitParameters" : [ [ "oauthFlowInitParameters", "oauthFlowInitParameters" ], [ "oauthFlowInitParameters", "oauthFlowInitParameters" ] ]
}
},
Expand Down Expand Up @@ -6967,7 +6971,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