vers-sdk 0.1.7 → 0.1.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c951cf2151004223920df0bb138293192188e8d1c0f9745bf784bbe89aa58162
4
- data.tar.gz: cbbdf495be7bc1d4600eea1a9166987ca74ea4c5185a0d542e1abecf1c264e62
3
+ metadata.gz: 7a2dcc5a41778ee85766e42933c29a3bef0836381b8f73b1130048602896ae9e
4
+ data.tar.gz: d2f1183f925fc04050b43a7ee96daa602d55016a7789184b27cb965ceb7a869f
5
5
  SHA512:
6
- metadata.gz: 179a482d53ff0bce6c840820c12238e35976d279d0d6cc905535587269569a10f06cdd01c64b4a522f2ef3582b1158b512f9339fc636d97bbfc24ffa5c50c51b
7
- data.tar.gz: cbf6c8f749280c44a0fb07f1f39617a5b8cf9aabf02d989ed512b5d7a19362de30a1e23aa0cf518a334683b9ef76d65fe7325ad4aab33b572fcab7140b3791a4
6
+ metadata.gz: 14dea0ed131c7929f2e04b24794bfaef9fb717df211c47318db89e3bf6fc7983e8ea8c8ea580cf802dc8f7744418059b56b82d7f0dadcdce151fc1c96142adde
7
+ data.tar.gz: 966a0221d365dba8e402d0bced5a6ef9e8206fe5751ccee46ac62eb14b088fc0fb62228403cb675855e6c057f775bf24125aa6b94c385722f740dd18e8b562cd
@@ -51,7 +51,7 @@ module VersSdk
51
51
  @default_headers = {
52
52
  "Content-Type" => "application/json",
53
53
  "Accept" => "application/json",
54
- "User-Agent" => "vers-sdk/0.1.7 ruby/#{RUBY_VERSION} #{RUBY_PLATFORM}"
54
+ "User-Agent" => "vers-sdk/0.1.9 ruby/#{RUBY_VERSION} #{RUBY_PLATFORM}"
55
55
  }
56
56
  @default_headers["Authorization"] = "Bearer #{@api_key}" if @api_key
57
57
  end
@@ -67,8 +67,37 @@ module VersSdk
67
67
  end
68
68
 
69
69
  #
70
- def resize_vm_disk(vm_id, body: nil, params: nil, options: nil)
71
- path = sprintf("/api/v1/vm/%s/disk", vm_id)
70
+ def vm_logs(vm_id, params: nil, options: nil)
71
+ path = sprintf("/api/v1/vm/%s/logs", vm_id)
72
+ query = {}
73
+ if params
74
+ h = params.is_a?(Hash) ? params : params.to_h
75
+ h.each { |k, v| query[k.to_s] = v.to_s unless v.nil? }
76
+ end
77
+ request("GET", path, options: options, query: query)
78
+ end
79
+
80
+ # Upsert (additive) labels on a VM.
81
+ def upsert_vm_labels(vm_id, body: nil, options: nil)
82
+ path = sprintf("/api/v1/vm/%s/label", vm_id)
83
+ request("PATCH", path, options: options, body: body)
84
+ end
85
+
86
+ #
87
+ def list_public_repo_tags(org_name, repo_name, options: nil)
88
+ path = sprintf("/api/v1/public/repositories/%s/%s/tags", org_name, repo_name)
89
+ request("GET", path, options: options)
90
+ end
91
+
92
+ #
93
+ def list_parent_commits(commit_id, options: nil)
94
+ path = sprintf("/api/v1/vm/commits/%s/parents", commit_id)
95
+ request("GET", path, options: options)
96
+ end
97
+
98
+ #
99
+ def update_vm_state(vm_id, body: nil, params: nil, options: nil)
100
+ path = sprintf("/api/v1/vm/%s/state", vm_id)
72
101
  query = {}
73
102
  if params
74
103
  h = params.is_a?(Hash) ? params : params.to_h
@@ -78,31 +107,132 @@ module VersSdk
78
107
  end
79
108
 
80
109
  #
