]> git.arvados.org - arvados.git/blob - sdk/cli/bin/arv-tag
Adding `tag' command: initial commit.
[arvados.git] / sdk / cli / bin / arv-tag
1 #! /usr/bin/env ruby
2
3 # arv tag usage:
4 #   arv tag add tag1 [tag2 ...] --objects obj_uuid1 [obj_uuid2 ...]
5 #   arv tag remove tag1 [tag2 ...] --objects obj_uuid1 [obj_uuid2 ...]
6 #   arv tag remove tag1 [tag2 ...] --all
7
8 if RUBY_VERSION < '1.9.3' then
9   abort <<-EOS
10 #{$0.gsub(/^\.\//,'')} requires Ruby version 1.9.3 or higher.
11   EOS
12 end
13
14 $arvados_api_version = ENV['ARVADOS_API_VERSION'] || 'v1'
15 $arvados_api_host = ENV['ARVADOS_API_HOST'] or
16   abort "#{$0}: fatal: ARVADOS_API_HOST environment variable not set."
17 $arvados_api_token = ENV['ARVADOS_API_TOKEN'] or
18   abort "#{$0}: fatal: ARVADOS_API_TOKEN environment variable not set."
19
20 begin
21   require 'rubygems'
22   require 'google/api_client'
23   require 'json'
24   require 'pp'
25   require 'trollop'
26 rescue LoadError
27   abort <<-EOS
28 #{$0}: fatal: some runtime dependencies are missing.
29 Try: gem install pp google-api-client json trollop
30   EOS
31 end
32
33 def debuglog(message, verbosity=1)
34   $stderr.puts "#{File.split($0).last} #{$$}: #{message}" if $debuglevel >= verbosity
35 end
36
37 module Kernel
38   def suppress_warnings
39     original_verbosity = $VERBOSE
40     $VERBOSE = nil
41     result = yield
42     $VERBOSE = original_verbosity
43     return result
44   end
45 end
46
47 if $arvados_api_host.match /local/
48   # You probably don't care about SSL certificate checks if you're
49   # testing with a dev server.
50   suppress_warnings { OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE }
51 end
52
53 class Google::APIClient
54   def discovery_document(api, version)
55     api = api.to_s
56     return @discovery_documents["#{api}:#{version}"] ||=
57       begin
58         response = self.execute!(
59                                  :http_method => :get,
60                                  :uri => self.discovery_uri(api, version),
61                                  :authenticated => false
62                                  )
63         response.body.class == String ? JSON.parse(response.body) : response.body
64       end
65   end
66 end
67