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

Implement Object operations for Spaces API #146

Merged
merged 19 commits into from Feb 7, 2018

Conversation

amoeba
Copy link
Contributor

@amoeba amoeba commented Jan 9, 2018

Description

This implements the first half of the operations listed in #140 which are the Spaces API operations related to Objects

Related Issue

#140

No tests yet, since all these tests require external calls. See discussion in #140

@amoeba amoeba mentioned this pull request Jan 9, 2018
27 tasks
Copy link
Collaborator

@sckott sckott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work.

  • Add yourself as author to DESCRIPTION file
  • pulled your branch down - looks like man/spaces_delete_object.Rd was updated, run document() or equiv. again and push that

R/spaces.R Outdated
#' with the spaces key. If missing, defaults to value stored in an environment
#' variable \code{DO_SPACES_SECRET_KEY}.
#' @param ... Additional argument passed to \code{\link[aws.s3]{get_object}}
#'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amoeba if you want to include @author <youremail> tags for the functions you write go ahead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I'm okay not doing this.

R/spaces.R Outdated
#' # basename
#' spaces_put_object("./some-file.txt", space = "my-space")
#' }
spaces_put_object <- function(file, object = basename(file), space, spaces_key = NULL, spaces_secret = NULL, ...) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function doesn't error well if the file doesn't exist - maybe an internal check for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Roger.

R/spaces.R Outdated
#' @examples
#' \dontrun{
#' spaces_put_object("./some-file.txt", "my-object", "my-space")
#' spaces_get_object("my-object", "my-space")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding an example of how to convert the raw bytes to text would be good, e.g, rawToChar(x)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion! Will do.

R/spaces.R Outdated
#' spaces_put_object("./some-file.txt", "my-object", "my-space")
#' spaces_head_object("my-object", "my-space")
#' }
spaces_head_object <- function(object, space, spaces_key = NULL, spaces_secret = NULL, ...) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Toughts on the output structure from this function? Maybe make it into a named list instead? just via attributes(x)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that.

@amoeba
Copy link
Contributor Author

amoeba commented Jan 11, 2018

Thanks for the comments. Will update this PR.

@sckott
Copy link
Collaborator

sckott commented Jan 23, 2018

@amoeba sorry for delay - getting to looking this over hopefully today

@@ -10,6 +10,8 @@ Authors@R: c(
person("Hadley", "Wickham", role = "aut", email = "hadley@rstudio.com"),
person("Winston", "Chang", role = "aut", email = "winston@stdout.org"),
person("Bob", "Rudis", role = "ctb", email = "bob@rudis.net"),
person("Bryce", "Mecum", role = "ctb", email = "brycemecum@gmail.com",
comment = c("ORCID" = "0000-0002-0381-3766")),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, will gather ORCIDs for others later

base_url = spaces_base,
...)

# if (!requireNamespace("xml2")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amoeba i forget, did you mean to leave this block commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops. I did not! Will fix.

@sckott
Copy link
Collaborator

sckott commented Jan 25, 2018

@amoeba is space_create working for you?

I'm getting an error on every try, checked that my env vars are there.

SO with verbose curl output i'm seeing

space_create('new_space_name', config=httr::verbose())
-> PUT /new_space_name/ HTTP/1.1
-> Host: nyc3.digitaloceanspaces.com
-> User-Agent: libcurl/7.54.0 r-curl/3.1 httr/1.3.1
... cut out some stuff
<- HTTP/1.1 400 Bad Request
<- Date: Thu, 25 Jan 2018 02:37:06 GMT
<- Content-Length: 153
<- Content-Type: text/plain; charset=utf-8

so the URL seems like nyc3.digitaloceanspaces.com/space-name

whereas in creating one in the DO platform, and the API docs say the same, looks like the URL should be of the form

space-name.nyc3.digitaloceanspaces.com

thoughts? does it work for you?

#' spaces_object_put("some-file.txt", space = "my-space")
#'
#' # You can get a copy of the ACL
#' acl <- spaces_acl_get("some-file.txt", "my-space") %>% read_xml()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in examples, with Suggested pkgs, should use them conditionally on whether user has the pkg.

