shibkit-meta_meta 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +21 -0
  4. data/Gemfile.lock +52 -0
  5. data/Icon.png +0 -0
  6. data/LICENSE.txt +177 -0
  7. data/README.md +789 -0
  8. data/Rakefile +38 -0
  9. data/VERSION +1 -0
  10. data/examples/biggest_entity_id.rb +4 -0
  11. data/lib/shibkit/meta_meta.rb +600 -0
  12. data/lib/shibkit/meta_meta/attribute.rb +73 -0
  13. data/lib/shibkit/meta_meta/config.rb +463 -0
  14. data/lib/shibkit/meta_meta/contact.rb +85 -0
  15. data/lib/shibkit/meta_meta/data/default_metadata/example_federation_metadata.xml +168 -0
  16. data/lib/shibkit/meta_meta/data/default_metadata/local_metadata.xml +66 -0
  17. data/lib/shibkit/meta_meta/data/default_metadata/uncommon_federation_metadata.xml +115 -0
  18. data/lib/shibkit/meta_meta/data/default_metadata_cache.yml +166 -0
  19. data/lib/shibkit/meta_meta/data/dev_sources.yml +86 -0
  20. data/lib/shibkit/meta_meta/data/real_sources.yml +163 -0
  21. data/lib/shibkit/meta_meta/entity.rb +219 -0
  22. data/lib/shibkit/meta_meta/federation.rb +161 -0
  23. data/lib/shibkit/meta_meta/idp.rb +81 -0
  24. data/lib/shibkit/meta_meta/logo.rb +216 -0
  25. data/lib/shibkit/meta_meta/metadata_item.rb +244 -0
  26. data/lib/shibkit/meta_meta/mixin/cached_downloads.rb +127 -0
  27. data/lib/shibkit/meta_meta/mixin/xpath_chores.rb +111 -0
  28. data/lib/shibkit/meta_meta/organisation.rb +73 -0
  29. data/lib/shibkit/meta_meta/provider.rb +195 -0
  30. data/lib/shibkit/meta_meta/provisioning/base.rb +33 -0
  31. data/lib/shibkit/meta_meta/requested_attribute.rb +29 -0
  32. data/lib/shibkit/meta_meta/service.rb +94 -0
  33. data/lib/shibkit/meta_meta/source.rb +558 -0
  34. data/lib/shibkit/meta_meta/sp.rb +79 -0
  35. data/shibkit-meta_meta.gemspec +154 -0
  36. data/spec/meta_meta/attribute/token +0 -0
  37. data/spec/meta_meta/config/autoloading_and_refreshing_spec.rb +72 -0
  38. data/spec/meta_meta/config/code_nspec.rb +13 -0
  39. data/spec/meta_meta/config/configuration_spec.rb +30 -0
  40. data/spec/meta_meta/config/creation_spec.rb +43 -0
  41. data/spec/meta_meta/config/downloading_and_caching_settings_spec.rb +216 -0
  42. data/spec/meta_meta/config/env_platform_settings.rb +129 -0
  43. data/spec/meta_meta/config/filtering_settings_spec.rb +123 -0
  44. data/spec/meta_meta/config/init.rb +8 -0
  45. data/spec/meta_meta/config/logger_settings_spec.rb +91 -0
  46. data/spec/meta_meta/config/smartcache_settings_spec.rb +110 -0
  47. data/spec/meta_meta/config/source_file_settings_spec.rb +99 -0
  48. data/spec/meta_meta/config/tagging_settings_spec.rb +81 -0
  49. data/spec/meta_meta/config/working_directory_settings_spec.rb +106 -0
  50. data/spec/meta_meta/config/xml_processing_settings_spec.rb +75 -0
  51. data/spec/meta_meta/contact/contact_oldspec.rb +0 -0
  52. data/spec/meta_meta/entity/entity_oldspec.rb +53 -0
  53. data/spec/meta_meta/federation/federation_oldspec.rb +0 -0
  54. data/spec/meta_meta/idp/token +0 -0
  55. data/spec/meta_meta/logo/token +0 -0
  56. data/spec/meta_meta/meta_meta/cache_example.yaml +141284 -0
  57. data/spec/meta_meta/meta_meta/meta_meta_spec.rb +269 -0
  58. data/spec/meta_meta/meta_meta/saved_sources.yaml +46 -0
  59. data/spec/meta_meta/metadata_item/token +0 -0
  60. data/spec/meta_meta/organisation/organisation_oldspec.rb +0 -0
  61. data/spec/meta_meta/provider/token +0 -0
  62. data/spec/meta_meta/requested_attribute/token +0 -0
  63. data/spec/meta_meta/service/token +0 -0
  64. data/spec/meta_meta/source/application_extras_spec.rb +234 -0
  65. data/spec/meta_meta/source/conversion_spec.rb +75 -0
  66. data/spec/meta_meta/source/creation_spec.rb +0 -0
  67. data/spec/meta_meta/source/downloads_and_caching_spec.rb +0 -0
  68. data/spec/meta_meta/source/federation_information_spec.rb +11 -0
  69. data/spec/meta_meta/source/fixtures.rb +24 -0
  70. data/spec/meta_meta/source/init.rb +1 -0
  71. data/spec/meta_meta/source/loading_and_saving_spec.rb +0 -0
  72. data/spec/meta_meta/source/metadata_details_spec.rb +0 -0
  73. data/spec/meta_meta/source/metadata_integrity_spec.rb +0 -0
  74. data/spec/meta_meta/source/selection_spec.rb +0 -0
  75. data/spec/meta_meta/source/source_oldspec.rb +353 -0
  76. data/spec/meta_meta/source/xml_parsing_spec.rb +0 -0
  77. data/spec/meta_meta/sp/token +0 -0
  78. data/spec/meta_meta/template +2 -0
  79. data/spec/moi/config_spec.rb +0 -0
  80. data/spec/spec.opts +1 -0
  81. data/spec/spec_helper.rb +25 -0
  82. data/spec/support/supply_xml.rb +0 -0
  83. metadata +320 -0
@@ -0,0 +1,73 @@
1
+ ## @author Pete Birkinshaw (<pete@digitalidentitylabs.com>)
2
+ ## Copyright: Copyright (c) 2011 Digital Identity Ltd.
3
+ ## License: Apache License, Version 2.0
4
+
5
+ ## Licensed under the Apache License, Version 2.0 (the "License");
6
+ ## you may not use this file except in compliance with the License.
7
+ ## You may obtain a copy of the License at
8
+ ##
9
+ ## http://www.apache.org/licenses/LICENSE-2.0
10
+ ##
11
+ ## Unless required by applicable law or agreed to in writing, software
12
+ ## distributed under the License is distributed on an "AS IS" BASIS,
13
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ ## See the License for the specific language governing permissions and
15
+ ## limitations under the License.
16
+ ##
17
+
18
+ module Shibkit
19
+ class MetaMeta
20
+
21
+ ## Class to represent the metadata of the organisation owning a Shibboleth entity
22
+ class Attribute < MetadataItem
23
+
24
+ ## Element and attribute used to select XML for new objects
25
+ ROOT_ELEMENT = 'Attribute'
26
+ TARGET_ATTR = 'Name'
27
+ REQUIRED_QUACKS = [:Name, :NameFormat]
28
+
29
+
30
+ ##
31
+ attr_accessor :name
32
+
33
+ attr_accessor :is_required
34
+
35
+ attr_accessor :name_format
36
+
37
+ attr_accessor :friendly_name
38
+
39
+ ##
40
+ attr_accessor :values
41
+
42
+ alias :required? :is_required
43
+ alias :is_required? :is_required
44
+
45
+ private
46
+
47
+ ## Nicer presentation as a string
48
+ def to_s
49
+
50
+ return friendly_name
51
+
52
+ end
53
+
54
+ def parse_xml
55
+
56
+ @name = @noko['Name']
57
+
58
+ @is_required = @noko['isRequired'].to_s.downcase == 'true' ? true : false
59
+
60
+ @name_format = @noko['NameFormat']
61
+
62
+ @friendly_name = @noko['FriendlyName']
63
+
64
+ @values ||= Array.new
65
+ @noko.xpath('saml:AttributeValue').each { |ax| @values << ax.content.strip }
66
+
67
+ log.debug " Derived attribute #{name} from XML"
68
+
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,463 @@
1
+ ## @author Pete Birkinshaw (<pete@digitalidentitylabs.com>)
2
+ ## Copyright: Copyright (c) 2011 Digital Identity Ltd.
3
+ ## License: Apache License, Version 2.0
4
+
5
+ ## Licensed under the Apache License, Version 2.0 (the "License");
6
+ ## you may not use this file except in compliance with the License.
7
+ ## You may obtain a copy of the License at
8
+ ##
9
+ ## http://www.apache.org/licenses/LICENSE-2.0
10
+ ##
11
+ ## Unless required by applicable law or agreed to in writing, software
12
+ ## distributed under the License is distributed on an "AS IS" BASIS,
13
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ ## See the License for the specific language governing permissions and
15
+ ## limitations under the License.
16
+ ##
17
+
18
+ module Shibkit
19
+
20
+ class MetaMeta
21
+
22
+ class Config
23
+
24
+ require 'logger'
25
+ require 'rbconfig'
26
+ require 'tempfile'
27
+ require 'addressable/uri'
28
+ require 'fileutils'
29
+ require 'singleton'
30
+
31
+ include Singleton
32
+
33
+ ## Location of default real sources list (contains real-world federation details)
34
+ REAL_SOURCES_FILE = "#{::File.dirname(__FILE__)}/data/real_sources.yml"
35
+
36
+ ## Location of default mock sources list (contains small fictional federations)
37
+ DEV_SOURCES_FILE = "#{::File.dirname(__FILE__)}/data/real_sources.yml"
38
+
39
+ ## Location of default test sources list # TODO
40
+ TEST_SOURCES_FILE = "#{::File.dirname(__FILE__)}/data/real_sources.yml"
41
+
42
+ ## Slurp
43
+ VERSION_FILE = "#{::File.dirname(__FILE__)}/../../../VERSION"
44
+
45
+ ##
46
+ def initialize(&block)
47
+
48
+ @logger = ::Logger.new(STDOUT)
49
+ @logger.level = ::Logger::INFO
50
+ @logger.datetime_format = "%Y-%m-%d %H:%M:%S"
51
+ @logger.formatter = proc { |severity, datetime, progname, msg| "#{datetime}: #{severity} #{msg}\n" }
52
+ @logger.progname = "MetaMeta"
53
+
54
+ @download_cache_options = Hash.new
55
+ @sources_file = :auto
56
+
57
+ @selected_federation_uris = []
58
+
59
+ ## Execute block if passed one ## Does not get one. Needs a work around, eventually.
60
+ instance_eval(&block) if block
61
+
62
+ end
63
+
64
+ def configure(&block)
65
+
66
+ ## Execute block if passed one
67
+ self.instance_eval(&block) if block
68
+
69
+ end
70
+
71
+ ##
72
+ def sources_file=(file_path)
73
+
74
+ @sources_file = file_path
75
+
76
+ end
77
+
78
+ ##
79
+ def sources_file
80
+
81
+ @sources_file ||= :auto
82
+
83
+ case @sources_file
84
+ when :auto
85
+ #file_path = self.in_production? ? REAL_SOURCES_FILE : DEV_SOURCES_FILE
86
+ file_path = REAL_SOURCES_FILE
87
+ when :dev, :development
88
+ file_path = DEV_SOURCES_FILE
89
+ when :test, :testing
90
+ file_path = TEST_SOURCES_FILE
91
+ when :real, :prod, :production, :all, :full
92
+ file_path = REAL_SOURCES_FILE
93
+ else
94
+ file_path = @sources_file
95
+ end
96
+
97
+ return file_path
98
+
99
+ end
100
+
101
+ ## Purge all XML data from object after creating object
102
+ def purge_xml=(bool)
103
+
104
+ @purge_xml = bool ? true : false
105
+
106
+ end
107
+
108
+ ## Should all XML be purged from objects after creation?
109
+ def purge_xml?
110
+
111
+ return @purge_xml.nil? ? true : @purge_xml
112
+
113
+ end
114
+
115
+ ## Store source XML alongside the parsed XML
116
+ def remember_source_xml=(bool)
117
+
118
+ @remember_source_xml = bool ? true : false
119
+
120
+ end
121
+
122
+ ## Store source XML alongside the parsed XML
123
+ def remember_source_xml?
124
+
125
+ return @remember_source_xml.nil? ? false : @remember_source_xml
126
+
127
+ end
128
+
129
+ def smartcache_expiry=(seconds)
130
+
131
+ @smartcache_expiry = seconds.to_i
132
+
133
+ end
134
+
135
+ def smartcache_expiry
136
+
137
+ return @smartcache_expiry || 60*60
138
+
139
+ end
140
+
141
+ def smartcache_active=(bool)
142
+
143
+ @smartcache_active = bool ? true : false
144
+
145
+ end
146
+
147
+ def smartcache_active?
148
+
149
+ return @smartcache_active.nil? ? true : @smartcache_active
150
+
151
+ end
152
+
153
+ def smartcache_object_file
154
+
155
+ return File.join(cache_root, 'smartcache.marshal')
156
+
157
+ end
158
+
159
+ def smartcache_info_file
160
+
161
+ return File.join(cache_root, 'smartcache.yml')
162
+
163
+ end
164
+
165
+ def verbose_downloads=(bool)
166
+
167
+ @verbose = bool ? true : false
168
+ self.download_cache_options = { :verbose => @verbose }
169
+
170
+ end
171
+
172
+ def verbose_downloads?
173
+
174
+ return @verbose.nil? ? false : @verbose
175
+
176
+ end
177
+
178
+ def cache_fallback_ttl=(seconds)
179
+
180
+ @cache_fallback_ttl = seconds.to_i
181
+ self.download_cache_options = { :default_ttl => @cache_fallback_ttl }
182
+
183
+ end
184
+
185
+ def cache_fallback_ttl
186
+
187
+ return @cache_fallback_ttl.nil? ? 7200 : @cache_fallback_ttl
188
+
189
+ end
190
+
191
+ ## Set main logger
192
+ def logger=(logger)
193
+
194
+ @logger = logger
195
+
196
+ end
197
+
198
+ ## Returns current main logger
199
+ def logger
200
+
201
+ return @logger
202
+
203
+ end
204
+
205
+ ##
206
+ def downloads_logger=(logger)
207
+
208
+ return @downloads_logger = logger
209
+
210
+ end
211
+
212
+ ##
213
+ def downloads_logger
214
+
215
+ return @downloads_logger || nil
216
+
217
+ end
218
+
219
+ ## Load a metadata sources file automatically (true or false)
220
+ def autoload=(setting)
221
+
222
+ @autoload = setting ? true : false
223
+
224
+ end
225
+
226
+ ## Should metadata sources and objects be loaded automatically? Normally, yes.
227
+ def autoload?
228
+
229
+ return true unless defined? @autoload
230
+ return @autoload
231
+
232
+ end
233
+
234
+ ##
235
+ def selected_groups=(*list)
236
+
237
+ @selected_groups = [list].flatten
238
+ @selected_groups = [] if @selected_groups.include? :all
239
+
240
+ end
241
+
242
+ ##
243
+ def selected_groups
244
+
245
+ return @selected_groups || []
246
+
247
+ end
248
+
249
+ ## Only use these federations/sources even if know about 100s - works on
250
+ ## various functions (loading, processing and listing *after* it is set)
251
+ def only_use(selection)
252
+
253
+ @selected_federation_uris = []
254
+
255
+ case selection
256
+ when String
257
+ @selected_federation_uris << selection
258
+ when Array
259
+ @selected_federation_uris.concat(selection)
260
+ when Hash
261
+ @selected_federation_uris.concat(selection.keys)
262
+ when :all, :everything, nil, false
263
+ @selected_federation_uris = []
264
+ else
265
+ raise "Expected federation/source selection to be single uri or array"
266
+ end
267
+
268
+ end
269
+
270
+ ## List of federation/collection uris
271
+ def selected_federation_uris=(selection)
272
+
273
+ only_use(selection)
274
+
275
+ end
276
+
277
+ ## List of federation/collection uris
278
+ def selected_federation_uris
279
+
280
+ return @selected_federation_uris || []
281
+
282
+ end
283
+
284
+ ## @return [String]
285
+ def auto_refresh=(bool)
286
+
287
+ @auto_refresh = bool ? true : false
288
+
289
+ end
290
+
291
+ ## @return [String]
292
+ def auto_refresh?
293
+
294
+ return @auto_refresh.nil? ? true : @auto_refresh
295
+
296
+ end
297
+
298
+ def can_delete=(bool)
299
+
300
+ @can_delete = bool ? true : false
301
+
302
+ end
303
+
304
+ def can_delete?
305
+
306
+ return @can_delete || false
307
+
308
+ end
309
+
310
+ ##
311
+ def auto_tag=(bool)
312
+
313
+ @auto_tag = bool ? true : false
314
+
315
+ end
316
+
317
+ ##
318
+ def auto_tag?
319
+
320
+ return @auto_tag.nil? ? false : @auto_tag
321
+
322
+ end
323
+
324
+ ##
325
+ def merge_primary_tags=(bool)
326
+
327
+ @merge_primary_tags = bool ? true : false
328
+
329
+ end
330
+
331
+ ##
332
+ def merge_primary_tags?
333
+
334
+ return @merge_primary_tags.nil? ? true : @merge_primary_tags
335
+
336
+ end
337
+
338
+ ## Forcibly set environment (not normally needed)
339
+ ## @return [String]
340
+ def environment=(environ)
341
+
342
+ @environment = environ.to_sym
343
+
344
+ end
345
+
346
+ ## Forcibly set environment (not normally needed)
347
+ ## @return [String]
348
+ def environment
349
+
350
+ return @environment || :development
351
+
352
+ end
353
+
354
+ ## Options to set how remote files are cached and expired
355
+ ## @param [Hash] Rack::Cache compatible hash of options
356
+ ## @see http://rtomayko.github.com/rack-cache/ Rack::Cache for more information
357
+ def download_cache_options=(options)
358
+
359
+ @download_cache_options ||= Hash.new
360
+
361
+ if download_cache_options
362
+ @download_cache_options.merge!(options)
363
+ else
364
+ @download_cache_options = @options
365
+ end
366
+
367
+ end
368
+
369
+ ## Returns hash of options to set how remote files are cached and expired
370
+ def download_cache_options
371
+
372
+ @download_cache_options ||= Hash.new
373
+
374
+ return download_cache_defaults.merge(@download_cache_options).freeze
375
+
376
+ end
377
+
378
+
379
+ ## Work out if we are in production or not by snooping on environment
380
+ def in_production?
381
+
382
+ ## Use attribute rather than method so we can distinguish between default and set values
383
+ return true if @environment == :production
384
+ return false if @environment == :development
385
+ return false if @environment == :test
386
+
387
+ if defined? Rails and Rails.respond_to? :env
388
+ return Rails.env.production?
389
+ end
390
+
391
+ if defined? Rack and defined? RACK_ENV
392
+ return true if RACK_ENV == 'production'
393
+ end
394
+
395
+ return false
396
+
397
+ end
398
+
399
+ ## Set cache root
400
+ def cache_root=(file_path)
401
+
402
+ @cache_root = file_path
403
+
404
+ end
405
+
406
+ ## return or calculate the filesystem path to store the web cache
407
+ def cache_root
408
+
409
+ unless @cache_root
410
+
411
+ tmp_dir = sensible_os? ? '/tmp' : ENV['TEMP']
412
+ @cache_root = File.join(tmp_dir, 'skmm-cache')
413
+
414
+ end
415
+
416
+ return @cache_root
417
+
418
+ end
419
+
420
+ ##
421
+ def version
422
+
423
+ unless @version
424
+
425
+ @version = File.open(VERSION_FILE, 'r') { |file| file.gets.strip }
426
+
427
+ end
428
+
429
+ return @version
430
+
431
+ end
432
+
433
+ ##
434
+ def platform
435
+
436
+ return [RUBY_VERSION, RUBY_PLATFORM, RUBY_RELEASE_DATE].join(':')
437
+
438
+ end
439
+
440
+ private
441
+
442
+ ## Are we on a POSIX standard system or on MS-DOS/Windows, etc?
443
+ def sensible_os?
444
+
445
+ return ::Config::CONFIG['host_os'] =~ /mswin|mingw/ ? false : true
446
+
447
+ end
448
+
449
+ ##
450
+ def download_cache_defaults
451
+
452
+ return {
453
+ :default_ttl => cache_fallback_ttl,
454
+ :verbose => verbose_downloads?,
455
+ :metastore => Addressable::URI.convert_path(File.join(cache_root, 'meta')).to_s,
456
+ :entitystore => Addressable::URI.convert_path(File.join(cache_root, 'body')).to_s
457
+ }
458
+
459
+ end
460
+
461
+ end
462
+ end
463
+ end