Skip to content

Commit

Permalink
fix(openapi): Rewrite Swagger to OpenAPI annotations (#6309) (#6330)
Browse files Browse the repository at this point in the history
* fix(openapi): Rewrite Swagger to OpenAPI annotations

* Update gradle.properties

(cherry picked from commit 0cc36f8)

Co-authored-by: Christos Arvanitis <christos.arvanitis@armory.io>
  • Loading branch information
mergify[bot] and christosarvanitis authored Jan 6, 2025
1 parent 7daeb3b commit ec28083
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
1 change: 1 addition & 0 deletions clouddriver-kubernetes/clouddriver-kubernetes.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ dependencies {
implementation "org.springframework.cloud:spring-cloud-config-server"
implementation "io.github.resilience4j:resilience4j-retry"
implementation "io.github.resilience4j:resilience4j-micrometer"
implementation "io.swagger.core.v3:swagger-annotations"

testImplementation "io.spinnaker.kork:kork-test"
testImplementation "org.apache.commons:commons-exec"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package com.netflix.spinnaker.clouddriver.kubernetes.controllers;

import com.netflix.spinnaker.clouddriver.kubernetes.provider.view.KubernetesJobProvider;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import java.util.Collections;
import java.util.Map;
import org.springframework.security.access.prepost.PreAuthorize;
Expand All @@ -38,18 +38,25 @@ public PodController(KubernetesJobProvider jobProvider) {

@PreAuthorize(
"hasPermission(#application, 'APPLICATION', 'READ') and hasPermission(#account, 'ACCOUNT', 'READ')")
@ApiOperation(value = "Collect a file from a pod", notes = "Collects the file result of a pod.")
@Operation(
summary = "Collect a file from a pod",
description = "Collects the file result of a pod.")
@RequestMapping(
value = "/{account}/{namespace}/{podName}/{fileName:.+}",
method = RequestMethod.GET)
Map<String, Object> getFileContents(
@ApiParam(value = "Application name", required = true) @PathVariable String application,
@ApiParam(value = "Account job was created by", required = true) @PathVariable String account,
@ApiParam(value = "Namespace in which the pod is running in", required = true) @PathVariable
@Parameter(description = "Application name", required = true) @PathVariable
String application,
@Parameter(description = "Account job was created by", required = true) @PathVariable
String account,
@Parameter(description = "Namespace in which the pod is running in", required = true)
@PathVariable
String namespace,
@ApiParam(value = "Unique identifier of pod being looked up", required = true) @PathVariable
@Parameter(description = "Unique identifier of pod being looked up", required = true)
@PathVariable
String podName,
@ApiParam(value = "File name to look up", required = true) @PathVariable String fileName) {
@Parameter(description = "File name to look up", required = true) @PathVariable
String fileName) {
Map<String, Object> results =
kubernetesJobProvider.getFileContentsFromPod(account, namespace, podName, fileName);

Expand Down
2 changes: 1 addition & 1 deletion clouddriver-web/clouddriver-web.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
implementation "io.spinnaker.kork:kork-moniker"
implementation "commons-io:commons-io"
implementation "io.reactivex:rxjava"
implementation "io.swagger:swagger-annotations"
implementation "io.swagger.core.v3:swagger-annotations"
implementation "org.apache.groovy:groovy"
implementation "org.slf4j:slf4j-api"
implementation "org.springframework.boot:spring-boot-starter-actuator"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package com.netflix.spinnaker.clouddriver.controllers
import com.netflix.spinnaker.clouddriver.model.JobProvider
import com.netflix.spinnaker.clouddriver.model.JobStatus
import com.netflix.spinnaker.kork.web.exceptions.NotFoundException
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiParam
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.MessageSource
import org.springframework.security.access.prepost.PreAuthorize
Expand All @@ -42,12 +42,12 @@ class JobController {
MessageSource messageSource

@PreAuthorize("hasPermission(#application, 'APPLICATION', 'READ') and hasPermission(#account, 'ACCOUNT', 'READ')")
@ApiOperation(value = "Collect a JobStatus", notes = "Collects the output of the job.")
@Operation(summary = "Collect a JobStatus", description = "Collects the output of the job.")
@RequestMapping(value = "/{account}/{location}/{id:.+}", method = RequestMethod.GET)
JobStatus collectJob(@ApiParam(value = "Application name", required = true) @PathVariable String application,
@ApiParam(value = "Account job was created by", required = true) @PathVariable String account,
@ApiParam(value = "Namespace, region, or zone job is running in", required = true) @PathVariable String location,
@ApiParam(value = "Unique identifier of job being looked up", required = true) @PathVariable String id) {
JobStatus collectJob(@Parameter(description = "Application name", required = true) @PathVariable String application,
@Parameter(description = "Account job was created by", required = true) @PathVariable String account,
@Parameter(description = "Namespace, region, or zone job is running in", required = true) @PathVariable String location,
@Parameter(description = "Unique identifier of job being looked up", required = true) @PathVariable String id) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
Collection<JobStatus> jobMatches = jobProviders.findResults {
return it.collectJob(account, location, id)
Expand All @@ -59,26 +59,26 @@ class JobController {
}

@PreAuthorize("hasPermission(#application, 'APPLICATION', 'EXECUTE') and hasPermission(#account, 'ACCOUNT', 'WRITE')")
@ApiOperation(value = "Cancel a Job", notes = "Cancels the job.")
@Operation(summary = "Cancel a Job", description = "Cancels the job.")
@RequestMapping(value = "/{account}/{location}/{id:.+}", method = RequestMethod.DELETE)
void cancelJob(@ApiParam(value = "Application name", required = true) @PathVariable String application,
@ApiParam(value = "Account job is running in", required = true) @PathVariable String account,
@ApiParam(value = "Namespace, region, or zone job is running in", required = true) @PathVariable String location,
@ApiParam(value = "Unique identifier of job to be canceled", required = true) @PathVariable String id) {
void cancelJob(@Parameter(description = "Application name", required = true) @PathVariable String application,
@Parameter(description = "Account job is running in", required = true) @PathVariable String account,
@Parameter(description = "Namespace, region, or zone job is running in", required = true) @PathVariable String location,
@Parameter(description = "Unique identifier of job to be canceled", required = true) @PathVariable String id) {
jobProviders.forEach {
it.cancelJob(account, location, id)
}
}

@PreAuthorize("hasPermission(#application, 'APPLICATION', 'READ') and hasPermission(#account, 'ACCOUNT', 'READ')")
@ApiOperation(value = "Collect a file from a job", notes = "Collects the file result of a job.")
@Operation(summary = "Collect a file from a job", description = "Collects the file result of a job.")
@RequestMapping(value = "/{account}/{location}/{id}/{fileName:.+}", method = RequestMethod.GET)
Map<String, Object> getFileContents(
@ApiParam(value = "Application name", required = true) @PathVariable String application,
@ApiParam(value = "Account job was created by", required = true) @PathVariable String account,
@ApiParam(value = "Namespace, region, or zone job is running in", required = true) @PathVariable String location,
@ApiParam(value = "Unique identifier of job being looked up", required = true) @PathVariable String id,
@ApiParam(value = "File name to look up", required = true) @PathVariable String fileName
@Parameter(description = "Application name", required = true) @PathVariable String application,
@Parameter(description = "Account job was created by", required = true) @PathVariable String account,
@Parameter(description = "Namespace, region, or zone job is running in", required = true) @PathVariable String location,
@Parameter(description = "Unique identifier of job being looked up", required = true) @PathVariable String id,
@Parameter(description = "File name to look up", required = true) @PathVariable String fileName
) {
Collection<Map<String, Object>> results = jobProviders.findResults {
it.getFileContents(account, location, id, fileName)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
korkVersion=7.245.0
korkVersion=7.247.0
fiatVersion=1.51.0
org.gradle.parallel=true
spinnakerGradleVersion=8.32.1
Expand Down

0 comments on commit ec28083

Please sign in to comment.