duracloud-client 0.9.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/Gemfile +1 -2
- data/README.md +39 -49
- data/duracloud.gemspec +0 -1
- data/lib/duracloud.rb +34 -8
- data/lib/duracloud/abstract_entity.rb +11 -22
- data/lib/duracloud/cli.rb +35 -40
- data/lib/duracloud/client.rb +6 -35
- data/lib/duracloud/command_options.rb +11 -2
- data/lib/duracloud/commands.rb +4 -0
- data/lib/duracloud/commands/store_content.rb +13 -0
- data/lib/duracloud/content.rb +20 -7
- data/lib/duracloud/content_manifest.rb +5 -6
- data/lib/duracloud/request.rb +30 -14
- data/lib/duracloud/response.rb +2 -3
- data/lib/duracloud/response_handler.rb +63 -0
- data/lib/duracloud/rest_methods.rb +3 -2
- data/lib/duracloud/space.rb +8 -9
- data/lib/duracloud/storage_report.rb +1 -6
- data/lib/duracloud/sync_validation.rb +6 -4
- data/lib/duracloud/version.rb +1 -1
- data/spec/spec_helper.rb +4 -6
- data/spec/unit/cli_spec.rb +28 -14
- data/spec/unit/content_spec.rb +1 -2
- metadata +4 -28
- data/gemfiles/Gemfile.activemodel-4.2 +0 -3
- data/gemfiles/Gemfile.activemodel-5.0 +0 -3
- data/lib/duracloud/configuration.rb +0 -42
- data/lib/duracloud/connection.rb +0 -18
- data/lib/duracloud/durastore_request.rb +0 -7
- data/lib/duracloud/error_handler.rb +0 -56
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab3c4183dff4f6bcd2b40da7e2601cf0822407d0
|
4
|
+
data.tar.gz: 426c246ed3d48bbac47dc17972157147cd9dcf56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99041da397ad7d9cef8ff49cc0cf352bf254db576cc068e270133e0f3e247a38f954c3de7c1a8e5d636e3f3e508a5fcc1d7aa118fbeaeb97038ec06e7e72ca59
|
7
|
+
data.tar.gz: 5f377cbe3a4940613310bad558bf8761bcbcfbd4fee5352ab3a5ac41a08368ef28e0715d0ed219cd0b54441243bc19af4ddb894432ca9ec99a82fa6250e1fba2
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -31,36 +31,21 @@ Option 1. Environment variables
|
|
31
31
|
|
32
32
|
Option 2. Manual configuration
|
33
33
|
|
34
|
-
|
35
|
-
Duracloud::Client.configure do |config|
|
36
|
-
config.host = "foo.duracloud.org"
|
37
|
-
config.user = "bob@example.com"
|
38
|
-
config.password = "s3cret"
|
39
|
-
end
|
40
|
-
```
|
34
|
+
*Changed in v0.10.0* Set attributes on `Duracloud` module instead of using `Duracloud::Client.configure {|config| ...}` block.
|
41
35
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
```
|
36
|
+
Duracloud.host = "foo.duracloud.org"
|
37
|
+
Duracloud.user = "bob@example.com"
|
38
|
+
Duracloud.password = "s3cret"
|
46
39
|
|
47
40
|
#### Logging
|
48
41
|
|
49
|
-
By default
|
42
|
+
By default duracloud-client logs to `STDERR`. Use the `logger` config setting to change:
|
50
43
|
|
51
|
-
|
52
|
-
Duracloud::Client.configure do |config|
|
53
|
-
config.logger = Rails.logger
|
54
|
-
end
|
55
|
-
```
|
44
|
+
Duracloud.logger = Rails.logger
|
56
45
|
|
57
46
|
You can also silence logging:
|
58
47
|
|
59
|
-
|
60
|
-
Duracloud::Client.configure do |config|
|
61
|
-
config.silence_logging! # sets logger device to null device
|
62
|
-
end
|
63
|
-
```
|
48
|
+
Duracloud.silence_logging! # sets logger device to null device
|
64
49
|
|
65
50
|
### List Storage Providers
|
66
51
|
|
@@ -81,7 +66,7 @@ end
|
|
81
66
|
|
82
67
|
```
|
83
68
|
>> space = Duracloud::Space.create("rest-api-testing2")
|
84
|
-
D, [2016-04-29T12:12:32.641574 #28275] DEBUG -- : Duracloud::
|
69
|
+
D, [2016-04-29T12:12:32.641574 #28275] DEBUG -- : Duracloud::Request PUT https://foo.duracloud.org/durastore/rest-api-testing2 201 Created
|
85
70
|
=> #<Duracloud::Space space_id="rest-api-testing2", store_id="(default)">
|
86
71
|
```
|
87
72
|
|
@@ -91,7 +76,7 @@ A `Duracloud::BadRequestError` exception is raised if the space ID is invalid (i
|
|
91
76
|
|
92
77
|
```
|
93
78
|
>> space = Duracloud::Space.find("rest-api-testing")
|
94
|
-
D, [2016-04-29T12:15:12.593075 #28275] DEBUG -- : Duracloud::
|
79
|
+
D, [2016-04-29T12:15:12.593075 #28275] DEBUG -- : Duracloud::Request HEAD https://foo.duracloud.org/durastore/rest-api-testing 200 OK
|
95
80
|
=> #<Duracloud::Space space_id="rest-api-testing", store_id="(default)">
|
96
81
|
|
97
82
|
>> space.count
|
@@ -103,11 +88,11 @@ D, [2016-04-29T12:15:12.593075 #28275] DEBUG -- : Duracloud::Client HEAD https:/
|
|
103
88
|
|
104
89
|
A `Duracloud::NotFoundError` exception is raised if the space does not exist.
|
105
90
|
|
106
|
-
|
91
|
+
**Note:** When the object count in a space exceeds 1000, Duracloud returns `1000+` as the count. Ruby's integer coercion `to_i`
|
107
92
|
turns that string into the integer 1000. Getting an exact count above 1000 requires (on the client side) enumerating the content_ids
|
108
|
-
(below, fixed in v0.7.2 when count is >= 1000) which can take a long time for a space with a lot of content items
|
109
|
-
|
110
|
-
count is not required, the storage report for the space
|
93
|
+
(below, fixed in v0.7.2 when count is >= 1000) which can take a long time for a space with a lot of content items
|
94
|
+
(a maxiumum of 1000 ids can be retrived at one time). If an up-to-the-minute
|
95
|
+
count is not required, the storage report for the space shows an exact count on a daily basis.
|
111
96
|
|
112
97
|
#### Enumerate the content IDs of the space
|
113
98
|
|
@@ -152,10 +137,11 @@ Duracloud::SyncValidation.call(space_id: 'foo', content_dir: '/var/foo/bar')
|
|
152
137
|
create a temporary directory which is deleted on completion of the process. If `:work_dir` is specified, no cleanup is performed.
|
153
138
|
|
154
139
|
Files created in work directory:
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
140
|
+
|
141
|
+
{SPACE_ID}-manifest.tsv DuraCloud manifest as downloaded
|
142
|
+
{SPACE_ID}-md5.txt Munged manifest for md5deep
|
143
|
+
{SPACE_ID}-audit.txt Output of md5deep, empty if all files match
|
144
|
+
{SPACE_ID}-recheck.txt Output of audit recheck, if necessary
|
159
145
|
|
160
146
|
*Added in version 0.9.0* - `Duracloud::FastSyncValidation`. This variant of sync validation does not compute local hashes but instead compares the local file list (generated with `find`) to the list of content IDs in the space manifest. Local misses are rechecked as in `SyncValidation` (but without MD5 comparison).
|
161
147
|
|
@@ -181,6 +167,8 @@ When storing content a `Duracloud::NotFoundError` is raised if the space does no
|
|
181
167
|
A `Duracloud::BadRequestError` is raised if the content ID is invalid.
|
182
168
|
A `Duracloud::ConflictError` is raised if the provided MD5 digest does not match the stored digest.
|
183
169
|
|
170
|
+
**Note:** duracloud-client does not currently provide for chunking of large files as, for example, the DuraCloud Sync Tool does.
|
171
|
+
|
184
172
|
#### Retrieve an existing content item from DuraCloud
|
185
173
|
|
186
174
|
```
|
@@ -196,7 +184,7 @@ raised if the content ID exists and the stored digest does not match.
|
|
196
184
|
|
197
185
|
If a content item is not found at the content ID, `Duracloud::Content.find` will look for a "content manifest"
|
198
186
|
by appending ".dura-manifest" to the content ID. If the manifest is found, the content item is marked as
|
199
|
-
"chunked". **Caution: Working with chunked files should be considered EXPERIMENTAL.**
|
187
|
+
"chunked". **Caution: Working with chunked files should be considered EXPERIMENTAL and unsupported.**
|
200
188
|
|
201
189
|
#### Update the properties for a content item
|
202
190
|
|
@@ -205,7 +193,7 @@ by appending ".dura-manifest" to the content ID. If the manifest is found, the c
|
|
205
193
|
=> #<Duracloud::Space space_id="rest-api-testing", store_id="(default)">
|
206
194
|
|
207
195
|
>> content = space.find_content("foo3")
|
208
|
-
D, [2016-04-29T18:31:16.975749 #32379] DEBUG -- : Duracloud::
|
196
|
+
D, [2016-04-29T18:31:16.975749 #32379] DEBUG -- : Duracloud::Request HEAD https://foo.duracloud.org/durastore/rest-api-testing/foo3 200 OK
|
209
197
|
=> #<Duracloud::Content space_id="rest-api-testing", content_id="foo3", store_id=(default)>
|
210
198
|
|
211
199
|
>> content.properties
|
@@ -213,12 +201,12 @@ D, [2016-04-29T18:31:16.975749 #32379] DEBUG -- : Duracloud::Client HEAD https:/
|
|
213
201
|
|
214
202
|
>> content.properties["x-dura-meta-creator"] = "bob@example.com"
|
215
203
|
>> content.save
|
216
|
-
D, [2016-04-29T18:31:52.770195 #32379] DEBUG -- : Duracloud::
|
204
|
+
D, [2016-04-29T18:31:52.770195 #32379] DEBUG -- : Duracloud::Request POST https://foo.duracloud.org/durastore/rest-api-testing/foo3 200 OK
|
217
205
|
I, [2016-04-29T18:31:52.770293 #32379] INFO -- : Content foo3 updated successfully
|
218
206
|
=> true
|
219
207
|
|
220
208
|
>> content.properties["x-dura-meta-creator"]
|
221
|
-
D, [2016-04-29T18:32:06.465928 #32379] DEBUG -- : Duracloud::
|
209
|
+
D, [2016-04-29T18:32:06.465928 #32379] DEBUG -- : Duracloud::Request HEAD https://foo.duracloud.org/durastore/rest-api-testing/foo3 200 OK
|
222
210
|
=> "bob@example.com"
|
223
211
|
```
|
224
212
|
|
@@ -234,11 +222,11 @@ Also, `:space_id` and `:content_id` arguments are not required, but default to t
|
|
234
222
|
|
235
223
|
```
|
236
224
|
>> content = Duracloud::Content.find(space_id: 'rest-api-testing', content_id: 'contentItem.txt')
|
237
|
-
D, [2017-01-27T17:16:45.846459 #93283] DEBUG -- : Duracloud::
|
225
|
+
D, [2017-01-27T17:16:45.846459 #93283] DEBUG -- : Duracloud::Request HEAD https://duke.duracloud.org/durastore/rest-api-testing/contentItem.txt 200 OK
|
238
226
|
=> #<Duracloud::Content space_id="rest-api-testing", content_id="contentItem.txt", store_id=(default)>
|
239
227
|
|
240
228
|
>> content.copy(space_id: 'rest-api-testing2')
|
241
|
-
D, [2017-01-27T17:17:59.848741 #93283] DEBUG -- : Duracloud::
|
229
|
+
D, [2017-01-27T17:17:59.848741 #93283] DEBUG -- : Duracloud::Request PUT https://duke.duracloud.org/durastore/rest-api-testing2/contentItem.txt 201 Created
|
242
230
|
=> #<Duracloud::Content space_id="rest-api-testing2", content_id="contentItem.txt", store_id=(default)>
|
243
231
|
```
|
244
232
|
|
@@ -246,18 +234,18 @@ D, [2017-01-27T17:17:59.848741 #93283] DEBUG -- : Duracloud::Client PUT https://
|
|
246
234
|
|
247
235
|
*Added in v0.3.0; Changed in v0.4.0.*
|
248
236
|
|
249
|
-
See also *Copy a content item
|
237
|
+
See also *Copy a content item*, above.
|
250
238
|
|
251
239
|
```
|
252
240
|
This is a convenience operation -- copy and delete -- not directly supported by the DuraCloud REST API.
|
253
241
|
|
254
242
|
>> content = Duracloud::Content.find(space_id: 'rest-api-testing', content_id: 'contentItem.txt')
|
255
|
-
D, [2017-01-27T17:19:41.926994 #93286] DEBUG -- : Duracloud::
|
243
|
+
D, [2017-01-27T17:19:41.926994 #93286] DEBUG -- : Duracloud::Request HEAD https://duke.duracloud.org/durastore/rest-api-testing/contentItem.txt 200 OK
|
256
244
|
=> #<Duracloud::Content space_id="rest-api-testing", content_id="contentItem.txt", store_id=(default)>
|
257
245
|
|
258
246
|
>> content.move(space_id: 'rest-api-testing2')
|
259
|
-
D, [2017-01-27T17:20:07.542468 #93286] DEBUG -- : Duracloud::
|
260
|
-
D, [2017-01-27T17:20:08.442504 #93286] DEBUG -- : Duracloud::
|
247
|
+
D, [2017-01-27T17:20:07.542468 #93286] DEBUG -- : Duracloud::Request PUT https://duke.duracloud.org/durastore/rest-api-testing2/contentItem.txt 201 Created
|
248
|
+
D, [2017-01-27T17:20:08.442504 #93286] DEBUG -- : Duracloud::Request DELETE https://duke.duracloud.org/durastore/rest-api-testing/contentItem.txt 200 OK
|
261
249
|
=> #<Duracloud::Content space_id="rest-api-testing2", content_id="contentItem.txt", store_id=(default)>
|
262
250
|
|
263
251
|
>> content.deleted?
|
@@ -274,15 +262,17 @@ D, [2017-01-27T17:20:08.442504 #93286] DEBUG -- : Duracloud::Client DELETE https
|
|
274
262
|
=> #<Duracloud::Content space_id="rest-api-testing", content_id="foo2", store_id=(default)>
|
275
263
|
|
276
264
|
>> content.delete
|
277
|
-
D, [2016-04-29T18:28:31.459962 #32379] DEBUG -- : Duracloud::
|
265
|
+
D, [2016-04-29T18:28:31.459962 #32379] DEBUG -- : Duracloud::Request DELETE https://foo.duracloud.org/durastore/rest-api-testing/foo2 200 OK
|
278
266
|
I, [2016-04-29T18:28:31.460069 #32379] INFO -- : Content foo2 deleted successfully
|
279
267
|
=> #<Duracloud::Content space_id="rest-api-testing", content_id="foo2", store_id=(default)>
|
280
268
|
|
281
269
|
>> Duracloud::Content.exist?(space_id: "rest-api-testing", content_id: "foo2")
|
282
|
-
D, [2016-04-29T18:29:03.935451 #32379] DEBUG -- : Duracloud::
|
270
|
+
D, [2016-04-29T18:29:03.935451 #32379] DEBUG -- : Duracloud::Request HEAD https://foo.duracloud.org/durastore/rest-api-testing/foo2 404 Not Found
|
283
271
|
=> false
|
284
272
|
```
|
285
273
|
|
274
|
+
*Added in v0.10.0.pre* `Duracloud::Content.delete` class method.
|
275
|
+
|
286
276
|
### Reports
|
287
277
|
|
288
278
|
The audit logs, bit integrity reports and manifests are accessible in their original TSV format and in normalized CSV tables.
|
@@ -295,7 +285,7 @@ The audit logs, bit integrity reports and manifests are accessible in their orig
|
|
295
285
|
=> #<Duracloud::AuditLog:0x007fd44c077f38 @space_id="rest-api-testing", @store_id=nil, @response=nil>
|
296
286
|
|
297
287
|
>> audit_log.csv
|
298
|
-
D, [2016-05-19T13:36:49.107520 #28754] DEBUG -- : Duracloud::
|
288
|
+
D, [2016-05-19T13:36:49.107520 #28754] DEBUG -- : Duracloud::Request GET https://duke.duracloud.org/durastore/audit/rest-api-testing 200 OK
|
299
289
|
=> #<CSV::Table mode:col_or_row row_count:168>
|
300
290
|
```
|
301
291
|
|
@@ -307,20 +297,20 @@ D, [2016-05-19T13:36:49.107520 #28754] DEBUG -- : Duracloud::Client GET https://
|
|
307
297
|
=> #<Duracloud::Manifest:0x007fd44d3c7048 @space_id="rest-api-testing", @store_id=nil, @tsv_response=nil, @bagit_response=nil>
|
308
298
|
|
309
299
|
>> manifest.csv
|
310
|
-
D, [2016-05-19T13:37:39.831013 #28754] DEBUG -- : Duracloud::
|
300
|
+
D, [2016-05-19T13:37:39.831013 #28754] DEBUG -- : Duracloud::Request GET https://duke.duracloud.org/durastore/manifest/rest-api-testing 200 OK
|
311
301
|
=> #<CSV::Table mode:col_or_row row_count:10>
|
312
302
|
|
313
303
|
>> manifest.csv.headers
|
314
304
|
=> ["space_id", "content_id", "md5"]
|
315
305
|
```
|
316
306
|
|
317
|
-
*Added in v0.5.0
|
307
|
+
*Added in v0.5.0* Support for asynchronous generation of manifest (Generate Manifest API)
|
318
308
|
|
319
309
|
```
|
320
310
|
>> manifest = Duracloud::Manifest.new('ddr-validation')
|
321
311
|
=> #<Duracloud::Manifest:0x007f8fd82fe328 @space_id="ddr-validation", @store_id=nil>
|
322
312
|
>> manifest.generate
|
323
|
-
D, [2017-06-06T20:49:50.191301 #92029] DEBUG -- : Duracloud::
|
313
|
+
D, [2017-06-06T20:49:50.191301 #92029] DEBUG -- : Duracloud::Request POST https://duke.duracloud.org/durastore/manifest/ddr-validation 202 Accepted
|
324
314
|
I, [2017-06-06T20:49:50.191414 #92029] INFO -- : We are processing your manifest generation request. To retrieve your file, please poll the URI in the Location header of this response: (https://duke.duracloud.org/durastore/x-duracloud-admin/generated-manifests/manifest-ddr-validation_amazon_s3_2017-06-07-00-49-50.txt.gz).
|
325
315
|
=> "https://duke.duracloud.org/durastore/x-duracloud-admin/generated-manifests/manifest-ddr-validation_amazon_s3_2017-06-07-00-49-50.txt.gz"
|
326
316
|
```
|
@@ -333,7 +323,7 @@ D, [2016-05-19T13:37:39.831013 #28754] DEBUG -- : Duracloud::Client GET https://
|
|
333
323
|
=> #<Duracloud::BitIntegrityReport:0x007f88e39a2950 @space_id="rest-api-testing", @store_id=nil, @report=nil, @properties=nil>
|
334
324
|
|
335
325
|
>> bit_integrity_report.csv
|
336
|
-
D, [2016-05-19T15:39:33.538448 #29974] DEBUG -- : Duracloud::
|
326
|
+
D, [2016-05-19T15:39:33.538448 #29974] DEBUG -- : Duracloud::Request GET https://duke.duracloud.org/durastore/bit-integrity/rest-api-testing 200 OK
|
337
327
|
=> #<CSV::Table mode:col_or_row row_count:8>
|
338
328
|
```
|
339
329
|
|
data/duracloud.gemspec
CHANGED
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency "addressable", "~> 2.5"
|
24
24
|
spec.add_dependency "hashie", "~> 3.4"
|
25
25
|
spec.add_dependency "httpclient", "~> 2.7"
|
26
|
-
spec.add_dependency "activemodel", ">= 4.2", "< 6"
|
27
26
|
spec.add_dependency "nokogiri", "~> 1.6"
|
28
27
|
|
29
28
|
spec.add_development_dependency "webmock", "~> 2.0"
|
data/lib/duracloud.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'logger'
|
2
|
+
require 'uri'
|
3
|
+
require 'duracloud/version'
|
4
|
+
require 'duracloud/error'
|
3
5
|
|
4
6
|
module Duracloud
|
7
|
+
|
5
8
|
autoload :AbstractEntity, "duracloud/abstract_entity"
|
6
9
|
autoload :AuditLog, "duracloud/audit_log"
|
7
10
|
autoload :BitIntegrityReport, "duracloud/bit_integrity_report"
|
@@ -10,24 +13,47 @@ module Duracloud
|
|
10
13
|
autoload :CLI, "duracloud/cli"
|
11
14
|
autoload :CommandOptions, "duracloud/command_options"
|
12
15
|
autoload :Commands, "duracloud/commands"
|
13
|
-
autoload :Configuration, "duracloud/configuration"
|
14
|
-
autoload :Connection, "duracloud/connection"
|
15
16
|
autoload :Content, "duracloud/content"
|
16
17
|
autoload :ContentManifest, "duracloud/content_manifest"
|
17
|
-
autoload :DurastoreRequest, "duracloud/durastore_request"
|
18
|
-
autoload :ErrorHandler, "duracloud/error_handler"
|
19
18
|
autoload :FastSyncValidation, "duracloud/fast_sync_validation"
|
20
19
|
autoload :Manifest, "duracloud/manifest"
|
21
|
-
autoload :Persistence, "duracloud/persistence"
|
22
20
|
autoload :Properties, "duracloud/properties"
|
23
21
|
autoload :Request, "duracloud/request"
|
24
22
|
autoload :Response, "duracloud/response"
|
23
|
+
autoload :ResponseHandler, "duracloud/response_handler"
|
25
24
|
autoload :RestMethods, "duracloud/rest_methods"
|
26
25
|
autoload :Space, "duracloud/space"
|
27
26
|
autoload :SpaceAcls, "duracloud/space_acls"
|
28
|
-
autoload :Store, "duracloud/store"
|
29
27
|
autoload :StorageReport, "duracloud/storage_report"
|
30
28
|
autoload :StorageReports, "duracloud/storage_reports"
|
29
|
+
autoload :Store, "duracloud/store"
|
31
30
|
autoload :SyncValidation, "duracloud/sync_validation"
|
32
31
|
autoload :TSV, "duracloud/tsv"
|
32
|
+
|
33
|
+
class << self
|
34
|
+
attr_accessor :host, :port, :user, :password
|
35
|
+
attr_writer :logger
|
36
|
+
|
37
|
+
def logger
|
38
|
+
@logger ||= Logger.new(STDERR)
|
39
|
+
end
|
40
|
+
|
41
|
+
def silence_logging!
|
42
|
+
self.logger = Logger.new(File::NULL)
|
43
|
+
end
|
44
|
+
|
45
|
+
def base_url
|
46
|
+
URI::HTTPS.build(host: host, port: port, path: '/')
|
47
|
+
end
|
48
|
+
|
49
|
+
def auth?
|
50
|
+
!!user
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
self.host = ENV["DURACLOUD_HOST"]
|
55
|
+
self.port = ENV["DURACLOUD_PORT"]
|
56
|
+
self.user = ENV["DURACLOUD_USER"]
|
57
|
+
self.password = ENV["DURACLOUD_PASSWORD"]
|
58
|
+
|
33
59
|
end
|
@@ -1,30 +1,21 @@
|
|
1
|
-
require
|
1
|
+
require 'hashie'
|
2
2
|
|
3
3
|
module Duracloud
|
4
|
-
class AbstractEntity
|
5
|
-
include ActiveModel::Model
|
6
|
-
extend ActiveModel::Callbacks
|
7
|
-
|
8
|
-
define_model_callbacks :save, :delete, :load_properties
|
9
|
-
after_save :persisted!
|
10
|
-
after_save :reset_properties
|
11
|
-
after_load_properties :persisted!
|
12
|
-
before_delete :reset_properties
|
13
|
-
after_delete :deleted!
|
14
|
-
after_delete :freeze
|
4
|
+
class AbstractEntity < Hashie::Dash
|
15
5
|
|
16
6
|
def save
|
17
7
|
raise Error, "Cannot save deleted #{self.class}." if deleted?
|
18
|
-
|
19
|
-
|
20
|
-
|
8
|
+
do_save
|
9
|
+
persisted!
|
10
|
+
reset_properties
|
21
11
|
end
|
22
12
|
|
23
13
|
def delete
|
24
14
|
raise Error, "Cannot delete, already deleted." if deleted?
|
25
|
-
|
26
|
-
|
27
|
-
|
15
|
+
reset_properties
|
16
|
+
do_delete
|
17
|
+
deleted!
|
18
|
+
freeze
|
28
19
|
end
|
29
20
|
|
30
21
|
def persisted?
|
@@ -45,11 +36,9 @@ module Duracloud
|
|
45
36
|
@properties ||= Properties.new
|
46
37
|
end
|
47
38
|
|
48
|
-
|
49
39
|
def load_properties
|
50
|
-
|
51
|
-
|
52
|
-
end
|
40
|
+
do_load_properties
|
41
|
+
persisted!
|
53
42
|
end
|
54
43
|
|
55
44
|
private
|
data/lib/duracloud/cli.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'optparse'
|
2
|
-
require '
|
2
|
+
require 'hashie'
|
3
3
|
|
4
4
|
module Duracloud
|
5
|
-
class CLI
|
6
|
-
include ActiveModel::Model
|
5
|
+
class CLI < Hashie::Dash
|
7
6
|
include Commands
|
8
7
|
|
9
8
|
COMMANDS = Commands.public_instance_methods.map(&:to_s)
|
@@ -18,50 +17,48 @@ Options:
|
|
18
17
|
EOS
|
19
18
|
HELP = "Type 'duracloud -h/--help' for usage."
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
validates_presence_of :space_id, message: "-s/--space-id option is required.", unless: "command == 'get_storage_report'"
|
42
|
-
validates_inclusion_of :command, in: COMMANDS
|
20
|
+
property :all_spaces
|
21
|
+
property :command, required: true
|
22
|
+
property :content_dir
|
23
|
+
property :content_id
|
24
|
+
property :content_type
|
25
|
+
property :fast
|
26
|
+
property :format
|
27
|
+
property :host
|
28
|
+
property :infile
|
29
|
+
property :logging
|
30
|
+
property :md5
|
31
|
+
property :missing
|
32
|
+
property :password
|
33
|
+
property :port
|
34
|
+
property :prefix
|
35
|
+
property :space_id, required: -> { command != "get_storage_report" }, message: "-s/--space-id option is required."
|
36
|
+
property :store_id
|
37
|
+
property :user
|
38
|
+
property :work_dir
|
43
39
|
|
44
40
|
def self.error!(exception)
|
45
41
|
$stderr.puts exception.message
|
46
|
-
if [ CommandError, OptionParser::ParseError ].include?(exception.class)
|
42
|
+
if [ ArgumentError, CommandError, OptionParser::ParseError ].include?(exception.class)
|
47
43
|
$stderr.puts HELP
|
48
44
|
end
|
49
45
|
exit(false)
|
50
46
|
end
|
51
47
|
|
52
48
|
def self.call(*args)
|
53
|
-
|
54
|
-
cli = new(options) # .merge(command: command))
|
55
|
-
if cli.invalid?
|
56
|
-
message = cli.errors.map { |k, v| "ERROR: #{v}" }.join("\n")
|
57
|
-
raise CommandError, message
|
58
|
-
end
|
59
|
-
cli.execute
|
49
|
+
new(*args).execute
|
60
50
|
rescue => e
|
61
51
|
error!(e)
|
62
52
|
end
|
63
53
|
|
54
|
+
def initialize(*args)
|
55
|
+
super CommandOptions.parse(*args)
|
56
|
+
end
|
57
|
+
|
64
58
|
def execute
|
59
|
+
unless COMMANDS.include?(command)
|
60
|
+
raise CommandError, "Invalid command: #{command.inspect}."
|
61
|
+
end
|
65
62
|
configure_client
|
66
63
|
send(command, self)
|
67
64
|
end
|
@@ -69,14 +66,12 @@ EOS
|
|
69
66
|
private
|
70
67
|
|
71
68
|
def configure_client
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
config.port = port if port
|
69
|
+
Duracloud.user = user if user
|
70
|
+
Duracloud.password = password if password
|
71
|
+
Duracloud.host = host if host
|
72
|
+
Duracloud.port = port if port
|
77
73
|
|
78
|
-
|
79
|
-
end
|
74
|
+
Duracloud.silence_logging! unless logging
|
80
75
|
end
|
81
76
|
|
82
77
|
end
|