Skip to content

Commit

Permalink
refactor(controller): unify sign link api for dataset and evaluation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
anda-ren authored Oct 23, 2023
1 parent 71c3fa6 commit b044ccc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,16 @@ void pullUriContent(
}
}

/**
* legacy sign links api, use {@link FileStorageController} instead
*/
@Operation(summary = "Sign SWDS uris to get a batch of temporarily accessible links",
description = "Sign SWDS uris to get a batch of temporarily accessible links")
@PostMapping(
value = "/project/{projectName}/dataset/{datasetName}/uri/sign-links",
produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAnyRole('OWNER', 'MAINTAINER', 'GUEST')")
@Deprecated(since = "0.6.2")
ResponseEntity<ResponseMessage<Map>> signLinks(
@PathVariable String projectName,
@PathVariable String datasetName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,17 @@ void getHashedBlob(
}


/**
* legacy sign links api, use {@link FileStorageController} instead
*/
@Operation(summary = "Sign uris to get a batch of temporarily accessible links",
description = "Sign uris to get a batch of temporarily accessible links")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "ok")})
@PostMapping(
value = "/project/{projectUrl}/evaluation/{version}/uri/sign-links",
produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAnyRole('OWNER', 'MAINTAINER', 'GUEST')")
@Deprecated(since = "0.6.2")
ResponseEntity<ResponseMessage<Map<String, String>>> signLinks(
@PathVariable(name = "projectUrl") String projectUrl,
@PathVariable(name = "version") String version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,22 @@
import ai.starwhale.mlops.exception.SwProcessException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -105,4 +112,27 @@ void pullUriContent(
throw new SwProcessException(SwProcessException.ErrorType.NETWORK, "error write data to response", e);
}
}

@Operation(summary = "Sign uris to get a batch of temporarily accessible links",
description = "Sign uris to get a batch of temporarily accessible links")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "ok")})
@PostMapping(
value = "/filestorage/sign-links",
produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<ResponseMessage<Map<String, String>>> signLinks(
@RequestBody Set<String> uris,
@Parameter(name = "expTimeMillis", description = "the link will be expired after expTimeMillis")
@RequestParam(name = "expTimeMillis")
Long expTimeMillis
) {
return ResponseEntity.ok(
Code.success.asResponse(
uris.stream().collect(Collectors.toMap(
u -> u,
u -> uriAccessor.linkOf(
u,
expTimeMillis
)
))));
}
}

0 comments on commit b044ccc

Please sign in to comment.