{"id":420,"date":"2016-02-02T18:35:33","date_gmt":"2016-02-02T18:35:33","guid":{"rendered":"http:\/\/www.haxed.me.uk\/?p=420"},"modified":"2016-02-02T18:39:22","modified_gmt":"2016-02-02T18:39:22","slug":"using-cloud-files-versioning-setting-up-from-scratch","status":"publish","type":"post","link":"https:\/\/haxed.me.uk\/index.php\/2016\/02\/02\/using-cloud-files-versioning-setting-up-from-scratch\/","title":{"rendered":"Using Cloud Files Versioning, Setting up from Scratch"},"content":{"rendered":"<p>Sooooo.. you want to use cloud-files, but, you want to have versioning? no problem! Here&#8217;s how you do it from the ground up. <\/p>\n<h1> Authorise yourself thru identity API <\/h1>\n<h4> Basically&#8230; set the token by querying the identity api with username and password.. <\/h4>\n<pre>\r\n!\/bin\/bash\r\n\r\n# Username used to login to control panel\r\nUSERNAME='mycloudusername'\r\n\r\n# Find the APIKey in the 'account settings' part of the menu of the control panel\r\nAPIKEY='mycloudapikey'\r\n\r\n# This section simply retrieves the TOKEN\r\nTOKEN=`curl https:\/\/identity.api.rackspacecloud.com\/v2.0\/tokens -X POST -d '{ \"auth\":{\"RAX-KSKEY:apiKeyCredentials\": { \"username\":\"'$USERNAME'\", \"apiKey\": \"'$APIKEY'\" }} }' -H \"Content-type: application\/json\" |  python -mjson.tool | grep -A5 token | grep id | cut -d '\"' -f4`\r\n\r\n<\/pre>\n<p>If you were to add to this file;<\/p>\n<pre>\r\necho $TOKEN\r\n<\/pre>\n<p>You&#8217;d see this when running it<\/p>\n<pre>\r\n# .\/versioning.sh\r\n  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\r\n                                 Dload  Upload   Total   Spent    Left  Speed\r\n100  5143  100  5028  100   115   3991     91  0:00:01  0:00:01 --:--:--  3996\r\n8934534DFGJdfSdsdFDS232342DFFsDDFIKJDFijTx8WMIDO8CYzbhyViGGyekRYvtw3skCYMaqIWhw8adskfjds894FGKJDFKj34i2jgidgjdf@DFsSDsd\r\n<\/pre>\n<p>To understand how the curl works to authorise itself with the identity API and specifically how the TOKEN is extracted from the return output and set in the script, here is the -v verbose output<\/p>\n<pre>\r\n\r\n# .\/versioning.sh\r\n  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\r\n                                 Dload  Upload   Total   Spent    Left  Speed\r\n  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0\r\n* About to connect() to identity.api.rackspacecloud.com port 443 (#0)\r\n*   Trying 72.3.138.129...\r\n* Connected to identity.api.rackspacecloud.com (72.3.138.129) port 443 (#0)\r\n* Initializing NSS with certpath: sql:\/etc\/pki\/nssdb\r\n*   CAfile: \/etc\/pki\/tls\/certs\/ca-bundle.crt\r\n  CApath: none\r\n* SSL connection using TLS_DHE_RSA_WITH_AES_128_CBC_SHA\r\n* Server certificate:\r\n* \tsubject: CN=identity.api.rackspacecloud.com,OU=Domain Validated,OU=Thawte SSL123 certificate,OU=Go to https:\/\/www.thawte.com\/repository\/index.html,O=identity.api.rackspacecloud.com\r\n* \tstart date: Nov 14 00:00:00 2011 GMT\r\n* \texpire date: Nov 12 23:59:59 2016 GMT\r\n* \tcommon name: identity.api.rackspacecloud.com\r\n* \tissuer: CN=Thawte DV SSL CA,OU=Domain Validated SSL,O=\"Thawte, Inc.\",C=US\r\n  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0> POST \/v2.0\/tokens HTTP\/1.1\r\n> User-Agent: curl\/7.29.0\r\n> Host: identity.api.rackspacecloud.com\r\n> Accept: *\/*\r\n> Content-type: application\/json\r\n> Content-Length: 115\r\n>\r\n} [data not shown]\r\n* upload completely sent off: 115 out of 115 bytes\r\n< HTTP\/1.1 200 OK\r\n< Server: nginx\r\n< Date: Tue, 02 Feb 2016 18:19:06 GMT\r\n< Content-Type: application\/json\r\n< Content-Length: 5028\r\n< Connection: keep-alive\r\n< X-NewRelic-App-Data: Censored\r\n< vary: Accept, Accept-Encoding, X-Auth-Token\r\n< Front-End-Https: on\r\n<\r\n{ [data not shown]\r\n100  5143  100  5028  100   115   3825     87  0:00:01  0:00:01 --:--:--  3826\r\n* Connection #0 to host identity.api.rackspacecloud.com left intact\r\n{\r\n    \"access\": {\r\n        \"serviceCatalog\": [\r\n            {\r\n                \"endpoints\": [\r\n                    {\r\n                        \"internalURL\": \"https:\/\/snet-storage101.lon3.clouddrive.com\/v1\/MossoCloudFS_10045567\",\r\n                        \"publicURL\": \"https:\/\/storage101.lon3.clouddrive.com\/v1\/MossoCloudFS_10045567\",\r\n                        \"region\": \"LON\",\r\n                        \"tenantId\": \"MossoCloudFS_10010101\"\r\n                    }\r\n                ],\r\n                \"name\": \"cloudFiles\",\r\n                \"type\": \"object-store\"\r\n            },\r\n            {\r\n   \"token\": {\r\n            \"RAX-AUTH:authenticatedBy\": [\r\n                \"APIKEY\"\r\n            ],\r\n            \"expires\": \"2016-02-03T18:31:18.838Z\",\r\n            \"id\": \"#$dfgkldfkl34klDFGDFGLK#$OFDOKGDFODJ#$OFDOGIDFOGI34ldfldfgkdo34lfdFGDKDFGDODFKDFGDFLK\",\r\n            \"tenant\": {\r\n                \"id\": \"10010101\",\r\n                \"name\": \"10010101\"\r\n            }\r\n        },\r\n\r\n<\/pre>\n<p>This is truncated, the output is larger, but basically the \"token\" section is stripped away at the id: part so that only the string is left, then  that password is added into the TOKEN variable.<\/p>\n<p>So no you understand auth.<\/p>\n<h1> Create the Version container <\/h1>\n<h3> This contains all of the version changes of any file <\/h3>\n<p>i.e. if you overwrite a file 10 times, all 10 versions will be saved<\/p>\n<pre>\r\n# Create Versioning Container (Backup versions)\r\ncurl -i -XPUT -H \"X-Auth-Token: $TOKEN\" https:\/\/storage101.lon3.clouddrive.com\/v1\/MossoCloudFS_10010101\/versions\r\n<\/pre>\n<p>Note we use $TOKEN , which is basically just hte password with the X-Auth-Token Header. -H means 'send this header'. X-Auth-Token is the header name, and $TOKEN is the password we populated in the variable in the first auth section above.<\/p>\n<h1> Create a Current Container <\/h1>\n<h3> This only contains the 'current' or most latest version of the file <\/h3>\n<pre>\r\n# Create current container (latest versions)\r\ncurl -i -XPUT -H \"X-Auth-Token: $TOKEN\" -H  \"X-Versions-Location: versions\"  https:\/\/storage101.lon3.clouddrive.com\/v1\/MossoCloudFS_10010101\/current\r\n<\/pre>\n<p>I'm being a bit naughty here, I could make MossoCloudFS_10010101 a variable, like $CONTAINERSTORE or $CONTAINERPARENT. Or better $TENANTCONTAINER But meh. You get the idea. And learnt something. <\/p>\n<p>Note importantly X-Versions-Location Header set when creating the 'current' cloud files container. It's asking to store versions of changes in current to the versions folder. Nice.<\/p>\n<h1> Create an object <\/h1>\n<h3> Create the first version of an object, because its awesome <\/h3>\n<pre>\r\n# Create an object\r\ncurl -i -XPUT --data-binary 1 -H \"X-Auth-Token: $TOKEN\" https:\/\/storage101.lon3.clouddrive.com\/v1\/MossoCloudFS_10010101\/current\/myobject.obj\r\n<\/pre>\n<p>yay! My first object. I just put the number 1 in it. Not very imaginative but you get the idea. Now lets revise the object<\/p>\n<h1> Create a new version of the object <\/h1>\n<pre>\r\n# Create a new version of the object (second version)\r\ncurl -i -XPUT --data-binary 2 -H \"X-Auth-Token: $TOKEN\" https:\/\/storage101.lon3.clouddrive.com\/v1\/MossoCloudFS_10010101\/current\/myobject.obj\r\n<\/pre>\n<h1> Create a list of the older versions of the object <\/h1>\n<pre>\r\n# Create a list of the older versions of the object\r\ncurl -i -H \"X-Auth-Token: $TOKEN\" https:\/\/storage101.lon3.clouddrive.com\/v1\/MossoCloudFS_10010101\/versions?prefix=008myobject.obj\r\n<\/pre>\n<h1> Delete the current version of an object <\/h1>\n<pre>\r\n# Delete the current version of the object\r\ncurl -i -XDELETE -H \"X-Auth-Token: $TOKEN\" https:\/\/storage101.lon3.clouddrive.com\/v1\/MossoCloudFS_10010101\/versions?prefix=008myobject.obj\r\n<\/pre>\n<p>Pretty cool. Altogether now.<\/p>\n<pre>\r\n#!\/bin\/bash\r\n\r\n# Username used to login to control panel\r\nUSERNAME='mycloudusername'\r\n\r\n# Find the APIKey in the 'account settings' part of the menu of the control panel\r\nAPIKEY=mycloudapikey'\r\n\r\n\r\n# This section simply retrieves the TOKEN\r\nTOKEN=`curl https:\/\/identity.api.rackspacecloud.com\/v2.0\/tokens -X POST -d '{ \"auth\":{\"RAX-KSKEY:apiKeyCredentials\": { \"username\":\"'$USERNAME'\", \"apiKey\": \"'$APIKEY'\" }} }' -H \"Content-type: application\/json\" |  python -mjson.tool | grep -A5 token | grep id | cut -d '\"' -f4`\r\n\r\n\r\n# This section requests the Glance API to copy the cloud server image uuid to a cloud files container called export\r\n\r\n# Create Versioning Container (Backup versions)\r\ncurl -i -XPUT -H \"X-Auth-Token: $TOKEN\" https:\/\/storage101.lon3.clouddrive.com\/v1\/MossoCloudFS_10010101\/versions\r\n\r\n# Create current container (latest versions)\r\ncurl -i -XPUT -H \"X-Auth-Token: $TOKEN\" -H  \"X-Versions-Location: versions\"  https:\/\/storage101.lon3.clouddrive.com\/v1\/MossoCloudFS_10010101\/current\r\n\r\n\r\n# Create an object\r\ncurl -i -XPUT --data-binary 1 -H \"X-Auth-Token: $TOKEN\" https:\/\/storage101.lon3.clouddrive.com\/v1\/MossoCloudFS_10010101\/current\/myobject.obj\r\n\r\n# Create a new version of the object (second version)\r\ncurl -i -XPUT --data-binary 2 -H \"X-Auth-Token: $TOKEN\" https:\/\/storage101.lon3.clouddrive.com\/v1\/MossoCloudFS_10010101\/current\/myobject.obj\r\n\r\n# Create a list of the older versions of the object\r\ncurl -i -H \"X-Auth-Token: $TOKEN\" https:\/\/storage101.lon3.clouddrive.com\/v1\/MossoCloudFS_10010101\/versions?prefix=008myobject.obj\r\n\r\n# Delete the current version of the object\r\n\r\ncurl -i -XDELETE -H \"X-Auth-Token: $TOKEN\" https:\/\/storage101.lon3.clouddrive.com\/v1\/MossoCloudFS_10010101\/versions?prefix=008myobject.obj\r\n<\/pre>\n<p>What the output of the full script looks like:<\/p>\n<pre>\r\n# .\/versioning.sh\r\n  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\r\n                                 Dload  Upload   Total   Spent    Left  Speed\r\n100  5143  100  5028  100   115   4291     98  0:00:01  0:00:01 --:--:--  4290\r\nHTTP\/1.1 202 Accepted\r\nContent-Length: 76\r\nContent-Type: text\/html; charset=UTF-8\r\nX-Trans-Id: tx514bac5247924b5db247d-0056b0ecb7lon3\r\nDate: Tue, 02 Feb 2016 17:51:51 GMT\r\n\r\n<html><h1>Accepted<\/h1><p>The request is accepted for processing.<\/p><\/html>HTTP\/1.1 202 Accepted\r\nContent-Length: 76\r\nContent-Type: text\/html; charset=UTF-8\r\nX-Trans-Id: tx7b7f42fc19b1428b97cfa-0056b0ecb8lon3\r\nDate: Tue, 02 Feb 2016 17:51:52 GMT\r\n\r\n<html><h1>Accepted<\/h1><p>The request is accepted for processing.<\/p><\/html>HTTP\/1.1 201 Created\r\nLast-Modified: Tue, 02 Feb 2016 17:51:53 GMT\r\nContent-Length: 0\r\nEtag: c4ca4238a0b923820dcc509a6f75849b\r\nContent-Type: text\/html; charset=UTF-8\r\nX-Trans-Id: tx2495824253374261bf52a-0056b0ecb8lon3\r\nDate: Tue, 02 Feb 2016 17:51:53 GMT\r\n\r\nHTTP\/1.1 201 Created\r\nLast-Modified: Tue, 02 Feb 2016 17:51:54 GMT\r\nContent-Length: 0\r\nEtag: c81e728d9d4c2f636f067f89cc14862c\r\nContent-Type: text\/html; charset=UTF-8\r\nX-Trans-Id: tx785e4a5b784243a1b8034-0056b0ecb9lon3\r\nDate: Tue, 02 Feb 2016 17:51:54 GMT\r\n\r\nHTTP\/1.1 204 No Content\r\nContent-Length: 0\r\nX-Container-Object-Count: 2\r\nAccept-Ranges: bytes\r\nX-Storage-Policy: Policy-0\r\nX-Container-Bytes-Used: 2\r\nX-Timestamp: 1454435183.80523\r\nContent-Type: text\/html; charset=UTF-8\r\nX-Trans-Id: tx4782072371924905bc513-0056b0ecbalon3\r\nDate: Tue, 02 Feb 2016 17:51:54 GMT\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Sooooo.. you want to use cloud-files, but, you want to have versioning? no problem! Here&#8217;s how you do it from the ground up. Authorise yourself thru identity API Basically&#8230; set the token by querying the identity api with username and &hellip; <a href=\"https:\/\/haxed.me.uk\/index.php\/2016\/02\/02\/using-cloud-files-versioning-setting-up-from-scratch\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,19,15,14,7],"tags":[],"class_list":["post-420","post","type-post","status-publish","format-standard","hentry","category-api","category-bash","category-cloud","category-cloud-files","category-management-tools"],"_links":{"self":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/420","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/comments?post=420"}],"version-history":[{"count":3,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/420\/revisions"}],"predecessor-version":[{"id":423,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/420\/revisions\/423"}],"wp:attachment":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/media?parent=420"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/categories?post=420"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/tags?post=420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}