Unsolved

This post is more than 5 years old

281 Posts

3562

July 10th, 2012 10:00

Uploading a file to Atmos with Bash and Curl (and a little Python)

Here's an easy script to upload a file from bash using curl.  A small amount of Python is used here to compute the signature but you could substitue Perl or openssl if Python is not available.  The sections underlined should be modified to meet your local settings:

 

# Set up uid, key, and endpoint

uid="0206f43cfbb54e9099ee8de1ec77cf19/test1"

key="O4JmllPlIoqXPxcfWhrGV1TG2Y0="

endpoint="http://10.242.25.63"


# Choose the file to upload

file_to_upload=/etc/hosts


# Choose the Atmos directory to upload the file

atmos_dir="/share/"


# Build and send the Atmos request

filename=`basename $file_to_upload`

atmos_path="/rest/namespace${atmos_dir}$filename"

contentType="text/plain"

date=`date -u +"%a, %d %b %Y %H:%M:%S GMT"`

signstr="POST\n${contentType}\n\n\n${atmos_path}\nx-emc-date:${date}\nx-emc-uid:${uid}"

sig=$(python -c "import base64, hmac, sha; print base64.b64encode(hmac.new(base64.b64decode(\"$key\"), \"$signstr\", sha).digest())")

curl -i -X POST -H "Content-Type:$contentType" -H "x-emc-date:$date" -H "x-emc-uid:$uid" -H "x-emc-signature:$sig" --data-binary @${file_to_upload} ${endpoint}${atmos_path}


When you run the script, you'll get a success or failure response from the server:

HTTP/1.1 201 Created

Date: Tue, 10 Jul 2012 16:38:57 GMT

Server: Apache

x-emc-policy: default

x-emc-delta: 649

location: /rest/objects/4fccd760a1f2194004fcce05b010a304ffc5aa15c541

Content-Length: 0

Connection: close

Content-Type: text/plain

You can parse the location response header to get the object ID if required.

281 Posts

August 6th, 2012 11:00

Tom,

If you're looking for something with a CLI interface and have PHP available, I'd use xcloudtool:

http://code.google.com/p/xcloudtool/

August 6th, 2012 11:00

Great post Jason! Would you be able to put this into java and create a quick .jar with an interface that you can add customer metadata to or modify the exiting AtmosConnect? This would help with users at companies who are required to perform regression testing against Atmos and its metering abilities (ACDP). Thanks!

August 6th, 2012 17:00

Jason,

Although this is a great tool, I was thinking more inline with what is provided via the Atmos Procedure Generator (AtmosConnect). If a modification of the AtmosConnect tool was done to allow testing of custom policies created at installation I think it would be a great additon.

Thanks,

Tom

No Events found!

Top