81
- def exec_vm_stream_attach(vm_id, body: nil, options: nil)
82
- path = sprintf("/api/v1/vm/%s/exec/stream/attach", vm_id)
110
+ def list_repositories(options: nil)
111
+ path = "/api/v1/repositories"
112
+ request("GET", path, options: options)
113
+ end
114
+
115
+ #
116
+ def create_repository(body: nil, options: nil)
117
+ path = "/api/v1/repositories"
83
118
  request("POST", path, options: options, body: body)
84
119
  end
85
120
 
86
121
  #
87
- def create_new_root_vm(body: nil, params: nil, options: nil)
88
- path = "/api/v1/vm/new_root"
122
+ def get_public_repo_tag(org_name, repo_name, tag_name, options: nil)
123
+ path = sprintf("/api/v1/public/repositories/%s/%s/tags/%s", org_name, repo_name, tag_name)
124
+ request("GET", path, options: options)
125
+ end
126
+
127
+ #
128
+ def list_tags(options: nil)
129
+ path = "/api/v1/commit_tags"
130
+ request("GET", path, options: options)
131
+ end
132
+
133
+ #
134
+ def create_tag(body: nil, options: nil)
135
+ path = "/api/v1/commit_tags"
136
+ request("POST", path, options: options, body: body)
137
+ end
138
+
139
+ #
140
+ def list_vms(options: nil)
141
+ path = "/api/v1/vm"
142
+ request("GET", path, options: options)
143
+ end
144
+
145
+ #
146
+ def get_vm_metadata(vm_id, options: nil)
147
+ path = sprintf("/api/v1/vm/%s/metadata", vm_id)
148
+ request("GET", path, options: options)
149
+ end
150
+
151
+ #
152
+ def list_commits(options: nil)
153
+ path = "/api/v1/commits"
154
+ request("GET", path, options: options)
155
+ end
156
+
157
+ #
158
+ def list_repo_tags(repo_name, options: nil)
159
+ path = sprintf("/api/v1/repositories/%s/tags", repo_name)
160
+ request("GET", path, options: options)
161
+ end
162
+
163
+ #
164
+ def create_repo_tag(repo_name, body: nil, options: nil)
165
+ path = sprintf("/api/v1/repositories/%s/tags", repo_name)
166
+ request("POST", path, options: options, body: body)
167
+ end
168
+
169
+ #
170
+ def exec_vm(vm_id, body: nil, options: nil)
171
+ path = sprintf("/api/v1/vm/%s/exec", vm_id)
172
+ request("POST", path, options: options, body: body)
173
+ end
174
+
175
+ #
176
+ def set_repository_visibility(repo_name, body: nil, options: nil)
177
+ path = sprintf("/api/v1/repositories/%s/visibility", repo_name)
178
+ request("PATCH", path, options: options, body: body)
179
+ end
180
+
181
+ #
182
+ def list_images(options: nil)
183
+ path = "/api/v1/images"
184
+ request("GET", path, options: options)
185
+ end
186
+
187
+ #
188
+ def read_file_vm(vm_id, params: nil, options: nil)
189
+ path = sprintf("/api/v1/vm/%s/files", vm_id)
89
190
  query = {}
90
191
  if params
91
192
  h = params.is_a?(Hash) ? params : params.to_h
92
193
  h.each { |k, v| query[k.to_s] = v.to_s unless v.nil? }
93
194
  end
94
- request("POST", path, options: options, body: body, query: query)
195
+ request("GET", path, options: options, query: query)
95
196
  end
96
197
 
97
198
  #
98
- def vm_logs(vm_id, params: nil, options: nil)
99
- path = sprintf("/api/v1/vm/%s/logs", vm_id)
199
+ def write_file_vm(vm_id, body: nil, options: nil)
200
+ path = sprintf("/api/v1/vm/%s/files", vm_id)
201
+ request("PUT", path, options: options, body: body)
202
+ end
203
+
204
+ #
205
+ def get_public_repository(org_name, repo_name, options: nil)
206
+ path = sprintf("/api/v1/public/repositories/%s/%s", org_name, repo_name)
207
+ request("GET", path, options: options)
208
+ end
209
+
210
+ #
211
+ def resize_vm_disk(vm_id, body: nil, params: nil, options: nil)
212
+ path = sprintf("/api/v1/vm/%s/disk", vm_id)
100
213
  query = {}
