Class: Fog::Storage::HP::Directory
- Inherits:
-
Model
- Object
- Model
- Fog::Storage::HP::Directory
show all
- Defined in:
- lib/fog/hp/models/storage/directory.rb
Instance Attribute Summary
Attributes inherited from Model
#collection, #service
Instance Method Summary
collapse
Methods inherited from Model
#inspect, #reload, #symbolize_keys, #to_json, #wait_for
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
#connection, #connection=, #prepare_service_value
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one
Constructor Details
#initialize(attributes = {}) ⇒ Directory
Returns a new instance of Directory.
22
23
24
25
26
|
# File 'lib/fog/hp/models/storage/directory.rb', line 22
def initialize(attributes = {})
@read_acl = []
@write_acl = []
super
end
|
Instance Method Details
#can_read?(user) ⇒ Boolean
36
37
38
39
|
# File 'lib/fog/hp/models/storage/directory.rb', line 36
def can_read?(user)
return false if @read_acl.nil?
list_users_with_read.include?(user)
end
|
#can_read_write?(user) ⇒ Boolean
46
47
48
|
# File 'lib/fog/hp/models/storage/directory.rb', line 46
def can_read_write?(user)
can_read?(user) && can_write?(user)
end
|
#can_write?(user) ⇒ Boolean
41
42
43
44
|
# File 'lib/fog/hp/models/storage/directory.rb', line 41
def can_write?(user)
return false if @write_acl.nil?
list_users_with_write.include?(user)
end
|
#cdn_enable=(new_cdn_enable) ⇒ Object
174
175
176
177
178
179
180
181
182
|
# File 'lib/fog/hp/models/storage/directory.rb', line 174
def cdn_enable=(new_cdn_enable)
@cdn_enable ||= false
if (!service.cdn.nil? && service.cdn.enabled?)
@cdn_enable = new_cdn_enable
else
@cdn_enable = false
end
end
|
#cdn_enabled? ⇒ Boolean
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
# File 'lib/fog/hp/models/storage/directory.rb', line 184
def cdn_enabled?
if (!service.cdn.nil? && service.cdn.enabled?)
begin response = service.cdn.head_container(key)
= response..fetch('X-Cdn-Enabled', nil)
if (!.nil? && == 'True')
@cdn_enable = true
else
@cdn_enable = false
end
rescue Fog::CDN::HP::NotFound, Excon::Errors::SocketError
@cdn_enable = false
end
else
@cdn_enable = false
end
end
|
#cdn_public_ssl_url ⇒ Object
216
217
218
219
220
221
222
223
224
225
226
227
228
|
# File 'lib/fog/hp/models/storage/directory.rb', line 216
def cdn_public_ssl_url
requires :key
@cdn_public_ssl_url ||= begin
begin response = service.cdn.head_container(key)
if response.['X-Cdn-Enabled'] == 'True'
response..fetch('X-Cdn-Ssl-Uri', nil)
end
rescue Fog::CDN::HP::NotFound
nil
end
end
end
|
#cdn_public_url ⇒ Object
202
203
204
205
206
207
208
209
210
211
212
213
214
|
# File 'lib/fog/hp/models/storage/directory.rb', line 202
def cdn_public_url
requires :key
@cdn_public_url ||= begin
begin response = service.cdn.head_container(key)
if response.['X-Cdn-Enabled'] == 'True'
response..fetch('X-Cdn-Uri', nil)
end
rescue Fog::CDN::HP::NotFound
nil
end
end
end
|
#destroy ⇒ Object
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/fog/hp/models/storage/directory.rb', line 119
def destroy
requires :key
service.delete_container(key)
if cdn_enabled?
begin
service.cdn.delete_container(key)
rescue Fog::CDN::HP::NotFound
end
end
true
rescue Excon::Errors::NotFound, Fog::Storage::HP::NotFound
false
end
|
#files ⇒ Object
135
136
137
138
139
140
141
142
|
# File 'lib/fog/hp/models/storage/directory.rb', line 135
def files
@files ||= begin
Fog::Storage::HP::Files.new(
:directory => self,
:service => service
)
end
end
|
#grant(perm, users = nil) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/fog/hp/models/storage/directory.rb', line 62
def grant(perm, users=nil)
if users.is_a?(String)
user_list = users.split(',')
else
user_list = users
end
r_acl, w_acl = service.perm_to_acl(perm, user_list)
unless r_acl.nil? || r_acl.empty?
@read_acl = [] if @read_acl.nil?
@read_acl = @read_acl + r_acl
@read_acl.uniq!
end
unless w_acl.nil? || w_acl.empty?
@write_acl = [] if @write_acl.nil?
@write_acl = @write_acl + w_acl
@write_acl.uniq!
end
true
end
|
#list_users_with_read ⇒ Object
50
51
52
53
54
|
# File 'lib/fog/hp/models/storage/directory.rb', line 50
def list_users_with_read
users = []
users = @read_acl.map {|acl| acl.split(':')[1]} unless @read_acl.nil?
return users
end
|
#list_users_with_write ⇒ Object
56
57
58
59
60
|
# File 'lib/fog/hp/models/storage/directory.rb', line 56
def list_users_with_write
users = []
users = @write_acl.map {|acl| acl.split(':')[1]} unless @write_acl.nil?
return users
end
|
104
105
106
107
108
109
110
111
|
# File 'lib/fog/hp/models/storage/directory.rb', line 104
def metadata
@metadata ||= begin
Fog::Storage::HP::Metadata.new({
:service => service,
:parent => self
})
end
end
|
113
114
115
116
117
|
# File 'lib/fog/hp/models/storage/directory.rb', line 113
def metadata=(new_metadata={})
metas = []
new_metadata.each_pair {|k,v| metas << {'key' => k, 'value' => v} }
metadata.load(metas)
end
|
#public=(new_public) ⇒ Object
144
145
146
147
148
149
150
151
|
# File 'lib/fog/hp/models/storage/directory.rb', line 144
def public=(new_public)
if new_public
self.grant("pr")
else
self.revoke("pr")
end
@public = new_public
end
|
#public? ⇒ Boolean
153
154
155
156
157
158
159
160
|
# File 'lib/fog/hp/models/storage/directory.rb', line 153
def public?
@read_acl = [] if @read_acl.nil?
if @read_acl.include?(".r:*")
true
else
false
end
end
|
#public_url ⇒ Object
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/fog/hp/models/storage/directory.rb', line 162
def public_url
requires :key
@public_url ||= begin
begin response = service.head_container(key)
url = service.public_url(key)
rescue Fog::Storage::HP::NotFound => err
nil
end
end
end
|
#read_acl ⇒ Object
28
29
30
|
# File 'lib/fog/hp/models/storage/directory.rb', line 28
def read_acl
@read_acl || []
end
|
#revoke(perm, users = nil) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/fog/hp/models/storage/directory.rb', line 83
def revoke(perm, users=nil)
if users.is_a?(String)
user_list = users.split(',')
else
user_list = users
end
r_acl, w_acl = service.perm_to_acl(perm, user_list)
unless r_acl.nil? || r_acl.empty?
@read_acl = [] if @read_acl.nil?
@read_acl = @read_acl - r_acl
@read_acl.uniq!
end
unless w_acl.nil? || w_acl.empty?
@write_acl = [] if @write_acl.nil?
@write_acl = @write_acl - w_acl
@write_acl.uniq!
end
true
end
|
#save(new_options = {}) ⇒ Object
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
# File 'lib/fog/hp/models/storage/directory.rb', line 251
def save(new_options = {})
requires :key
options = {}
meta_hash = {}
metadata.each { |meta| meta_hash.store(meta.key, meta.value) }
if meta_hash
options.merge!(meta_hash)
end
options.merge!(service.(@read_acl, @write_acl))
options.merge!({'X-Container-Sync-To' => self.sync_to}) unless self.sync_to.nil?
options.merge!({'X-Container-Sync-Key' => self.sync_key}) unless self.sync_key.nil?
options.merge!({'X-Container-Meta-Web-Index' => self.web_index}) unless self.web_index.nil?
options.merge!({'X-Container-Meta-Web-Listings' => self.web_listings})
options.merge!({'X-Container-Meta-Web-Listings-Css' => self.web_listings_css}) unless self.web_listings_css.nil?
options.merge!({'X-Container-Meta-Web-Error' => self.web_error}) unless self.web_error.nil?
options.merge!(new_options)
service.put_container(key, options)
if (!service.cdn.nil? && service.cdn.enabled?)
if @cdn_enable
begin response = service.cdn.head_container(key)
if response.['X-Cdn-Enabled'] == 'False'
service.cdn.post_container(key, {'X-Cdn-Enabled' => 'True'})
end
rescue Fog::CDN::HP::NotFound
service.cdn.put_container(key)
rescue Excon::Errors::SocketError
end
else
begin response = service.cdn.head_container(key)
if response.['X-Cdn-Enabled'] == 'True'
service.cdn.post_container(key, {'X-Cdn-Enabled' => 'False'})
end
rescue Fog::CDN::HP::NotFound
rescue Excon::Errors::SocketError
end
end
end
true
end
|
#sync(target_dir, secret) ⇒ Object
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
# File 'lib/fog/hp/models/storage/directory.rb', line 230
def sync(target_dir, secret)
requires :key
return false if target_dir.key == key
begin service.head_container(key)
if !target_dir.nil? && target_dir.is_a?(Fog::Storage::HP::Directory) && target_dir.respond_to?(:public_url) && !target_dir.public_url.nil?
self.sync_to = target_dir.public_url
self.sync_key = secret
target_dir.sync_key = secret
target_dir.save
true
else
false
end
rescue Fog::Storage::HP::NotFound
false
end
end
|
#write_acl ⇒ Object
32
33
34
|
# File 'lib/fog/hp/models/storage/directory.rb', line 32
def write_acl
@write_acl || []
end
|