X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/d6e1bfee59569d79f0f3e24620280e70aa161403..HEAD:/sdk/R/R/RESTService.R diff --git a/sdk/R/R/RESTService.R b/sdk/R/R/RESTService.R index 867665299f..5cbcb65f75 100644 --- a/sdk/R/R/RESTService.R +++ b/sdk/R/R/RESTService.R @@ -36,16 +36,13 @@ RESTService <- R6::R6Class( { if(is.null(private$webDavHostName)) { - discoveryDocumentURL <- paste0("https://", private$rawHostName, - "/discovery/v1/apis/arvados/v1/rest") + publicConfigURL <- paste0("https://", private$rawHostName, + "/arvados/v1/config") - headers <- list(Authorization = paste("OAuth2", self$token)) - - serverResponse <- self$http$exec("GET", discoveryDocumentURL, headers, - retryTimes = self$numRetries) + serverResponse <- self$http$exec("GET", publicConfigURL, retryTimes = self$numRetries) - discoveryDocument <- self$httpParser$parseJSONResponse(serverResponse) - private$webDavHostName <- discoveryDocument$keepWebServiceUrl + configDocument <- self$httpParser$parseJSONResponse(serverResponse) + private$webDavHostName <- configDocument$Services$WebDAVDownload$ExternalURL if(is.null(private$webDavHostName)) stop("Unable to find WebDAV server.") @@ -81,10 +78,10 @@ RESTService <- R6::R6Class( { collectionURL <- paste0(self$getWebDavHostName(), "c=", uuid, "/") fromURL <- paste0(collectionURL, from) - toURL <- paste0(collectionURL, to) + toURL <- paste0(collectionURL, trimFromStart(to, "/")) headers <- list("Authorization" = paste("OAuth2", self$token), - "Destination" = toURL) + "Destination" = toURL) serverResponse <- self$http$exec("MOVE", fromURL, headers, retryTimes = self$numRetries) @@ -95,12 +92,31 @@ RESTService <- R6::R6Class( serverResponse }, - getCollectionContent = function(uuid) + copy = function(from, to, uuid) + { + collectionURL <- paste0(self$getWebDavHostName(), "c=", uuid, "/") + fromURL <- paste0(collectionURL, from) + toURL <- paste0(collectionURL, trimFromStart(to, "/")) + + headers <- list("Authorization" = paste("OAuth2", self$token), + "Destination" = toURL) + + serverResponse <- self$http$exec("COPY", fromURL, headers, + retryTimes = self$numRetries) + + if(serverResponse$status_code < 200 || serverResponse$status_code >= 300) + stop(paste("Server code:", serverResponse$status_code)) + + serverResponse + }, + + getCollectionContent = function(uuid, relativePath = NULL) + { collectionURL <- URLencode(paste0(self$getWebDavHostName(), - "c=", uuid)) + "c=", uuid, "/", relativePath)) - headers <- list("Authorization" = paste("OAuth2", self$token)) + headers <- list("Authorization" = paste("Bearer", self$token)) response <- self$http$exec("PROPFIND", collectionURL, headers, retryTimes = self$numRetries) @@ -212,8 +228,12 @@ RESTService <- R6::R6Class( serverResponse <- self$http$exec("PUT", fileURL, headers, body, retryTimes = self$numRetries) - if(serverResponse$status_code < 200 || serverResponse$status_code >= 300) - stop(paste("Server code:", serverResponse$status_code)) + if (serverResponse$status_code < 200){ # to wyrzuca błędy + stop(paste("Server code:", serverResponse$status_code))} + else if (serverResponse$status_code >= 300 & serverResponse$status_code < 422) { + stop(paste("Server code:", serverResponse$status_code))} + else if (serverResponse$status_code == 422 ) { + stop(paste("Project of that name already exists. If you want to change it use project_update() instead"))} paste("File created:", relativePath) }