101
214
  if params
102
215
  h = params.is_a?(Hash) ? params : params.to_h
103
216
  h.each { |k, v| query[k.to_s] = v.to_s unless v.nil? }
104
217
  end
105
- request("GET", path, options: options, query: query)
218
+ request("PATCH", path, options: options, body: body, query: query)
219
+ end
220
+
221
+ #
222
+ def exec_vm_stream_attach(vm_id, body: nil, options: nil)
223
+ path = sprintf("/api/v1/vm/%s/exec/stream/attach", vm_id)
224
+ request("POST", path, options: options, body: body)
225
+ end
226
+
227
+ #
228
+ def create_new_root_vm(body: nil, params: nil, options: nil)
229
+ path = "/api/v1/vm/new_root"
230
+ query = {}
231
+ if params
232
+ h = params.is_a?(Hash) ? params : params.to_h
233
+ h.each { |k, v| query[k.to_s] = v.to_s unless v.nil? }
234
+ end
235
+ request("POST", path, options: options, body: body, query: query)
106
236
  end
107
237
 
108
238
  #
@@ -116,6 +246,12 @@ module VersSdk
116
246
  request("POST", path, options: options, body: body, query: query)
117
247
  end
118
248
 
249
+ # Replace **all** labels on a VM with the provided map.
250
+ def replace_vm_labels(vm_id, body: nil, options: nil)
251
+ path = sprintf("/api/v1/vm/%s/labels", vm_id)
252
+ request("PUT", path, options: options, body: body)
253
+ end
254
+
119
255
  #
120
256
  def list_public_commits(options: nil)
121
257
  path = "/api/v1/commits/public"
@@ -123,25 +259,20 @@ module VersSdk
123
259
  end
124
260
 
125
261
  #
126
- def list_public_repo_tags(org_name, repo_name, options: nil)
127
- path = sprintf("/api/v1/public/repositories/%s/%s/tags", org_name, repo_name)
262
+ def get_image_status(image_name, options: nil)
263
+ path = sprintf("/api/v1/images/%s/status", image_name)
128
264
  request("GET", path, options: options)
129
265
  end
130
266
 
131
267
  #
132
- def branch_by_tag(tag_name, body: nil, params: nil, options: nil)
133
- path = sprintf("/api/v1/vm/branch/by_tag/%s", tag_name)
134
- query = {}
135
- if params
136
- h = params.is_a?(Hash) ? params : params.to_h
137
- h.each { |k, v| query[k.to_s] = v.to_s unless v.nil? }
138
- end
139
- request("POST", path, options: options, body: body, query: query)
268
+ def version_handler(options: nil)
269
+ path = "/api/v1/system/version"
270
+ request("GET", path, options: options)
140
271
  end
141
272
 
142
273
  #
143
- def branch_vm(vm_or_commit_id, body: nil, params: nil, options: nil)
144
- path = sprintf("/api/v1/vm/%s/branch", vm_or_commit_id)
274
+ def branch_by_tag(tag_name, body: nil, params: nil, options: nil)
275
+ path = sprintf("/api/v1/vm/branch/by_tag/%s", tag_name)
145
276
  query = {}
146
277
  if params
147
278
  h = params.is_a?(Hash) ? params : params.to_h
@@ -168,6 +299,17 @@ module VersSdk
168
299
  request("PATCH", path, options: options, body: body)
169
300
  end
170
301
 
302
+ #
303
+ def branch_vm(vm_or_commit_id, body: nil, params: nil, options: nil)
304
+ path = sprintf("/api/v1/vm/%s/branch", vm_or_commit_id)
305
+ query = {}
306
+ if params
307
+ h = params.is_a?(Hash) ? params : params.to_h
308
+ h.each { |k, v| query[k.to_s] = v.to_s unless v.nil? }
309
+ end
310
+ request("POST", path, options: options, body: body, query: query)
311
+ end
312
+
171
313
  #
172
314
  def get_repository(repo_name, options: nil)
