td 0.10.78 → 0.10.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ChangeLog CHANGED
@@ -1,3 +1,12 @@
1
+ == 2013-06-13 version 0.10.79
2
+
3
+ * -h option shows --version option
4
+ * Show more messages when network related error occurred
5
+ * Fix bulk import encoding issue when -e option is specified
6
+ * Add user:apikey:add subcommand
7
+ * Add user:apikey:remove subcommand
8
+
9
+
1
10
  == 2013-05-27 version 0.10.78
2
11
 
3
12
  * Add -q(--query) option to sched:create command
@@ -127,7 +127,7 @@ module List
127
127
  LIST = []
128
128
  COMMAND = {}
129
129
  GUESS = {}
130
- HELP_EXCLUDE = [/^help/, /^account/, /^aggr/]
130
+ HELP_EXCLUDE = [/^help/, /^account/, /^aggr/, /^update/, /^user/, /^ip_limit/, /^role/, /^org/, /^acl/]
131
131
  USAGE_EXCLUDE = [/bulk_import:upload_part\z/, /bulk_import:delete_part\z/]
132
132
 
133
133
  def self.add_list(name, args, description, *examples)
@@ -284,7 +284,9 @@ module List
284
284
  add_list 'user:show', %w[name], 'Show an user'
285
285
  add_list 'user:create', %w[name], 'Create an user'
286
286
  add_list 'user:delete', %w[name], 'Delete an user'
287
- add_list 'user:apikey:list', %w[name], 'Show API keys'
287
+ add_list 'user:apikey:list', %w[name], 'Show API keys of an user'
288
+ add_list 'user:apikey:add', %w[name], 'Add an API key to an user'
289
+ add_list 'user:apikey:remove', %w[name apikey], 'Remove an API key from an user'
288
290
  add_list 'user:password:change', %w[name], 'Change password'
289
291
 
290
292
  add_list 'role:list', %w[], 'Show list of roles'
@@ -96,6 +96,11 @@ EOF
96
96
  usage nil
97
97
  }
98
98
 
99
+ op.on('--version', "show version") {
100
+ puts op.version
101
+ exit
102
+ }
103
+
99
104
  begin
100
105
  op.order!(argv)
101
106
  usage nil if argv.empty?
@@ -133,13 +138,23 @@ EOF
133
138
  rescue TreasureData::ConfigError
134
139
  $stderr.puts "TreasureData account is not configured yet."
135
140
  $stderr.puts "Run '#{$prog} account' first."
136
- rescue
141
+ rescue => e
137
142
  $stderr.puts "error #{$!.class}: backtrace:"
138
143
  $!.backtrace.each {|b|
139
144
  $stderr.puts " #{b}"
140
145
  }
141
146
  puts ""
142
147
  puts $!
148
+
149
+ require 'socket'
150
+ if e.is_a?(::SocketError)
151
+ $stderr.puts <<EOS
152
+
153
+ Network dependent error occurred.
154
+ If you want to use td command through a proxy,
155
+ please set HTTP_PROXY environment variable (e.g. export HTTP_PROXY="host:port")
156
+ EOS
157
+ end
143
158
  end
144
159
  end
145
160
  end
@@ -110,17 +110,25 @@ module Command
110
110
 
111
111
  rows = []
