Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(controller): unify sign link api for dataset and evaluation #2887

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
)
))));
}
}
Loading