173
315
  path = sprintf("/api/v1/repositories/%s", repo_name)
@@ -181,20 +323,9 @@ module VersSdk
181
323
  end
182
324
 
183
325
  #
184
- def list_parent_commits(commit_id, options: nil)
185
- path = sprintf("/api/v1/vm/commits/%s/parents", commit_id)
186
- request("GET", path, options: options)
187
- end
188
-
189
- #
190
- def update_vm_state(vm_id, body: nil, params: nil, options: nil)
191
- path = sprintf("/api/v1/vm/%s/state", vm_id)
192
- query = {}
193
- if params
194
- h = params.is_a?(Hash) ? params : params.to_h
195
- h.each { |k, v| query[k.to_s] = v.to_s unless v.nil? }
196
- end
197
- request("PATCH", path, options: options, body: body, query: query)
326
+ def validate_key(body: nil, options: nil)
327
+ path = "/api/v1/keys/validate"
328
+ request("POST", path, options: options, body: body)
198
329
  end
199
330
 
200
331
  #
@@ -203,15 +334,15 @@ module VersSdk
203
334
  request("POST", path, options: options, body: body)
204
335
  end
205
336
 
206
- #
207
- def list_repositories(options: nil)
208
- path = "/api/v1/repositories"
209
- request("GET", path, options: options)
337
+ # Delete a single label from a VM by name.
338
+ def delete_vm_label(vm_id, label_name, options: nil)
339
+ path = sprintf("/api/v1/vm/%s/label/%s", vm_id, label_name)
340
+ request("DELETE", path, options: options)
210
341
  end
211
342
 
212
343
  #
213
- def create_repository(body: nil, options: nil)
214
- path = "/api/v1/repositories"
344
+ def create_image(body: nil, options: nil)
345
+ path = "/api/v1/images/create"
215
346
  request("POST", path, options: options, body: body)
216
347
  end
217
348
 
@@ -233,36 +364,12 @@ module VersSdk
233
364
  request("DELETE", path, options: options)
234
365
  end
235
366
 
236
- #
237
- def list_tags(options: nil)
238
- path = "/api/v1/commit_tags"
239
- request("GET", path, options: options)
240
- end
241
-
242
- #
243
- def create_tag(body: nil, options: nil)
244
- path = "/api/v1/commit_tags"
245
- request("POST", path, options: options, body: body)
246
- end
247
-
248
367
  #
249
368
  def list_public_repositories(options: nil)
250
369
  path = "/api/v1/public/repositories"
251
370
  request("GET", path, options: options)
252
371
  end
253
372
 
254
- #
255
- def get_public_repo_tag(org_name, repo_name, tag_name, options: nil)
256
- path = sprintf("/api/v1/public/repositories/%s/%s/tags/%s", org_name, repo_name, tag_name)
257
- request("GET", path, options: options)
258
- end
259
-
260
- #
261
- def get_vm_metadata(vm_id, options: nil)
262
- path = sprintf("/api/v1/vm/%s/metadata", vm_id)
263
- request("GET", path, options: options)
264
- end
265
-
266
373
  #
267
374
  def list_env_vars(options: nil)
268
375
  path = "/api/v1/env_vars"
@@ -286,12 +393,6 @@ module VersSdk
286
393
  request("DELETE", path, options: options, query: query)
287
394
  end
288
395
 
289
- #
290
- def list_commits(options: nil)
291
- path = "/api/v1/commits"
292
- request("GET", path, options: options)
293
- end
294
-
295
396
  #
296
397
  def get_tag(tag_name, options: nil)
297
398
  path = sprintf("/api/v1/commit_tags/%s", tag_name)
@@ -328,9 +429,9 @@ module VersSdk
328
429
  end
329
430
 
330
431
  #
331
- def exec_vm_stream(vm_id, body: nil, options: nil)
332
- path = sprintf("/api/v1/vm/%s/exec/stream", vm_id)
333
- request("POST", path, options: options, body: body)
432
+ def delete_image(base_image_id, options: nil)
433
+ path = sprintf("/api/v1/images/images/%s", base_image_id)
434
+ request("DELETE", path, options: options)
334
435
  end
335
436
 
