dor-services 5.24.1 → 5.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dor/certificate_authenticated_rest_resource_factory.rb +37 -0
- data/lib/dor/config.rb +12 -7
- data/lib/dor/datastreams/content_metadata_ds.rb +3 -0
- data/lib/dor/models/concerns/governable.rb +14 -0
- data/lib/dor/rest_resource_factory.rb +39 -0
- data/lib/dor/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46e3ff972a83b4179a404ade467d7faeb01d853a
|
4
|
+
data.tar.gz: 18ae1967c9357b69c59cd095070856eb8914b9b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a444e2762bf1be1c121a3745ad625be500fdc5b05b01e90ed243795a9fabfd02652a4f8e1cff95ea3b0c30acf5b51eff79bb49363469293ca4f071af985e3f2f
|
7
|
+
data.tar.gz: 6276d8db063539fc266a972ba7f01a050fd1469dc45da97e8186f7320db1b7735eb98f413fe87a914d323f16e49d6770c9f5fc5bb975e962b93b4cd5d7143151
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'dor/rest_resource_factory'
|
2
|
+
# Creates RestClient::Resources with client ssl keys for various connections
|
3
|
+
module Dor
|
4
|
+
class CertificateAuthenticatedRestResourceFactory < RestResourceFactory
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
# @return [Hash] options for creating a RestClient::Resource
|
9
|
+
def connection_options
|
10
|
+
params = super
|
11
|
+
params[:ssl_client_cert] = cert if cert
|
12
|
+
params[:ssl_client_key] = key if key
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [OpenSSL::X509::Certificate]
|
16
|
+
def cert
|
17
|
+
@cert ||= OpenSSL::X509::Certificate.new(File.read(cert_file)) if cert_file
|
18
|
+
end
|
19
|
+
|
20
|
+
def cert_file
|
21
|
+
Dor::Config.ssl.cert_file
|
22
|
+
end
|
23
|
+
|
24
|
+
def key_file
|
25
|
+
Dor::Config.ssl.key_file
|
26
|
+
end
|
27
|
+
|
28
|
+
def key_pass
|
29
|
+
Dor::Config.ssl.key_pass
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [OpenSSL::PKey::RSA]
|
33
|
+
def key
|
34
|
+
@key ||= OpenSSL::PKey::RSA.new(File.read(key_file), key_pass) if key_file
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/dor/config.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'confstruct/configuration'
|
2
2
|
require 'rsolr'
|
3
3
|
require 'yaml'
|
4
|
+
require 'dor/certificate_authenticated_rest_resource_factory'
|
4
5
|
|
5
6
|
module Dor
|
6
7
|
class Configuration < Confstruct::Configuration
|
@@ -13,16 +14,17 @@ module Dor
|
|
13
14
|
run_callbacks(:initialize) { }
|
14
15
|
end
|
15
16
|
|
17
|
+
# Call the super method with callbacks and with $VERBOSE temporarily disabled
|
16
18
|
def configure(*args)
|
17
19
|
result = self
|
18
|
-
|
19
|
-
|
20
|
+
temp_verbose = $VERBOSE
|
21
|
+
$VERBOSE = nil
|
20
22
|
begin
|
21
23
|
run_callbacks :configure do
|
22
24
|
result = super(*args)
|
23
25
|
end
|
24
26
|
ensure
|
25
|
-
|
27
|
+
$VERBOSE = temp_verbose
|
26
28
|
end
|
27
29
|
result
|
28
30
|
end
|
@@ -32,6 +34,7 @@ module Dor
|
|
32
34
|
config = Confstruct::Configuration.symbolize_hash JSON.parse(client.get(accept: 'application/json'))
|
33
35
|
configure(config)
|
34
36
|
end
|
37
|
+
deprecation_deprecate :autoconfigure
|
35
38
|
|
36
39
|
def sanitize
|
37
40
|
dup
|
@@ -43,6 +46,8 @@ module Dor
|
|
43
46
|
params[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(key), pass) if key
|
44
47
|
RestClient::Resource.new(url, params)
|
45
48
|
end
|
49
|
+
deprecation_deprecate :make_rest_client
|
50
|
+
|
46
51
|
|
47
52
|
def make_solr_connection(add_opts = {})
|
48
53
|
opts = Dor::Config.solr.opts.merge(add_opts).merge(
|
@@ -54,7 +59,7 @@ module Dor
|
|
54
59
|
set_callback :initialize, :after do |config|
|
55
60
|
config.deep_merge!({
|
56
61
|
:fedora => {
|
57
|
-
:client => Confstruct.deferred { |c|
|
62
|
+
:client => Confstruct.deferred { |c| CertificateAuthenticatedRestResourceFactory.create(:fedora) },
|
58
63
|
:safeurl => Confstruct.deferred { |c|
|
59
64
|
begin
|
60
65
|
fedora_uri = URI.parse(config.fedora.url)
|
@@ -66,10 +71,10 @@ module Dor
|
|
66
71
|
}
|
67
72
|
},
|
68
73
|
:dor_services => {
|
69
|
-
:rest_client => Confstruct.deferred { |c|
|
74
|
+
:rest_client => Confstruct.deferred { |c| RestResourceFactory.create(:dor_services) }
|
70
75
|
},
|
71
76
|
:sdr => {
|
72
|
-
:rest_client => Confstruct.deferred { |c|
|
77
|
+
:rest_client => Confstruct.deferred { |c| RestResourceFactory.create(:sdr) }
|
73
78
|
},
|
74
79
|
:workflow => {
|
75
80
|
:client => Confstruct.deferred do |c|
|
@@ -89,6 +94,7 @@ module Dor
|
|
89
94
|
end
|
90
95
|
|
91
96
|
set_callback :configure, :after do |config|
|
97
|
+
# Deprecate fedora.cert_file, fedora.key_file, fedora.key_pass
|
92
98
|
[:cert_file, :key_file, :key_pass].each do |key|
|
93
99
|
next unless config.fedora[key].present?
|
94
100
|
stack = Kernel.caller.dup
|
@@ -112,7 +118,6 @@ module Dor
|
|
112
118
|
ActiveFedora::SolrService.register
|
113
119
|
ActiveFedora::SolrService.instance.instance_variable_set :@conn, make_solr_connection
|
114
120
|
end
|
115
|
-
|
116
121
|
end
|
117
122
|
|
118
123
|
# Act like an ActiveFedora.configurator
|
@@ -82,6 +82,7 @@ module Dor
|
|
82
82
|
return solr_doc unless doc.root['type']
|
83
83
|
|
84
84
|
preserved_size = 0
|
85
|
+
shelved_size = 0
|
85
86
|
counts = Hash.new(0) # default count is zero
|
86
87
|
resource_type_counts = Hash.new(0) # default count is zero
|
87
88
|
mime_types = ::Set.new
|
@@ -93,6 +94,7 @@ module Dor
|
|
93
94
|
resource.xpath('file').each do |file|
|
94
95
|
counts['content_file'] += 1
|
95
96
|
preserved_size += file['size'].to_i if file['preserve'] == 'yes'
|
97
|
+
shelved_size += file['size'].to_i if file['shelve'] == 'yes'
|
96
98
|
next unless file['shelve'] == 'yes'
|
97
99
|
counts['shelved_file'] += 1
|
98
100
|
first_shelved_image ||= file['id'] if file['id'] =~ /jp2$/
|
@@ -105,6 +107,7 @@ module Dor
|
|
105
107
|
solr_doc['shelved_content_file_count_itsi'] = counts['shelved_file']
|
106
108
|
solr_doc['resource_count_itsi' ] = counts['resource']
|
107
109
|
solr_doc['preserved_size_dbtsi' ] = preserved_size # double (trie) to support very large sizes
|
110
|
+
solr_doc['shelved_size_dbtsi' ] = shelved_size # double (trie) to support very large sizes
|
108
111
|
solr_doc['resource_types_ssim' ] = resource_type_counts.keys if resource_type_counts.size > 0
|
109
112
|
resource_type_counts.each do |key, count|
|
110
113
|
solr_doc["#{key}_resource_count_itsi"] = count
|
@@ -32,6 +32,20 @@ module Dor
|
|
32
32
|
|
33
33
|
def set_read_rights(rights)
|
34
34
|
rightsMetadata.set_read_rights(rights)
|
35
|
+
unshelve_and_unpublish if rights == 'dark'
|
36
|
+
end
|
37
|
+
|
38
|
+
def unshelve_and_unpublish
|
39
|
+
if self.respond_to? :contentMetadata
|
40
|
+
content_ds = datastreams['contentMetadata']
|
41
|
+
unless content_ds.nil?
|
42
|
+
content_ds.ng_xml.xpath('/contentMetadata/resource//file').each_with_index do |file_node, index|
|
43
|
+
content_ds.ng_xml_will_change! if index == 0
|
44
|
+
file_node['publish'] = 'no'
|
45
|
+
file_node['shelve'] = 'no'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
35
49
|
end
|
36
50
|
|
37
51
|
def add_collection(collection_or_druid)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Creates RestClient::Resources for various connections
|
2
|
+
module Dor
|
3
|
+
class RestResourceFactory
|
4
|
+
include Singleton
|
5
|
+
|
6
|
+
# @param type [Symbol] the type of connection to create (e.g. :fedora)
|
7
|
+
# @return [RestClient::Resource]
|
8
|
+
def self.create(type)
|
9
|
+
instance.create(type)
|
10
|
+
end
|
11
|
+
|
12
|
+
# @param type [Symbol] the type of connection to create (e.g. :fedora)
|
13
|
+
# @return [RestClient::Resource]
|
14
|
+
def create(type)
|
15
|
+
RestClient::Resource.new(url_for(type), connection_options)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
# @param type [Symbol] the type of connection to create (e.g. :fedora)
|
21
|
+
# @return [String] the url to connect to.
|
22
|
+
def url_for(type)
|
23
|
+
connection_configuration(type).url
|
24
|
+
end
|
25
|
+
|
26
|
+
# @param type [Symbol] the type of connection to create (e.g. :fedora)
|
27
|
+
# @return [#url] the configuration for the connection
|
28
|
+
def connection_configuration(type)
|
29
|
+
Dor::Config.fetch(type)
|
30
|
+
rescue KeyError
|
31
|
+
raise "ERROR: Unable to find a configuration for #{type}"
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Hash] options for creating a RestClient::Resource
|
35
|
+
def connection_options
|
36
|
+
{}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/dor/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dor-services
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.25.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Klein
|
@@ -14,7 +14,7 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date: 2017-
|
17
|
+
date: 2017-09-25 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: active-fedora
|
@@ -592,6 +592,7 @@ files:
|
|
592
592
|
- config/dev_console_env.rb.example
|
593
593
|
- config/predicate_mappings.yml
|
594
594
|
- lib/dor-services.rb
|
595
|
+
- lib/dor/certificate_authenticated_rest_resource_factory.rb
|
595
596
|
- lib/dor/config.rb
|
596
597
|
- lib/dor/datastreams/administrative_metadata_ds.rb
|
597
598
|
- lib/dor/datastreams/content_metadata_ds.rb
|
@@ -636,6 +637,7 @@ files:
|
|
636
637
|
- lib/dor/models/item.rb
|
637
638
|
- lib/dor/models/set.rb
|
638
639
|
- lib/dor/models/workflow_object.rb
|
640
|
+
- lib/dor/rest_resource_factory.rb
|
639
641
|
- lib/dor/services/cleanup_reset_service.rb
|
640
642
|
- lib/dor/services/cleanup_service.rb
|
641
643
|
- lib/dor/services/digital_stacks_service.rb
|
@@ -682,7 +684,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
682
684
|
version: 1.3.6
|
683
685
|
requirements: []
|
684
686
|
rubyforge_project:
|
685
|
-
rubygems_version: 2.6.
|
687
|
+
rubygems_version: 2.6.12
|
686
688
|
signing_key:
|
687
689
|
specification_version: 4
|
688
690
|
summary: Ruby implmentation of DOR services used by the SULAIR Digital Library
|