Merge branch '21666-provision-test-improvement'
[arvados.git] / sdk / R / R / RESTService.R
index 78b2c35e32fa117190f033075e1ea5ee2a3805e3..5cbcb65f753b769ec108fa9f757ba6b1f219443d 100644 (file)
@@ -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.")
@@ -113,12 +110,13 @@ RESTService <- R6::R6Class(
             serverResponse
         },
 
-        getCollectionContent = function(uuid)
+       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)
@@ -230,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)
         }