Skip to content

Commit

Permalink
Update public API health check & add organization ID to workspace con…
Browse files Browse the repository at this point in the history
…troller (#12427)
  • Loading branch information
JonsSpaghetti committed May 10, 2024
1 parent 7b3c978 commit 3786cfc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions airbyte-api/src/main/openapi/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12091,6 +12091,10 @@ components:
name:
description: Name of the workspace
type: string
organizationId:
description: ID of organization to add workspace to.
format: uuid
type: string
x-sdk-entity: Workspace
x-sdk-param-suppress-computed-diff: true
x-sdk-component: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

package io.airbyte.server.apis.publicapi.controllers

import io.airbyte.commons.server.errors.problems.UnexpectedProblem
import io.airbyte.commons.server.handlers.HealthCheckHandler
import io.airbyte.commons.server.scheduling.AirbyteTaskExecutors
import io.micronaut.http.HttpResponse
import io.micronaut.http.HttpStatus
import io.micronaut.http.annotation.Controller
import io.micronaut.scheduling.annotation.ExecuteOn
import io.micronaut.security.annotation.Secured
Expand All @@ -17,9 +20,9 @@ import jakarta.ws.rs.GET
/**
* Health endpoint used by kubernetes and the gcp load balancer.
*/
@Controller("/public/api/v1/health")
@Controller("/api/public/v1/health")
@Secured(SecurityRule.IS_ANONYMOUS)
class HealthController {
class HealthController(private val healthCheckHandler: HealthCheckHandler) {
@GET
@ApiResponses(
value = [
Expand All @@ -32,6 +35,9 @@ class HealthController {
)
@ExecuteOn(AirbyteTaskExecutors.HEALTH)
fun healthCheck(): HttpResponse<String> {
return HttpResponse.ok<String?>().body("Successful operation")
if (healthCheckHandler.health().available) {
return HttpResponse.ok<String?>().body("Successful operation")
}
throw UnexpectedProblem(HttpStatus.SERVICE_UNAVAILABLE)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ val logger = KotlinLogging.logger {}
@Secured(SecurityRule.IS_AUTHENTICATED)
open class WorkspacesController(
protected val workspaceService: WorkspaceService,
private val apiAuthorizationHelper: ApiAuthorizationHelper,
protected val apiAuthorizationHelper: ApiAuthorizationHelper,
private val currentUserService: CurrentUserService,
) : PublicWorkspacesApi {
@Path("/{workspaceId}/oauthCredentials")
Expand All @@ -56,14 +56,14 @@ open class WorkspacesController(
}

@ExecuteOn(AirbyteTaskExecutors.PUBLIC_API)
override fun publicCreateWorkspace(workspaceCreateRequest: WorkspaceCreateRequest?): Response {
override fun publicCreateWorkspace(workspaceCreateRequest: WorkspaceCreateRequest): Response {
// Now that we have orgs everywhere, ensure the user is at least an organization editor
apiAuthorizationHelper.ensureUserHasAnyRequiredRoleOrThrow(
Scope.ORGANIZATION,
listOf(DEFAULT_ORGANIZATION_ID.toString()),
setOf(OrganizationAuthRole.ORGANIZATION_EDITOR),
)
return workspaceService.controllerCreateWorkspace(workspaceCreateRequest!!)
return workspaceService.controllerCreateWorkspace(workspaceCreateRequest)
}

@Path("/{workspaceId}")
Expand Down

0 comments on commit 3786cfc

Please sign in to comment.