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

return auth spec in the API #6121

Merged
merged 1 commit into from
Sep 16, 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
34 changes: 34 additions & 0 deletions airbyte-api/src/main/openapi/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,34 @@ components:
description: The specification for what values are required to configure the sourceDefinition.
type: object
example: { user: { type: string } }
SourceAuthSpecification:
$ref: "#/components/schemas/AuthSpecification"
AuthSpecification:
type: object
properties:
auth_type:
type: string
enum: ["oauth2.0"] # Future auth types should be added here
oauth2Specification:
"$ref": "#/components/schemas/OAuth2Specification"
OAuth2Specification:
description: An object containing any metadata needed to describe this connector's Oauth flow
type: object
properties:
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.
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']]"
type: array
items:
description: A list of strings which describes each parameter's path inside the ConnectionSpecification
type: array
items:
type: string
SourceDefinitionSpecificationRead:
type: object
required:
Expand All @@ -1918,6 +1946,8 @@ components:
type: string
connectionSpecification:
$ref: "#/components/schemas/SourceDefinitionSpecification"
authSpecification:
$ref: "#/components/schemas/SourceAuthSpecification"
jobInfo:
$ref: "#/components/schemas/SynchronousJobRead"
# SOURCE
Expand Down Expand Up @@ -2018,6 +2048,8 @@ components:
DestinationDefinitionId:
type: string
format: uuid
DestinationAuthSpecification:
$ref: "#/components/schemas/AuthSpecification"
DestinationDefinitionIdRequestBody:
type: object
required:
Expand Down Expand Up @@ -2101,6 +2133,8 @@ components:
type: string
connectionSpecification:
$ref: "#/components/schemas/DestinationDefinitionSpecification"
authSpecification:
$ref: "#/components/schemas/DestinationAuthSpecification"
jobInfo:
$ref: "#/components/schemas/SynchronousJobRead"
supportedDestinationSyncModes:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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 io.airbyte.api.model.AuthSpecification;
import io.airbyte.api.model.OAuth2Specification;
import io.airbyte.protocol.models.ConnectorSpecification;
import java.util.Optional;

public class OauthModelConverter {

public static Optional<AuthSpecification> getAuthSpec(ConnectorSpecification spec) {
if (spec.getAuthSpecification() == null) {
return Optional.empty();
}
io.airbyte.protocol.models.AuthSpecification incomingAuthSpec = spec.getAuthSpecification();

AuthSpecification authSpecification = new AuthSpecification();
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()));
}

return Optional.ofNullable(authSpecification);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import io.airbyte.api.model.AuthSpecification;
import io.airbyte.api.model.CheckConnectionRead;
import io.airbyte.api.model.CheckConnectionRead.StatusEnum;
import io.airbyte.api.model.ConnectionIdRequestBody;
Expand Down Expand Up @@ -67,6 +68,7 @@
import io.airbyte.server.converters.CatalogConverter;
import io.airbyte.server.converters.ConfigurationUpdate;
import io.airbyte.server.converters.JobConverter;
import io.airbyte.server.converters.OauthModelConverter;
import io.airbyte.server.converters.SpecFetcher;
import io.airbyte.validation.json.JsonSchemaValidator;
import io.airbyte.validation.json.JsonValidationException;
Expand Down Expand Up @@ -246,11 +248,18 @@ public SourceDefinitionSpecificationRead getSourceDefinitionSpecification(Source
final String imageName = DockerUtils.getTaggedImageName(source.getDockerRepository(), source.getDockerImageTag());
final SynchronousResponse<ConnectorSpecification> response = getConnectorSpecification(imageName);
final ConnectorSpecification spec = response.getOutput();
return new SourceDefinitionSpecificationRead()
SourceDefinitionSpecificationRead specRead = new SourceDefinitionSpecificationRead()
.jobInfo(JobConverter.getSynchronousJobRead(response))
.connectionSpecification(spec.getConnectionSpecification())
.documentationUrl(spec.getDocumentationUrl().toString())
.sourceDefinitionId(sourceDefinitionId);

Optional<AuthSpecification> authSpec = OauthModelConverter.getAuthSpec(spec);
if (authSpec.isPresent()) {
specRead.setAuthSpecification(authSpec.get());
}

return specRead;
}

public DestinationDefinitionSpecificationRead getDestinationSpecification(DestinationDefinitionIdRequestBody destinationDefinitionIdRequestBody)
Expand All @@ -260,14 +269,22 @@ public DestinationDefinitionSpecificationRead getDestinationSpecification(Destin
final String imageName = DockerUtils.getTaggedImageName(destination.getDockerRepository(), destination.getDockerImageTag());
final SynchronousResponse<ConnectorSpecification> response = getConnectorSpecification(imageName);
final ConnectorSpecification spec = response.getOutput();
return new DestinationDefinitionSpecificationRead()

DestinationDefinitionSpecificationRead specRead = new DestinationDefinitionSpecificationRead()
.jobInfo(JobConverter.getSynchronousJobRead(response))
.supportedDestinationSyncModes(Enums.convertListTo(spec.getSupportedDestinationSyncModes(), DestinationSyncMode.class))
.connectionSpecification(spec.getConnectionSpecification())
.documentationUrl(spec.getDocumentationUrl().toString())
.supportsNormalization(spec.getSupportsNormalization())
.supportsDbt(spec.getSupportsDBT())
.destinationDefinitionId(destinationDefinitionId);

Optional<AuthSpecification> authSpec = OauthModelConverter.getAuthSpec(spec);
if (authSpec.isPresent()) {
specRead.setAuthSpecification(authSpec.get());
}

return specRead;
}

public SynchronousResponse<ConnectorSpecification> getConnectorSpecification(String dockerImage) throws IOException {
Expand Down Expand Up @@ -352,7 +369,7 @@ public JobInfoRead cancelJob(JobIdRequestBody jobIdRequestBody) throws IOExcepti

private void cancelTemporalWorkflowIfPresent(long jobId) throws IOException {
var latestAttemptId = jobPersistence.getJob(jobId).getAttempts().size() - 1; // attempts ids are monotonically increasing starting from 0 and
// specific to a job id, allowing us to do this.
// specific to a job id, allowing us to do this.
var workflowId = jobPersistence.getAttemptTemporalWorkflowId(jobId, latestAttemptId);

if (workflowId.isPresent()) {
Expand Down
33 changes: 33 additions & 0 deletions docs/reference/api/generated-api-html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2296,6 +2296,12 @@ <h3 class="field-label">Example data</h3>
"supportedDestinationSyncModes" : [ null, null ],
"supportsDbt" : true,
"destinationDefinitionId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91",
"authSpecification" : {
"auth_type" : "oauth2.0",
"oauth2Specification" : {
"oauthFlowInitParameters" : [ [ "oauthFlowInitParameters", "oauthFlowInitParameters" ], [ "oauthFlowInitParameters", "oauthFlowInitParameters" ] ]
}
},
"jobInfo" : {
"createdAt" : 0,
"configId" : "configId",
Expand Down Expand Up @@ -4641,6 +4647,12 @@ <h3 class="field-label">Example data</h3>
}
},
"sourceDefinitionId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91",
"authSpecification" : {
"auth_type" : "oauth2.0",
"oauth2Specification" : {
"oauthFlowInitParameters" : [ [ "oauthFlowInitParameters", "oauthFlowInitParameters" ], [ "oauthFlowInitParameters", "oauthFlowInitParameters" ] ]
}
},
"jobInfo" : {
"createdAt" : 0,
"configId" : "configId",
Expand Down Expand Up @@ -6004,6 +6016,7 @@ <h3>Table of Contents</h3>
<li><a href="#AttemptInfoRead"><code>AttemptInfoRead</code> - </a></li>
<li><a href="#AttemptRead"><code>AttemptRead</code> - </a></li>
<li><a href="#AttemptStatus"><code>AttemptStatus</code> - </a></li>
<li><a href="#AuthSpecification"><code>AuthSpecification</code> - </a></li>
<li><a href="#CheckConnectionRead"><code>CheckConnectionRead</code> - </a></li>
<li><a href="#CheckOperationRead"><code>CheckOperationRead</code> - </a></li>
<li><a href="#CompleteDestinationOAuthRequest"><code>CompleteDestinationOAuthRequest</code> - </a></li>
Expand Down Expand Up @@ -6058,6 +6071,7 @@ <h3>Table of Contents</h3>
<li><a href="#Notification"><code>Notification</code> - </a></li>
<li><a href="#NotificationRead"><code>NotificationRead</code> - </a></li>
<li><a href="#NotificationType"><code>NotificationType</code> - </a></li>
<li><a href="#OAuth2Specification"><code>OAuth2Specification</code> - </a></li>
<li><a href="#OAuthConsentRead"><code>OAuthConsentRead</code> - </a></li>
<li><a href="#OperationCreate"><code>OperationCreate</code> - </a></li>
<li><a href="#OperationIdRequestBody"><code>OperationIdRequestBody</code> - </a></li>
Expand Down Expand Up @@ -6171,6 +6185,16 @@ <h3><a name="AttemptStatus"><code>AttemptStatus</code> - </a> <a class="up" href
<div class="field-items">
</div> <!-- field-items -->
</div>
<div class="model">
<h3><a name="AuthSpecification"><code>AuthSpecification</code> - </a> <a class="up" href="#__Models">Up</a></h3>
<div class='model-description'></div>
<div class="field-items">
<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> <!-- field-items -->
</div>
<div class="model">
<h3><a name="CheckConnectionRead"><code>CheckConnectionRead</code> - </a> <a class="up" href="#__Models">Up</a></h3>
<div class='model-description'></div>
Expand Down Expand Up @@ -6410,6 +6434,7 @@ <h3><a name="DestinationDefinitionSpecificationRead"><code>DestinationDefinition
<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">documentationUrl (optional)</div><div class="param-desc"><span class="param-type"><a href="#string">String</a></span> </div>
<div class="param">connectionSpecification (optional)</div><div class="param-desc"><span class="param-type"><a href="#DestinationDefinitionSpecification">DestinationDefinitionSpecification</a></span> </div>
<div class="param">authSpecification (optional)</div><div class="param-desc"><span class="param-type"><a href="#AuthSpecification">AuthSpecification</a></span> </div>
<div class="param">jobInfo </div><div class="param-desc"><span class="param-type"><a href="#SynchronousJobRead">SynchronousJobRead</a></span> </div>
<div class="param">supportedDestinationSyncModes (optional)</div><div class="param-desc"><span class="param-type"><a href="#DestinationSyncMode">array[DestinationSyncMode]</a></span> </div>
<div class="param">supportsDbt (optional)</div><div class="param-desc"><span class="param-type"><a href="#boolean">Boolean</a></span> </div>
Expand Down Expand Up @@ -6656,6 +6681,13 @@ <h3><a name="NotificationType"><code>NotificationType</code> - </a> <a class="up
<div class="field-items">
</div> <!-- field-items -->
</div>
<div class="model">
<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> <!-- field-items -->
</div>
<div class="model">
<h3><a name="OAuthConsentRead"><code>OAuthConsentRead</code> - </a> <a class="up" href="#__Models">Up</a></h3>
<div class='model-description'></div>
Expand Down Expand Up @@ -6849,6 +6881,7 @@ <h3><a name="SourceDefinitionSpecificationRead"><code>SourceDefinitionSpecificat
<div class="param">sourceDefinitionId </div><div class="param-desc"><span class="param-type"><a href="#UUID">UUID</a></span> format: uuid</div>
<div class="param">documentationUrl (optional)</div><div class="param-desc"><span class="param-type"><a href="#string">String</a></span> </div>
<div class="param">connectionSpecification (optional)</div><div class="param-desc"><span class="param-type"><a href="#SourceDefinitionSpecification">SourceDefinitionSpecification</a></span> </div>
<div class="param">authSpecification (optional)</div><div class="param-desc"><span class="param-type"><a href="#AuthSpecification">AuthSpecification</a></span> </div>
<div class="param">jobInfo </div><div class="param-desc"><span class="param-type"><a href="#SynchronousJobRead">SynchronousJobRead</a></span> </div>
</div> <!-- field-items -->
</div>
Expand Down