336
437
  #
@@ -357,14 +458,14 @@ module VersSdk
357
458
  end
358
459
 
359
460
  #
360
- def list_repo_tags(repo_name, options: nil)
361
- path = sprintf("/api/v1/repositories/%s/tags", repo_name)
362
- request("GET", path, options: options)
461
+ def exec_vm_stream(vm_id, body: nil, options: nil)
462
+ path = sprintf("/api/v1/vm/%s/exec/stream", vm_id)
463
+ request("POST", path, options: options, body: body)
363
464
  end
364
465
 
365
- #
366
- def create_repo_tag(repo_name, body: nil, options: nil)
367
- path = sprintf("/api/v1/repositories/%s/tags", repo_name)
466
+ # Deploy a GitHub repository to a new Vers project.
467
+ def deploy_handler(body: nil, options: nil)
468
+ path = "/api/v1/deploy"
368
469
  request("POST", path, options: options, body: body)
369
470
  end
370
471
 
@@ -375,20 +476,8 @@ module VersSdk
375
476
  end
376
477
 
377
478
  #
378
- def exec_vm(vm_id, body: nil, options: nil)
379
- path = sprintf("/api/v1/vm/%s/exec", vm_id)
380
- request("POST", path, options: options, body: body)
381
- end
382
-
383
- #
384
- def set_repository_visibility(repo_name, body: nil, options: nil)
385
- path = sprintf("/api/v1/repositories/%s/visibility", repo_name)
386
- request("PATCH", path, options: options, body: body)
387
- end
388
-
389
- #
390
- def list_vms(options: nil)
391
- path = "/api/v1/vms"
479
+ def vm_status(vm_id, options: nil)
480
+ path = sprintf("/api/v1/vm/%s/status", vm_id)
392
481
  request("GET", path, options: options)
393
482
  end
394
483
 
@@ -410,15 +499,15 @@ module VersSdk
410
499
  end
411
500
 
412
501
  #
413
- def vm_status(vm_id, options: nil)
414
- path = sprintf("/api/v1/vm/%s/status", vm_id)
502
+ def whoami_handler(options: nil)
503
+ path = "/api/v1/whoami"
415
504
  request("GET", path, options: options)
416
505
  end
417
506
 
418
507
  #
419
- def get_public_repository(org_name, repo_name, options: nil)
420
- path = sprintf("/api/v1/public/repositories/%s/%s", org_name, repo_name)
421
- request("GET", path, options: options)
508
+ def upload_image(body: nil, options: nil)
509
+ path = "/api/v1/images/upload"
510
+ request("POST", path, options: options, body: body)
422
511
  end
423
512
 
424
513
  #
@@ -467,7 +556,7 @@ module VersSdk
467
556
  end
468
557
 
469
558
  check_response(response)
470
- return response
559
+ return JSON.parse(response.body) rescue response.body
471
560
  rescue APIError
472
561
  raise
473
562
  rescue Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT,
@@ -551,9 +640,14 @@ module VersSdk
551
640
 
552
641
  body = nil
553
642
  message = nil
554
- begin
555
- body = JSON.parse(response.body)
556
- rescue StandardError
643
+ ct = response["content-type"] || ""
644
+ if ct.include?("application/json")
645
+ begin
646
+ body = JSON.parse(response.body)
647
+ rescue StandardError
648
+ message = response.body
649
+ end
650
+ else
557
651
  message = response.body
558
652
  end
559
653
 
@@ -18,6 +18,17 @@ module VersSdk
18
18
  super(make_message(status, body, message))
19
19
  end
20
20
 
21
+ # Extract the human-readable error message from the response body.
22
+ # Looks for an "error" or "message" field in the JSON body,
23
+ # or falls back to the raw message.
24
+ def error_message
25
+ if body.is_a?(Hash)
26
+ return body["error"] if body["error"].is_a?(String)
27
+ return body["message"] if body["message"].is_a?(String)
28
+ end
29
+ message
30
+ end
31
+
21
32
  def self.generate(status:, body: nil, message: nil, headers: nil)
22
33
  return APIConnectionError.new(message: message) if status.nil? || headers.nil?
23
34