soracom 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/soracom/cli.rb +40 -15
- data/lib/soracom/client.rb +33 -3
- data/lib/soracom/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 276f913a7cb1bc4256133a313758c3ff0bf0586a
|
4
|
+
data.tar.gz: ae10d579fd37349651954bb0a3f348d48685c700
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73d03edb0033258e9392cbab65718396e9592f1ff12e42dfa88d63ba67acbaf8638cb07a82845de3d3af23e461176cb145dcfb982bc231d40acf654e8961cd96
|
7
|
+
data.tar.gz: 6f260fa99d3bb56ce471617f0d8b413ce7a0ce7ff2d2cb7ab49aa9d62dbfb2ac33144e1a325fbfa07f5297b6cc21c3ab843e421c10c000bd57686a3d8f0929e3
|
data/Gemfile.lock
CHANGED
data/lib/soracom/cli.rb
CHANGED
@@ -116,7 +116,7 @@ module SoracomCli
|
|
116
116
|
puts JSON.pretty_generate(client.unset_group(options[:imsi]))
|
117
117
|
end
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
# Group related commands
|
121
121
|
class Group < Thor
|
122
122
|
desc 'list', 'list groups'
|
@@ -125,28 +125,28 @@ module SoracomCli
|
|
125
125
|
client = Soracom::Client.new
|
126
126
|
puts JSON.pretty_generate(client.list_groups(options.group_id))
|
127
127
|
end
|
128
|
-
|
128
|
+
|
129
129
|
desc 'list_subscribers', 'list subscriber in a group'
|
130
130
|
option :group_id, type: :string, required:true, desc: 'group ID'
|
131
131
|
def list_subscribers
|
132
132
|
client = Soracom::Client.new
|
133
133
|
puts JSON.pretty_generate(client.list_subscribers_in_group(options.group_id))
|
134
134
|
end
|
135
|
-
|
135
|
+
|
136
136
|
desc 'create', 'create group'
|
137
137
|
option :tags, type: :hash, desc: 'group tags'
|
138
138
|
def create
|
139
139
|
client = Soracom::Client.new
|
140
140
|
puts JSON.pretty_generate(client.create_group(options.tags))
|
141
141
|
end
|
142
|
-
|
142
|
+
|
143
143
|
desc 'delete_group', 'delete a group'
|
144
144
|
option :group_id, type: :string, required:true, desc: 'group ID'
|
145
145
|
def delete
|
146
146
|
client = Soracom::Client.new
|
147
147
|
puts JSON.pretty_generate(client.delete_group(options.group_id))
|
148
148
|
end
|
149
|
-
|
149
|
+
|
150
150
|
desc 'update_configuration', 'update configuration parameter'
|
151
151
|
option :group_id, type: :string, required:true, desc: 'group ID'
|
152
152
|
option :namespace, type: :string, required:true, desc: 'namespace of the parameter'
|
@@ -155,7 +155,7 @@ module SoracomCli
|
|
155
155
|
client = Soracom::Client.new
|
156
156
|
puts JSON.pretty_generate(client.update_group_configuration(options.group_id, options.namespace, options.params))
|
157
157
|
end
|
158
|
-
|
158
|
+
|
159
159
|
desc 'delete_configuration', 'delete configuration parameter'
|
160
160
|
option :group_id, type: :string, required:true, desc: 'group ID'
|
161
161
|
option :namespace, type: :string, required:true, desc: 'namespace of the parameter'
|
@@ -172,7 +172,7 @@ module SoracomCli
|
|
172
172
|
client = Soracom::Client.new
|
173
173
|
puts JSON.pretty_generate(client.update_group_tags(options.group_id, options.tags))
|
174
174
|
end
|
175
|
-
|
175
|
+
|
176
176
|
desc 'delete_tag', 'delete group tag'
|
177
177
|
option :group_id, type: :string, required:true, desc: 'group ID'
|
178
178
|
option :name, type: :string, required:true, desc: 'tag name to delete'
|
@@ -181,7 +181,7 @@ module SoracomCli
|
|
181
181
|
puts JSON.pretty_generate(client.delete_group_tags(options.group_id, options.name))
|
182
182
|
end
|
183
183
|
end
|
184
|
-
|
184
|
+
|
185
185
|
# EventHandler related commands
|
186
186
|
class EventHandler < Thor
|
187
187
|
desc 'list', 'list event handlers'
|
@@ -192,21 +192,21 @@ module SoracomCli
|
|
192
192
|
client = Soracom::Client.new
|
193
193
|
puts JSON.pretty_generate(client.list_event_handlers(Hash[options.map { |k, v| [k.to_sym, v] }]))
|
194
194
|
end
|
195
|
-
|
195
|
+
|
196
196
|
desc 'create', 'create event handler'
|
197
197
|
option :req, type: :string, desc: 'JSON string of event handler configuration'
|
198
198
|
def create
|
199
199
|
client = Soracom::Client.new
|
200
200
|
puts JSON.pretty_generate(client.create_event_handler(options.req))
|
201
201
|
end
|
202
|
-
|
202
|
+
|
203
203
|
desc 'delete', 'delete event handler'
|
204
204
|
option :handler_id, type: :string, required:true, desc: 'Event Handler ID'
|
205
205
|
def delete
|
206
206
|
client = Soracom::Client.new
|
207
207
|
puts JSON.pretty_generate(client.delete_event_handler(options.handler_id))
|
208
208
|
end
|
209
|
-
|
209
|
+
|
210
210
|
desc 'update', 'update event handler configuration'
|
211
211
|
option :handler_id, type: :string, required:true, desc: 'Event Handler ID'
|
212
212
|
option :req, type: :string, desc: 'JSON string of event handler configuration'
|
@@ -215,7 +215,7 @@ module SoracomCli
|
|
215
215
|
puts JSON.pretty_generate(client.update_event_handler(options.handler_id, options.req))
|
216
216
|
end
|
217
217
|
end
|
218
|
-
|
218
|
+
|
219
219
|
# Stats related commands
|
220
220
|
class Stats < Thor
|
221
221
|
desc 'get_air_usage', 'get air usage per Subscriber(SIM)'
|
@@ -228,7 +228,7 @@ module SoracomCli
|
|
228
228
|
data = client.get_air_usage(Hash[options.map { |k, v| [k.to_sym, v] }])
|
229
229
|
puts JSON.pretty_generate(data)
|
230
230
|
end
|
231
|
-
|
231
|
+
|
232
232
|
desc 'get_beam_usage', 'get beam usage per Subscriber(SIM)'
|
233
233
|
option :imsi, type: :string, required: true, desc: '15 digits SIM unique ID'
|
234
234
|
option :from, type: :numeric, required: false, desc: 'UNIX time in seconds when stat window begins'
|
@@ -239,7 +239,7 @@ module SoracomCli
|
|
239
239
|
data = client.get_beam_usage(Hash[options.map { |k, v| [k.to_sym, v] }])
|
240
240
|
puts JSON.pretty_generate(data)
|
241
241
|
end
|
242
|
-
|
242
|
+
|
243
243
|
desc 'export_air_usage', 'export air usage for all Subscriber(SIM)s in csv format'
|
244
244
|
option :from, type: :numeric, required: false, desc: 'UNIX time in seconds when stat window begins'
|
245
245
|
option :to, type: :numeric, required: false, desc: 'UNIX time in seconds when stat window ends'
|
@@ -249,7 +249,7 @@ module SoracomCli
|
|
249
249
|
csv = client.export_air_usage(Hash[options.map { |k, v| [k.to_sym, v] }])
|
250
250
|
puts csv
|
251
251
|
end
|
252
|
-
|
252
|
+
|
253
253
|
desc 'export_beam_usage', 'export beam usage for all Subscriber(SIM)s in csv format'
|
254
254
|
option :from, type: :numeric, required: false, desc: 'UNIX time in seconds when stat window begins'
|
255
255
|
option :to, type: :numeric, required: false, desc: 'UNIX time in seconds when stat window ends'
|
@@ -261,6 +261,30 @@ module SoracomCli
|
|
261
261
|
end
|
262
262
|
end
|
263
263
|
|
264
|
+
class Operator < Thor
|
265
|
+
desc 'create_auth_key', 'list auth keys'
|
266
|
+
def list_auth_keys
|
267
|
+
client = Soracom::Client.new
|
268
|
+
data = client.list_auth_keys()
|
269
|
+
puts JSON.pretty_generate(data)
|
270
|
+
end
|
271
|
+
|
272
|
+
desc 'create_auth_key', 'create new auth key'
|
273
|
+
def create_auth_key
|
274
|
+
client = Soracom::Client.new
|
275
|
+
data = client.create_auth_key()
|
276
|
+
puts JSON.pretty_generate(data)
|
277
|
+
end
|
278
|
+
|
279
|
+
desc 'delete_auth_key', 'delete existing auth key'
|
280
|
+
option :auth_key_id, type: :string, required: true, desc: 'auth key id starting "keyId-"'
|
281
|
+
def delete_auth_key
|
282
|
+
client = Soracom::Client.new
|
283
|
+
data = client.delete_auth_key(options.auth_key_id)
|
284
|
+
puts JSON.pretty_generate(data)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
264
288
|
# Using Thor for CLI Implementation
|
265
289
|
class CLI < Thor
|
266
290
|
register(Subscriber, 'subscriber', 'subscriber <command>', 'Subscriber related operations')
|
@@ -268,6 +292,7 @@ module SoracomCli
|
|
268
292
|
register(Group, 'group', 'group <command>', 'Group related operations')
|
269
293
|
register(EventHandler, 'event_handler', 'event_handler <command>', 'Event Handler related operations')
|
270
294
|
register(Stats, 'stats', 'stats <command>', 'Stats related operations')
|
295
|
+
register(Operator, 'operator', 'operator <command>', 'Operator related operations')
|
271
296
|
|
272
297
|
desc 'auth', 'test authentication'
|
273
298
|
def auth
|
data/lib/soracom/client.rb
CHANGED
@@ -12,14 +12,20 @@ module Soracom
|
|
12
12
|
# Soracom API Client
|
13
13
|
class Client
|
14
14
|
# 設定されなかった場合には、環境変数から認証情報を取得
|
15
|
-
def initialize(
|
15
|
+
def initialize(
|
16
|
+
endpoint:ENV['SORACOM_ENDPOINT'],
|
17
|
+
email:ENV['SORACOM_EMAIL'], password:ENV['SORACOM_PASSWORD'],
|
18
|
+
auth_key_id:ENV['SORACOM_AUTH_KEY_ID'], auth_key:ENV['SORACOM_AUTH_KEY']
|
19
|
+
)
|
16
20
|
@log = Logger.new(STDERR)
|
17
21
|
@log.level = ENV['SORACOM_DEBUG'] ? Logger::DEBUG : Logger::WARN
|
18
22
|
begin
|
19
|
-
if
|
23
|
+
if auth_key_id && auth_key
|
24
|
+
@auth = auth_by_key(auth_key_id, auth_key, endpoint)
|
25
|
+
elsif email && password
|
20
26
|
@auth = auth(email, password, endpoint)
|
21
27
|
else
|
22
|
-
fail 'Could not find any credentials(email & password)'
|
28
|
+
fail 'Could not find any credentials(authKeyId & authKey or email & password)'
|
23
29
|
end
|
24
30
|
rescue => evar
|
25
31
|
abort 'ERROR: ' + evar.to_s
|
@@ -306,6 +312,18 @@ module Soracom
|
|
306
312
|
"https://soracom.zendesk.com/access/jwt?jwt=#{res['token']}&return_to=#{return_to}"
|
307
313
|
end
|
308
314
|
|
315
|
+
def list_auth_keys()
|
316
|
+
@api.get(path: "/operators/#{@auth[:operatorId]}/auth_keys")
|
317
|
+
end
|
318
|
+
|
319
|
+
def create_auth_key()
|
320
|
+
@api.post(path: "/operators/#{@auth[:operatorId]}/auth_keys")
|
321
|
+
end
|
322
|
+
|
323
|
+
def delete_auth_key(auth_key_id)
|
324
|
+
@api.delete(path: "/operators/#{@auth[:operatorId]}/auth_keys/#{auth_key_id}")
|
325
|
+
end
|
326
|
+
|
309
327
|
# APIキーを取得
|
310
328
|
def api_key
|
311
329
|
@auth[:apiKey]
|
@@ -335,6 +353,18 @@ module Soracom
|
|
335
353
|
Hash[JSON.parse(res.body).map { |k, v| [k.to_sym, v] }]
|
336
354
|
end
|
337
355
|
|
356
|
+
# authenticate by email and password
|
357
|
+
def auth_by_key(auth_key_id, auth_key, endpoint)
|
358
|
+
endpoint = API_BASE_URL if endpoint.nil?
|
359
|
+
res = RestClient.post endpoint + '/auth',
|
360
|
+
{ authKeyId: auth_key_id, authKey: auth_key },
|
361
|
+
'Content-Type' => 'application/json',
|
362
|
+
'Accept' => 'application/json'
|
363
|
+
result = JSON.parse(res.body)
|
364
|
+
fail result['message'] if res.code != '200'
|
365
|
+
Hash[JSON.parse(res.body).map { |k, v| [k.to_sym, v] }]
|
366
|
+
end
|
367
|
+
|
338
368
|
def extract_jwt(jwt)
|
339
369
|
encoded = jwt.split('.')[1]
|
340
370
|
encoded += '=' * (4 - encoded.length % 4) # add padding(=) for Base64
|
data/lib/soracom/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soracom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MATSUI, Motokatsu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
145
|
version: '0'
|
146
146
|
requirements: []
|
147
147
|
rubyforge_project:
|
148
|
-
rubygems_version: 2.0.14
|
148
|
+
rubygems_version: 2.0.14.1
|
149
149
|
signing_key:
|
150
150
|
specification_version: 4
|
151
151
|
summary: SORACOM API Client library and tool
|