112
112
  ::Parallel.each(databases, :in_threads => num_threads) {|db|
113
- db.tables.each {|table|
114
- pschema = table.schema.fields.map {|f|
115
- "#{f.name}:#{f.type}"
116
- }.join(', ')
117
- rows << {
118
- :Database => db.name, :Table => table.name, :Type => table.type.to_s, :Count => TreasureData::Helpers.format_with_delimiter(table.count),
119
- :Size => show_size_in_bytes ? TreasureData::Helpers.format_with_delimiter(table.estimated_storage_size) : table.estimated_storage_size_string,
120
- 'Last import' => table.last_import ? table.last_import.localtime : nil,
121
- :Schema => pschema
113
+ begin
114
+ db.tables.each {|table|
115
+ pschema = table.schema.fields.map {|f|
116
+ "#{f.name}:#{f.type}"
117
+ }.join(', ')
118
+ rows << {
119
+ :Database => db.name, :Table => table.name, :Type => table.type.to_s, :Count => TreasureData::Helpers.format_with_delimiter(table.count),
120
+ :Size => show_size_in_bytes ? TreasureData::Helpers.format_with_delimiter(table.estimated_storage_size) : table.estimated_storage_size_string,
121
+ 'Last import' => table.last_import ? table.last_import.localtime : nil,
122
+ :Schema => pschema
123
+ }
122
124
  }
123
- }
125
+ rescue APIError => e
126
+ # ignores permission error because db:list shows all databases
127
+ # even if the user can't access to tables in the database
128
+ unless e.to_s =~ /not authorized/
129
+ raise e
130
+ end
131
+ end
124
132
  }
125
133
  rows = rows.sort_by {|map|
126
134
  [map[:Database], map[:Type].size, map[:Table]]
@@ -133,22 +133,10 @@ module Command
133
133
  client.create_organization(org)
134
134
  end
135
135
 
136
- ok = false
137
136
  begin
138
137
  client.add_user(name, org, email, password)
139
-
140
- begin
141
- client.add_apikey(name)
142
- ok = true
143
-
144
- ensure
145
- if !ok
146
- client.remove_user(name)
147
- end
148
- end
149
-
150
138
  ensure
151
- if create_org && !ok
139
+ if create_org
152
140
  client.delete_organization(org)
153
141
  end
154
142
  end
@@ -175,13 +163,39 @@ module Command
175
163
  #def user_email_change(op)
176
164
  #end
177
165
 
178
- ## TODO user:apikey:add <name>
179
- #def user_apikey_add(op)
180
- #end
166
+ def user_apikey_add(op)
167
+ name = op.cmd_parse
181
168
 
182
- ## TODO user:apikey:remove <name> <apikey>
183
- #def user_apikey_remove(op)
184
- #end
169
+ client = get_client
170
+
171
+ begin
172
+ client.add_apikey(name)
173
+ rescue TreasureData::NotFoundError
174
+ $stderr.puts "User '#{name}' does not exist."
175
+ $stderr.puts "Use '#{$prog} users' to show users."
176
+ exit 1
177
+ end
178
+
179
+ $stderr.puts "Added an API key to user '#{name}'."
180
+ $stderr.puts "Use '#{$prog} user:apikeys #{name}' to show the API key"
181
+ end
182
+
183
+ def user_apikey_remove(op)
184
+ name, key = op.cmd_parse
185
+
186
+ client = get_client
187
+
188
+ begin
189
+ client.remove_apikey(name, key)
190
+ rescue TreasureData::NotFoundError
191
+ $stderr.puts "User '#{name}' or API key '#{key}' does not exist."
192
+ $stderr.puts "Use '#{$prog} users' to show users."
193
+ $stderr.puts "Use '#{$prog} user:apikeys '#{key}' to show API keys"
194
+ exit 1
195
+ end
196
+
197
+ $stderr.puts "Removed an an API key from user '#{name}'."
198
+ end
185
199
 
186
200
  def user_apikey_list(op)
187
201
  name = op.cmd_parse
@@ -50,7 +50,7 @@ module TreasureData
50
50
  class LineReader
51
51
  def initialize(io, error, opts)
52
52
  if encoding = opts[:encoding]
53
- io.set_encoding(encoding) if io.respond_to?(:set_encoding)
53
+ io.set_encoding(encoding, 'UTF-8') if io.respond_to?(:set_encoding)
54
54
  end
55
55
  #@delimiter = opts[:line_delimiter_expr] || /\r?\n/
56
56
  @io = io
data/lib/td/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module TreasureData
2
2
 
3
- VERSION = '0.10.78'
3
+ VERSION = '0.10.79'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: td
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.78
4
+ version: 0.10.79
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-27 00:00:00.000000000 Z
12
+ date: 2013-06-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: msgpack
@@ -262,7 +262,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
262
262
  version: '0'
263
263
  segments:
264
264
  - 0
265
- hash: 2134623419874142893
265
+ hash: 860167470271522845
266
266
  required_rubygems_version: !ruby/object:Gem::Requirement
267
267
  none: false
268
268
  requirements:
@@ -271,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
271
271
  version: '0'
272
272
  segments:
273
273
  - 0
274
- hash: 2134623419874142893
274
+ hash: 860167470271522845
275
275
  requirements: []
276
276
  rubyforge_project:
277
277
  rubygems_version: 1.8.23