Skip to content

Commit

Permalink
馃帀 API: Add an endpoint to list workspaces (#4530)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmolimar committed Jul 5, 2021
1 parent fc71ab0 commit 5c7f886
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 1 deletion.
22 changes: 22 additions & 0 deletions airbyte-api/src/main/openapi/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ paths:
$ref: "#/components/responses/NotFoundResponse"
"422":
$ref: "#/components/responses/InvalidInputResponse"
/v1/workspaces/list:
post:
tags:
- workspace
summary: List all workspaces registered in the current Airbyte deployment
operationId: listWorkspaces
responses:
"200":
description: Successful operation
content:
application/json:
schema:
$ref: "#/components/schemas/WorkspaceReadList"
/v1/workspaces/get:
post:
tags:
Expand Down Expand Up @@ -1480,6 +1493,15 @@ components:
properties:
workspaceId:
$ref: "#/components/schemas/WorkspaceId"
WorkspaceReadList:
type: object
required:
- workspaces
properties:
workspaces:
type: array
items:
$ref: "#/components/schemas/WorkspaceRead"
WorkspaceRead:
type: object
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import io.airbyte.api.model.WorkspaceCreate;
import io.airbyte.api.model.WorkspaceIdRequestBody;
import io.airbyte.api.model.WorkspaceRead;
import io.airbyte.api.model.WorkspaceReadList;
import io.airbyte.api.model.WorkspaceUpdate;
import io.airbyte.commons.io.FileTtlManager;
import io.airbyte.config.Configs;
Expand Down Expand Up @@ -187,6 +188,11 @@ public ConfigurationApi(final ConfigRepository configRepository,

// WORKSPACE

@Override
public WorkspaceReadList listWorkspaces() {
return execute(workspacesHandler::listWorkspaces);
}

@Override
public WorkspaceRead createWorkspace(@Valid WorkspaceCreate workspaceCreate) {
return execute(() -> workspacesHandler.createWorkspace(workspaceCreate));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import io.airbyte.api.model.WorkspaceCreate;
import io.airbyte.api.model.WorkspaceIdRequestBody;
import io.airbyte.api.model.WorkspaceRead;
import io.airbyte.api.model.WorkspaceReadList;
import io.airbyte.api.model.WorkspaceUpdate;
import io.airbyte.config.StandardWorkspace;
import io.airbyte.config.persistence.ConfigNotFoundException;
Expand All @@ -47,8 +48,10 @@
import io.airbyte.server.errors.ValueConflictKnownException;
import io.airbyte.validation.json.JsonValidationException;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
import java.util.function.Supplier;
import java.util.stream.Collectors;

public class WorkspacesHandler {

Expand Down Expand Up @@ -141,6 +144,13 @@ public void deleteWorkspace(final WorkspaceIdRequestBody workspaceIdRequestBody)
configRepository.writeStandardWorkspace(persistedWorkspace);
}

public WorkspaceReadList listWorkspaces() throws JsonValidationException, IOException {
final List<WorkspaceRead> reads = configRepository.listStandardWorkspaces(false).stream()
.map(WorkspacesHandler::buildWorkspaceRead)
.collect(Collectors.toList());
return new WorkspaceReadList().workspaces(reads);
}

public WorkspaceRead getWorkspace(WorkspaceIdRequestBody workspaceIdRequestBody)
throws JsonValidationException, IOException, ConfigNotFoundException {
final UUID workspaceId = workspaceIdRequestBody.getWorkspaceId();
Expand Down Expand Up @@ -201,7 +211,7 @@ private WorkspaceRead buildWorkspaceReadFromId(UUID workspaceId) throws ConfigNo
return buildWorkspaceRead(workspace);
}

private WorkspaceRead buildWorkspaceRead(StandardWorkspace workspace) {
private static WorkspaceRead buildWorkspaceRead(StandardWorkspace workspace) {
return new WorkspaceRead()
.workspaceId(workspace.getWorkspaceId())
.customerId(workspace.getCustomerId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import com.google.common.collect.Lists;
import io.airbyte.api.model.ConnectionRead;
import io.airbyte.api.model.ConnectionReadList;
import io.airbyte.api.model.DestinationRead;
Expand All @@ -39,6 +40,7 @@
import io.airbyte.api.model.WorkspaceCreate;
import io.airbyte.api.model.WorkspaceIdRequestBody;
import io.airbyte.api.model.WorkspaceRead;
import io.airbyte.api.model.WorkspaceReadList;
import io.airbyte.api.model.WorkspaceUpdate;
import io.airbyte.config.Notification;
import io.airbyte.config.Notification.NotificationType;
Expand Down Expand Up @@ -177,6 +179,45 @@ void testDeleteWorkspace() throws JsonValidationException, ConfigNotFoundExcepti
verify(sourceHandler).deleteSource(source);
}

@Test
void testListWorkspaces() throws JsonValidationException, IOException {
final StandardWorkspace workspace2 = generateWorkspace();

when(configRepository.listStandardWorkspaces(false))
.thenReturn(Lists.newArrayList(workspace, workspace2));

WorkspaceRead expectedWorkspaceRead1 = new WorkspaceRead()
.workspaceId(workspace.getWorkspaceId())
.customerId(workspace.getCustomerId())
.email(workspace.getEmail())
.name(workspace.getName())
.slug(workspace.getSlug())
.initialSetupComplete(workspace.getInitialSetupComplete())
.displaySetupWizard(workspace.getDisplaySetupWizard())
.news(workspace.getNews())
.anonymousDataCollection(workspace.getAnonymousDataCollection())
.securityUpdates(workspace.getSecurityUpdates())
.notifications(List.of(generateApiNotification()));

WorkspaceRead expectedWorkspaceRead2 = new WorkspaceRead()
.workspaceId(workspace2.getWorkspaceId())
.customerId(workspace2.getCustomerId())
.email(workspace2.getEmail())
.name(workspace2.getName())
.slug(workspace2.getSlug())
.initialSetupComplete(workspace2.getInitialSetupComplete())
.displaySetupWizard(workspace2.getDisplaySetupWizard())
.news(workspace2.getNews())
.anonymousDataCollection(workspace2.getAnonymousDataCollection())
.securityUpdates(workspace2.getSecurityUpdates())
.notifications(List.of(generateApiNotification()));

final WorkspaceReadList actualWorkspaceReadList = workspacesHandler.listWorkspaces();

assertEquals(Lists.newArrayList(expectedWorkspaceRead1, expectedWorkspaceRead2),
actualWorkspaceReadList.getWorkspaces());
}

@Test
void testGetWorkspace() throws JsonValidationException, ConfigNotFoundException, IOException {
when(configRepository.getStandardWorkspace(workspace.getWorkspaceId(), false))
Expand Down
89 changes: 89 additions & 0 deletions docs/reference/api/generated-api-html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ <h4><a href="#Workspace">Workspace</a></h4>
<li><a href="#deleteWorkspace"><code><span class="http-method">post</span> /v1/workspaces/delete</code></a></li>
<li><a href="#getWorkspace"><code><span class="http-method">post</span> /v1/workspaces/get</code></a></li>
<li><a href="#getWorkspaceBySlug"><code><span class="http-method">post</span> /v1/workspaces/get_by_slug</code></a></li>
<li><a href="#listWorkspaces"><code><span class="http-method">post</span> /v1/workspaces/list</code></a></li>
<li><a href="#updateWorkspace"><code><span class="http-method">post</span> /v1/workspaces/update</code></a></li>
</ul>

Expand Down Expand Up @@ -5156,6 +5157,86 @@ <h4 class="field-label">422</h4>
<a href="#InvalidInputExceptionInfo">InvalidInputExceptionInfo</a>
</div> <!-- method -->
<hr/>
<div class="method"><a name="listWorkspaces"/>
<div class="method-path">
<a class="up" href="#__Methods">Up</a>
<pre class="post"><code class="huge"><span class="http-method">post</span> /v1/workspaces/list</code></pre></div>
<div class="method-summary">List all workspaces registered in the current Airbyte deployment (<span class="nickname">listWorkspaces</span>)</div>
<div class="method-notes"></div>







<h3 class="field-label">Return type</h3>
<div class="return-type">
<a href="#WorkspaceReadList">WorkspaceReadList</a>

</div>

<!--Todo: process Response Object and its headers, schema, examples -->

<h3 class="field-label">Example data</h3>
<div class="example-data-content-type">Content-Type: application/json</div>
<pre class="example"><code>{
"workspaces" : [ {
"displaySetupWizard" : true,
"news" : true,
"initialSetupComplete" : true,
"anonymousDataCollection" : true,
"customerId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91",
"name" : "name",
"email" : "email",
"slug" : "slug",
"securityUpdates" : true,
"notifications" : [ {
"slackConfiguration" : {
"webhook" : "webhook"
}
}, {
"slackConfiguration" : {
"webhook" : "webhook"
}
} ],
"workspaceId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91"
}, {
"displaySetupWizard" : true,
"news" : true,
"initialSetupComplete" : true,
"anonymousDataCollection" : true,
"customerId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91",
"name" : "name",
"email" : "email",
"slug" : "slug",
"securityUpdates" : true,
"notifications" : [ {
"slackConfiguration" : {
"webhook" : "webhook"
}
}, {
"slackConfiguration" : {
"webhook" : "webhook"
}
} ],
"workspaceId" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91"
} ]
}</code></pre>

<h3 class="field-label">Produces</h3>
This API call produces the following media types according to the <span class="header">Accept</span> request header;
the media type will be conveyed by the <span class="header">Content-Type</span> response header.
<ul>
<li><code>application/json</code></li>
</ul>

<h3 class="field-label">Responses</h3>
<h4 class="field-label">200</h4>
Successful operation
<a href="#WorkspaceReadList">WorkspaceReadList</a>
</div> <!-- method -->
<hr/>
<div class="method"><a name="updateWorkspace"/>
<div class="method-path">
<a class="up" href="#__Methods">Up</a>
Expand Down Expand Up @@ -5332,6 +5413,7 @@ <h3>Table of Contents</h3>
<li><a href="#WorkspaceCreate"><code>WorkspaceCreate</code> - </a></li>
<li><a href="#WorkspaceIdRequestBody"><code>WorkspaceIdRequestBody</code> - </a></li>
<li><a href="#WorkspaceRead"><code>WorkspaceRead</code> - </a></li>
<li><a href="#WorkspaceReadList"><code>WorkspaceReadList</code> - </a></li>
<li><a href="#WorkspaceUpdate"><code>WorkspaceUpdate</code> - </a></li>
</ol>

Expand Down Expand Up @@ -6211,6 +6293,13 @@ <h3><a name="WorkspaceRead"><code>WorkspaceRead</code> - </a> <a class="up" href
<div class="param">notifications (optional)</div><div class="param-desc"><span class="param-type"><a href="#Notification">array[Notification]</a></span> </div>
</div> <!-- field-items -->
</div>
<div class="model">
<h3><a name="WorkspaceReadList"><code>WorkspaceReadList</code> - </a> <a class="up" href="#__Models">Up</a></h3>
<div class='model-description'></div>
<div class="field-items">
<div class="param">workspaces </div><div class="param-desc"><span class="param-type"><a href="#WorkspaceRead">array[WorkspaceRead]</a></span> </div>
</div> <!-- field-items -->
</div>
<div class="model">
<h3><a name="WorkspaceUpdate"><code>WorkspaceUpdate</code> - </a> <a class="up" href="#__Models">Up</a></h3>
<div class='model-description'></div>
Expand Down

0 comments on commit 5c7f886

Please sign in to comment.