so

if (requireNamespace("xml2")) {
  do the thing
}

and inside that block (if user has xml2 installed) namespace xml2 calls

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, interesting. I can certainly do that.

#' acl <- spaces_acl_get("some-file.txt", "my-space") %>% read_xml()
#'
#' # Modify it as needed, then update it
#' spaces_acl_put("my-object", "my-space", acl)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is my-object supposed to be equivalent to some-file.txt ? if so could you change that, so peole can actually do the eg

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a mistake. Fixed.

@sckott
Copy link
Collaborator

sckott commented Jan 25, 2018

I couldn't get spaces_object_delete to work. I kept getting a The specified bucket does not exist error, even though the bucket defiinitely existed. work for you?

@amoeba
Copy link
Contributor Author

amoeba commented Jan 25, 2018

Thanks for taking a look. I really appreciated the letting us have a go at this and the helpful comments.

I don't think I have ever been able to space_create working. I assumed it was just still in progress. But I think spaces_object_delete was working fine. I'll test now.

@amoeba
Copy link
Contributor Author

amoeba commented Jan 25, 2018

Hrm, spaces_object_delete worked fine for me just now:

> spaces_object_delete("GDP.csv", "test-analogsea")
[1] TRUE

@sckott
Copy link
Collaborator

sckott commented Jan 25, 2018

Glad delete works. Wonder if they changed how spaces create works since that fxn was originally made here?

@amoeba
Copy link
Contributor Author

amoeba commented Jan 25, 2018

I wonder. I'll take a look at it.

@amoeba
Copy link
Contributor Author

amoeba commented Jan 25, 2018

Looks like a limitation of aws.s3. In setup_s3_url, which appears to generate the URLs used in put_bucket (which creates new S3 buckets), it hard-codes this logic:

# handle S3-compatible storage URLs
    if (base_url != "s3.amazonaws.com") {
        if (isTRUE(verbose) && url_style != "path") {
            message("Non-AWS base URL requested. Switching to path-style URLs.")
        }
...

which looks like the cause of our problem here.

@sckott
Copy link
Collaborator

sckott commented Jan 25, 2018

ah, that could be it, right, i assume then it adds the bucket/space name after the base url

@amoeba
Copy link
Contributor Author

amoeba commented Jan 25, 2018

yup

@sckott
Copy link
Collaborator

sckott commented Feb 7, 2018

bump @amoeba , are you waiting on me to do anything here?

@amoeba
Copy link
Contributor Author

amoeba commented Feb 7, 2018

Hey @sckott thanks for the bump. This can be merged if you think so. I looked over all of the comments here and in the related issue and I think it's good to go.

@sckott
Copy link
Collaborator

sckott commented Feb 7, 2018

okay, will take another quick look

@sckott
Copy link
Collaborator

sckott commented Feb 7, 2018

@amoeba can you add man-roxygen to .Rbuildignore

@amoeba
Copy link
Contributor Author

amoeba commented Feb 7, 2018

Done!

@sckott
Copy link
Collaborator

sckott commented Feb 7, 2018

thanks for the rbuildignore fix.

hmm, did you see my comment about space_create not working? #146 (comment)

@amoeba
Copy link
Contributor Author

amoeba commented Feb 7, 2018

I did. I was thinking that, since this PR is just for the Object API operations that I/we'd work on that elsewhere. It'll require either an upstream aws.s3 fix or moving away from using aws.s3. Is that okay?

@sckott
Copy link
Collaborator

sckott commented Feb 7, 2018

right, forgot about that. yep, we'll deal with fixing create later.

@sckott sckott added this to the v0.7 milestone Feb 7, 2018
@sckott sckott added the spaces label Feb 7, 2018
@sckott sckott merged commit 597484d into pachadotdev:master Feb 7, 2018
@amoeba amoeba deleted the spaces-object-api branch February 7, 2018 20:49
@sckott sckott modified the milestones: v0.7, v0.8 Jun 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants