Skip to content

Instantly share code, notes, and snippets.

@seungjin
Created May 22, 2011 18:07
Show Gist options
  • Save seungjin/985719 to your computer and use it in GitHub Desktop.
Save seungjin/985719 to your computer and use it in GitHub Desktop.
##
## All files that are a part of this project, unless explicitly noted otherwise,
## are covered by the following license:
##
## Copyright (c) 2011, The Arizona Board of Regents on behalf of The University
## of Arizona
##
## All rights reserved.
##
## Developed by: iPlant Collaborative as a collaboration between participants at
## BIO5 at The University of Arizona (the primary hosting institution), Cold Spr
## ing Harbor Laboratory, The University of Texas at Austin, and individual cont
## ributors. Find out more at http://www.iplantcollaborative.org/.
##
## Redistribution and use in source and binary forms, with or without modificati
## on, are permitted provided that the following conditions are met:
##
## * Redistributions of source code must retain the above copyright notice, this
## list of conditions and the following disclaimer.
## * Redistributions in binary form must reproduce the above copyright notice, t
## his list of conditions and the following disclaimer in the documentation an
## d/or other materials provided with the distribution.
## * Neither the name of the iPlant Collaborative, BIO5, The University of Arizo
## na, Cold Spring Harbor Laboratory, The University of Texas at Austin, nor t
## he names of other contributors may be used to endorse or promote products d
## erived from this software without specific prior written permission.
##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" A
## ND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPL
## IED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DI
## SCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FO
## R ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMA
## GES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVIC
## ES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED A
## ND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
## SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
##
##
## Author: Seung-jin Kim <twitter: @seungjin>
##
require 'logger'
require 'net/http'
require 'net/https'
require 'open3'
require 'etc'
# get token
$token_server_url = "https://atmo-beta.iplantcollaborative.org/auth"
def getToken(user_id, user_password)
url = URI.parse($token_server_url)
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
data = nil
headers = {
"Content-type" => "application/x-www-form-urlencoded",
"Accept" => "text/plain",
"X-Auth-User" => user_id,
"X-Auth-Key" => user_password,
"User-Agent" => "Ruby / Atmo_mount"
}
resp, data = http.post(url.path, data, headers)
#resp, data = http.get(url.path, nil)
#p resp['x-auth-token']
#p resp['x-cdn-management-url']
#p resp['x-server-management-url']
#p resp['date']
#p resp['x-storage-url']
return resp['x-server-management-url'], resp['x-auth-token']
end
def getMyVolumeList(userid,token)
puts "A"
end
def getPassword()
begin
print "Password:"
system "stty -echo"
password = $stdin.gets.chomp
system "stty echo"
return password
rescue NoMethodError, Interrupt
#
system "stty echo"
exit
end
end
def attachVolume()
end
def detacheVolume()
end
def mountVolume()
end
def umountVolume()
end
def listAttachedDevices()
end
my_name = Etc.getlogin
puts "Hi! #{my_name}"
password = getPassword()
service_url, token = getToken(my_name,password)
if service_url == nil or token == nil
puts "\nPassword wrong... "
exit
end
getMyVolumeList(my_name,token)
# usage: atmo_volume list
# usage: atmo_volume mount vol-123 /mydirectory
# usage: atmo_volume umount /mydirectory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment