Created
October 2, 2013 19:57
-
-
Save cwvhogue/6799590 to your computer and use it in GitHub Desktop.
First cut of a working code block that authenticates from R to Joyent Manta.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install.packages(c("RCurl","RJSONIO"), dependencies = TRUE) | |
require(RCurl); require(RJSONIO); | |
ACTION="/cwvhogue/stor" | |
MANTA_USER<-Sys.getenv("MANTA_USER"); | |
MANTA_KEY_ID<-Sys.getenv("MANTA_KEY_ID"); | |
MANTA_URL<-Sys.getenv("MANTA_URL"); | |
USER_HOME<-Sys.getenv("HOME"); | |
USER_KEY<-"/.ssh/id_rsa"; | |
key_location<-paste(USER_HOME,USER_KEY,sep=""); | |
openssl_cmd="openssl"; | |
digest_args<-paste("dgst -sha256 -sign", key_location, "-out temp_digest.bin", sep=" "); | |
encrypt_args<-"enc -in temp_digest.bin -e -a"; | |
alg<-"rsa-sha256"; | |
keyID<-paste("/",MANTA_USER,"/keys/",MANTA_KEY_ID, sep=""); | |
the_time_now<-format(as.POSIXlt(Sys.time(), "UTC"), "%a, %d %h %Y %H:%M:%S GMT"); | |
sig_to_digest<-paste("date:",the_time_now, sep=" "); | |
# write sig_to_digest to a binary file without any CR | |
con <- file("sig_to_digest.bin", 'wb'); | |
writeBin(charToRaw(sig_to_digest), con); | |
close(con); | |
system2(openssl_cmd, args=digest_args, stdin="sig_to_digest.bin", stdout=FALSE); | |
#this will need some kind of test to see if temp_digest.bin was formed | |
sig_encrypted<-paste(system2(openssl_cmd, args=encrypt_args, stdout=TRUE), collapse=''); | |
gone<-file.remove("temp_digest.bin"); | |
gone<-file.remove("sig_to_digest.bin"); | |
manta_url<-paste( | |
MANTA_URL, | |
ACTION, sep=""); | |
auth_header<-paste("Signature keyId=", | |
'\"', | |
keyID, | |
'\",', | |
'algorithm=\"', | |
alg, | |
'\"', | |
',signature=\"', | |
sig_encrypted, | |
'\"', | |
sep=""); | |
R_version<-as.character(getRversion()); | |
RAPI_USER<-paste("R/",R_version,"/",MANTA_USER,sep=""); | |
manta_headers<-c( 'User-Agent'=RAPI_USER , date=the_time_now, Authorization=auth_header); | |
json_manta_reply<-getURL(manta_url, httpheader=manta_headers, verbose = TRUE); | |
fromJSON(json_manta_reply); | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment