From 1d809a753995e4b866b1eeb954c80678085b80de Mon Sep 17 00:00:00 2001 From: Anne <102554163+alovew@users.noreply.github.com> Date: Fri, 4 Nov 2022 14:20:07 -0700 Subject: [PATCH] Add new workspace api endpoint (#18983) * Add new workspace api endpoint --- airbyte-api/src/main/openapi/config.yaml | 23 +++++ .../airbyte/server/apis/ConfigurationApi.java | 5 + .../server/handlers/WorkspacesHandler.java | 6 ++ .../handlers/WorkspacesHandlerTest.java | 23 +++++ .../api/generated-api-html/index.html | 92 +++++++++++++++++++ 5 files changed, 149 insertions(+) diff --git a/airbyte-api/src/main/openapi/config.yaml b/airbyte-api/src/main/openapi/config.yaml index a30a31c0796f6..e9691ae1b4e01 100644 --- a/airbyte-api/src/main/openapi/config.yaml +++ b/airbyte-api/src/main/openapi/config.yaml @@ -168,6 +168,29 @@ paths: $ref: "#/components/responses/NotFoundResponse" "422": $ref: "#/components/responses/InvalidInputResponse" + /v1/workspaces/get_by_connection_id: + post: + tags: + - workspace + summary: Find workspace by connection id + operationId: getWorkspaceByConnectionId + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/ConnectionIdRequestBody" + required: true + responses: + "200": + description: Successful operation + content: + application/json: + schema: + $ref: "#/components/schemas/WorkspaceRead" + "404": + $ref: "#/components/responses/NotFoundResponse" + "422": + $ref: "#/components/responses/InvalidInputResponse" /v1/workspaces/update: post: tags: diff --git a/airbyte-server/src/main/java/io/airbyte/server/apis/ConfigurationApi.java b/airbyte-server/src/main/java/io/airbyte/server/apis/ConfigurationApi.java index 87cf9448cd999..872b1735dbdf9 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/apis/ConfigurationApi.java +++ b/airbyte-server/src/main/java/io/airbyte/server/apis/ConfigurationApi.java @@ -253,6 +253,11 @@ public WorkspaceRead getWorkspaceBySlug(final SlugRequestBody slugRequestBody) { return execute(() -> workspacesHandler.getWorkspaceBySlug(slugRequestBody)); } + @Override + public WorkspaceRead getWorkspaceByConnectionId(final ConnectionIdRequestBody connectionIdRequestBody) { + return execute(() -> workspacesHandler.getWorkspaceByConnectionId(connectionIdRequestBody)); + } + @Override public WorkspaceRead updateWorkspace(final WorkspaceUpdate workspaceUpdate) { return execute(() -> workspacesHandler.updateWorkspace(workspaceUpdate)); diff --git a/airbyte-server/src/main/java/io/airbyte/server/handlers/WorkspacesHandler.java b/airbyte-server/src/main/java/io/airbyte/server/handlers/WorkspacesHandler.java index f6658c94be209..05b37a8341e8c 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/handlers/WorkspacesHandler.java +++ b/airbyte-server/src/main/java/io/airbyte/server/handlers/WorkspacesHandler.java @@ -9,6 +9,7 @@ import com.google.common.base.Preconditions; import com.google.common.base.Strings; import io.airbyte.analytics.TrackingClientSingleton; +import io.airbyte.api.model.generated.ConnectionIdRequestBody; import io.airbyte.api.model.generated.ConnectionRead; import io.airbyte.api.model.generated.DestinationRead; import io.airbyte.api.model.generated.Geography; @@ -163,6 +164,11 @@ public WorkspaceRead getWorkspaceBySlug(final SlugRequestBody slugRequestBody) return buildWorkspaceRead(workspace); } + public WorkspaceRead getWorkspaceByConnectionId(final ConnectionIdRequestBody connectionIdRequestBody) { + final StandardWorkspace workspace = configRepository.getStandardWorkspaceFromConnection(connectionIdRequestBody.getConnectionId(), false); + return buildWorkspaceRead(workspace); + } + public WorkspaceRead updateWorkspace(final WorkspaceUpdate workspacePatch) throws ConfigNotFoundException, IOException, JsonValidationException { final UUID workspaceId = workspacePatch.getWorkspaceId(); diff --git a/airbyte-server/src/test/java/io/airbyte/server/handlers/WorkspacesHandlerTest.java b/airbyte-server/src/test/java/io/airbyte/server/handlers/WorkspacesHandlerTest.java index b9f64d12c2c75..466671991f584 100644 --- a/airbyte-server/src/test/java/io/airbyte/server/handlers/WorkspacesHandlerTest.java +++ b/airbyte-server/src/test/java/io/airbyte/server/handlers/WorkspacesHandlerTest.java @@ -16,6 +16,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.google.common.collect.Lists; +import io.airbyte.api.model.generated.ConnectionIdRequestBody; import io.airbyte.api.model.generated.ConnectionRead; import io.airbyte.api.model.generated.ConnectionReadList; import io.airbyte.api.model.generated.DestinationRead; @@ -333,6 +334,28 @@ void testGetWorkspaceBySlug() throws JsonValidationException, ConfigNotFoundExce assertEquals(workspaceRead, workspacesHandler.getWorkspaceBySlug(slugRequestBody)); } + @Test + void testGetWorkspaceByConnectionId() { + final UUID connectionId = UUID.randomUUID(); + when(configRepository.getStandardWorkspaceFromConnection(connectionId, false)).thenReturn(workspace); + final ConnectionIdRequestBody connectionIdRequestBody = new ConnectionIdRequestBody().connectionId(connectionId); + final WorkspaceRead workspaceRead = new WorkspaceRead() + .workspaceId(workspace.getWorkspaceId()) + .customerId(workspace.getCustomerId()) + .email(TEST_EMAIL) + .name(workspace.getName()) + .slug(workspace.getSlug()) + .initialSetupComplete(workspace.getInitialSetupComplete()) + .displaySetupWizard(workspace.getDisplaySetupWizard()) + .news(workspace.getNews()) + .anonymousDataCollection(workspace.getAnonymousDataCollection()) + .securityUpdates(workspace.getSecurityUpdates()) + .notifications(NotificationConverter.toApiList(workspace.getNotifications())) + .defaultGeography(GEOGRAPHY_AUTO); + + assertEquals(workspaceRead, workspacesHandler.getWorkspaceByConnectionId(connectionIdRequestBody)); + } + @Test void testUpdateWorkspace() throws JsonValidationException, ConfigNotFoundException, IOException { final io.airbyte.api.model.generated.Notification apiNotification = generateApiNotification(); diff --git a/docs/reference/api/generated-api-html/index.html b/docs/reference/api/generated-api-html/index.html index 14e34fd42968e..aa977cc558121 100644 --- a/docs/reference/api/generated-api-html/index.html +++ b/docs/reference/api/generated-api-html/index.html @@ -387,6 +387,7 @@
post /v1/workspaces/create
post /v1/workspaces/delete
post /v1/workspaces/get
post /v1/workspaces/get_by_connection_id
post /v1/workspaces/get_by_slug
post /v1/workspaces/list
post /v1/workspaces/update
{
+ "news" : true,
+ "webhookConfigs" : [ {
+ "name" : "name",
+ "id" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91"
+ }, {
+ "name" : "name",
+ "id" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91"
+ } ],
+ "displaySetupWizard" : true,
+ "initialSetupComplete" : true,
+ "anonymousDataCollection" : true,
+ "customerId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91",
+ "name" : "name",
+ "firstCompletedSync" : true,
+ "feedbackDone" : true,
+ "email" : "email",
+ "slug" : "slug",
+ "securityUpdates" : true,
+ "notifications" : [ {
+ "slackConfiguration" : {
+ "webhook" : "webhook"
+ },
+ "sendOnSuccess" : false,
+ "sendOnFailure" : true,
+ "customerioConfiguration" : "{}"
+ }, {
+ "slackConfiguration" : {
+ "webhook" : "webhook"
+ },
+ "sendOnSuccess" : false,
+ "sendOnFailure" : true,
+ "customerioConfiguration" : "{}"
+ } ],
+ "workspaceId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91"
+}
+
+ application/json
post /v1/workspaces/get_by_connection_id
application/json