Skip to content

Commit 85d3266

Browse files
authored
Merge pull request #89 from CollaboraOnline/discovery-cache
Add cache for the discovery loading
2 parents 1b8f7e8 + 43232d2 commit 85d3266

26 files changed

+1289
-402
lines changed

LICENSE-EUPL.txt

+194
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
The license below applies only to those files that explicitly mention the EUPL license in their header.
2+
3+
----------------
4+
5+
EUROPEAN UNION PUBLIC LICENCE v. 1.2
6+
EUPL © the European Union 2007, 2016
7+
8+
This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined below) which is provided under the
9+
terms of this Licence. Any use of the Work, other than as authorised under this Licence is prohibited (to the extent such
10+
use is covered by a right of the copyright holder of the Work).
11+
The Work is provided under the terms of this Licence when the Licensor (as defined below) has placed the following
12+
notice immediately following the copyright notice for the Work:
13+
Licensed under the EUPL
14+
or has expressed by any other means his willingness to license under the EUPL.
15+
16+
1.Definitions
17+
In this Licence, the following terms have the following meaning:
18+
— ‘The Licence’:this Licence.
19+
— ‘The Original Work’:the work or software distributed or communicated by the Licensor under this Licence, available
20+
as Source Code and also as Executable Code as the case may be.
21+
— ‘Derivative Works’:the works or software that could be created by the Licensee, based upon the Original Work or
22+
modifications thereof. This Licence does not define the extent of modification or dependence on the Original Work
23+
required in order to classify a work as a Derivative Work; this extent is determined by copyright law applicable in
24+
the country mentioned in Article 15.
25+
— ‘The Work’:the Original Work or its Derivative Works.
26+
— ‘The Source Code’:the human-readable form of the Work which is the most convenient for people to study and
27+
modify.
28+
— ‘The Executable Code’:any code which has generally been compiled and which is meant to be interpreted by
29+
a computer as a program.
30+
— ‘The Licensor’:the natural or legal person that distributes or communicates the Work under the Licence.
31+
— ‘Contributor(s)’:any natural or legal person who modifies the Work under the Licence, or otherwise contributes to
32+
the creation of a Derivative Work.
33+
— ‘The Licensee’ or ‘You’:any natural or legal person who makes any usage of the Work under the terms of the
34+
Licence.
35+
— ‘Distribution’ or ‘Communication’:any act of selling, giving, lending, renting, distributing, communicating,
36+
transmitting, or otherwise making available, online or offline, copies of the Work or providing access to its essential
37+
functionalities at the disposal of any other natural or legal person.
38+
39+
2.Scope of the rights granted by the Licence
40+
The Licensor hereby grants You a worldwide, royalty-free, non-exclusive, sublicensable licence to do the following, for
41+
the duration of copyright vested in the Original Work:
42+
— use the Work in any circumstance and for all usage,
43+
— reproduce the Work,
44+
— modify the Work, and make Derivative Works based upon the Work,
45+
— communicate to the public, including the right to make available or display the Work or copies thereof to the public
46+
and perform publicly, as the case may be, the Work,
47+
— distribute the Work or copies thereof,
48+
— lend and rent the Work or copies thereof,
49+
— sublicense rights in the Work or copies thereof.
50+
Those rights can be exercised on any media, supports and formats, whether now known or later invented, as far as the
51+
applicable law permits so.
52+
In the countries where moral rights apply, the Licensor waives his right to exercise his moral right to the extent allowed
53+
by law in order to make effective the licence of the economic rights here above listed.
54+
The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to any patents held by the Licensor, to the
55+
extent necessary to make use of the rights granted on the Work under this Licence.
56+
57+
3.Communication of the Source Code
58+
The Licensor may provide the Work either in its Source Code form, or as Executable Code. If the Work is provided as
59+
Executable Code, the Licensor provides in addition a machine-readable copy of the Source Code of the Work along with
60+
each copy of the Work that the Licensor distributes or indicates, in a notice following the copyright notice attached to
61+
the Work, a repository where the Source Code is easily and freely accessible for as long as the Licensor continues to
62+
distribute or communicate the Work.
63+
64+
4.Limitations on copyright
65+
Nothing in this Licence is intended to deprive the Licensee of the benefits from any exception or limitation to the
66+
exclusive rights of the rights owners in the Work, of the exhaustion of those rights or of other applicable limitations
67+
thereto.
68+
69+
5.Obligations of the Licensee
70+
The grant of the rights mentioned above is subject to some restrictions and obligations imposed on the Licensee. Those
71+
obligations are the following:
72+
73+
Attribution right: The Licensee shall keep intact all copyright, patent or trademarks notices and all notices that refer to
74+
the Licence and to the disclaimer of warranties. The Licensee must include a copy of such notices and a copy of the
75+
Licence with every copy of the Work he/she distributes or communicates. The Licensee must cause any Derivative Work
76+
to carry prominent notices stating that the Work has been modified and the date of modification.
77+
78+
Copyleft clause: If the Licensee distributes or communicates copies of the Original Works or Derivative Works, this
79+
Distribution or Communication will be done under the terms of this Licence or of a later version of this Licence unless
80+
the Original Work is expressly distributed only under this version of the Licence — for example by communicating
81+
‘EUPL v. 1.2 only’. The Licensee (becoming Licensor) cannot offer or impose any additional terms or conditions on the
82+
Work or Derivative Work that alter or restrict the terms of the Licence.
83+
84+
Compatibility clause: If the Licensee Distributes or Communicates Derivative Works or copies thereof based upon both
85+
the Work and another work licensed under a Compatible Licence, this Distribution or Communication can be done
86+
under the terms of this Compatible Licence. For the sake of this clause, ‘Compatible Licence’ refers to the licences listed
87+
in the appendix attached to this Licence. Should the Licensee's obligations under the Compatible Licence conflict with
88+
his/her obligations under this Licence, the obligations of the Compatible Licence shall prevail.
89+
90+
Provision of Source Code: When distributing or communicating copies of the Work, the Licensee will provide
91+
a machine-readable copy of the Source Code or indicate a repository where this Source will be easily and freely available
92+
for as long as the Licensee continues to distribute or communicate the Work.
93+
Legal Protection: This Licence does not grant permission to use the trade names, trademarks, service marks, or names
94+
of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and
95+
reproducing the content of the copyright notice.
96+
97+
6.Chain of Authorship
98+
The original Licensor warrants that the copyright in the Original Work granted hereunder is owned by him/her or
99+
licensed to him/her and that he/she has the power and authority to grant the Licence.
100+
Each Contributor warrants that the copyright in the modifications he/she brings to the Work are owned by him/her or
101+
licensed to him/her and that he/she has the power and authority to grant the Licence.
102+
Each time You accept the Licence, the original Licensor and subsequent Contributors grant You a licence to their contributions
103+
to the Work, under the terms of this Licence.
104+
105+
7.Disclaimer of Warranty
106+
The Work is a work in progress, which is continuously improved by numerous Contributors. It is not a finished work
107+
and may therefore contain defects or ‘bugs’ inherent to this type of development.
108+
For the above reason, the Work is provided under the Licence on an ‘as is’ basis and without warranties of any kind
109+
concerning the Work, including without limitation merchantability, fitness for a particular purpose, absence of defects or
110+
errors, accuracy, non-infringement of intellectual property rights other than copyright as stated in Article 6 of this
111+
Licence.
112+
This disclaimer of warranty is an essential part of the Licence and a condition for the grant of any rights to the Work.
113+
114+
8.Disclaimer of Liability
115+
Except in the cases of wilful misconduct or damages directly caused to natural persons, the Licensor will in no event be
116+
liable for any direct or indirect, material or moral, damages of any kind, arising out of the Licence or of the use of the
117+
Work, including without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, loss
118+
of data or any commercial damage, even if the Licensor has been advised of the possibility of such damage. However,
119+
the Licensor will be liable under statutory product liability laws as far such laws apply to the Work.
120+
121+
9.Additional agreements
122+
While distributing the Work, You may choose to conclude an additional agreement, defining obligations or services
123+
consistent with this Licence. However, if accepting obligations, You may act only on your own behalf and on your sole
124+
responsibility, not on behalf of the original Licensor or any other Contributor, and only if You agree to indemnify,
125+
defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against such Contributor by
126+
the fact You have accepted any warranty or additional liability.
127+
128+
10.Acceptance of the Licence
129+
The provisions of this Licence can be accepted by clicking on an icon ‘I agree’ placed under the bottom of a window
130+
displaying the text of this Licence or by affirming consent in any other similar way, in accordance with the rules of
131+
applicable law. Clicking on that icon indicates your clear and irrevocable acceptance of this Licence and all of its terms
132+
and conditions.
133+
Similarly, you irrevocably accept this Licence and all of its terms and conditions by exercising any rights granted to You
134+
by Article 2 of this Licence, such as the use of the Work, the creation by You of a Derivative Work or the Distribution
135+
or Communication by You of the Work or copies thereof.
136+
137+
11.Information to the public
138+
In case of any Distribution or Communication of the Work by means of electronic communication by You (for example,
139+
by offering to download the Work from a remote location) the distribution channel or media (for example, a website)
140+
must at least provide to the public the information requested by the applicable law regarding the Licensor, the Licence
141+
and the way it may be accessible, concluded, stored and reproduced by the Licensee.
142+
143+
12.Termination of the Licence
144+
The Licence and the rights granted hereunder will terminate automatically upon any breach by the Licensee of the terms
145+
of the Licence.
146+
Such a termination will not terminate the licences of any person who has received the Work from the Licensee under
147+
the Licence, provided such persons remain in full compliance with the Licence.
148+
149+
13.Miscellaneous
150+
Without prejudice of Article 9 above, the Licence represents the complete agreement between the Parties as to the
151+
Work.
152+
If any provision of the Licence is invalid or unenforceable under applicable law, this will not affect the validity or
153+
enforceability of the Licence as a whole. Such provision will be construed or reformed so as necessary to make it valid
154+
and enforceable.
155+
The European Commission may publish other linguistic versions or new versions of this Licence or updated versions of
156+
the Appendix, so far this is required and reasonable, without reducing the scope of the rights granted by the Licence.
157+
New versions of the Licence will be published with a unique version number.
158+
All linguistic versions of this Licence, approved by the European Commission, have identical value. Parties can take
159+
advantage of the linguistic version of their choice.
160+
161+
14.Jurisdiction
162+
Without prejudice to specific agreement between parties,
163+
— any litigation resulting from the interpretation of this License, arising between the European Union institutions,
164+
bodies, offices or agencies, as a Licensor, and any Licensee, will be subject to the jurisdiction of the Court of Justice
165+
of the European Union, as laid down in article 272 of the Treaty on the Functioning of the European Union,
166+
— any litigation arising between other parties and resulting from the interpretation of this License, will be subject to
167+
the exclusive jurisdiction of the competent court where the Licensor resides or conducts its primary business.
168+
169+
15.Applicable Law
170+
Without prejudice to specific agreement between parties,
171+
— this Licence shall be governed by the law of the European Union Member State where the Licensor has his seat,
172+
resides or has his registered office,
173+
— this licence shall be governed by Belgian law if the Licensor has no seat, residence or registered office inside
174+
a European Union Member State.
175+
176+
177+
Appendix
178+
179+
‘Compatible Licences’ according to Article 5 EUPL are:
180+
— GNU General Public License (GPL) v. 2, v. 3
181+
— GNU Affero General Public License (AGPL) v. 3
182+
— Open Software License (OSL) v. 2.1, v. 3.0
183+
— Eclipse Public License (EPL) v. 1.0
184+
— CeCILL v. 2.0, v. 2.1
185+
— Mozilla Public Licence (MPL) v. 2
186+
— GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
187+
— Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for works other than software
188+
— European Union Public Licence (EUPL) v. 1.1, v. 1.2
189+
— Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong Reciprocity (LiLiQ-R+).
190+
191+
The European Commission may update this Appendix to later versions of the above licences without producing
192+
a new version of the EUPL, as long as they provide the rights granted in Article 2 of this Licence and protect the
193+
covered Source Code from exclusive appropriation.
194+
All other changes or additions to this Appendix require the production of a new EUPL version.

collabora_online.install

+5-6
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212

1313
declare(strict_types=1);
1414

15-
use Drupal\collabora_online\Cool\CollaboraDiscoveryFetcherInterface;
16-
use Drupal\collabora_online\Cool\CollaboraDiscoveryInterface;
15+
use Drupal\collabora_online\Discovery\DiscoveryFetcherInterface;
1716
use Drupal\collabora_online\Exception\CollaboraNotAvailableException;
1817

1918
/**
@@ -40,10 +39,12 @@ function collabora_online_requirements(string $phase): array {
4039
}
4140

4241
// Check if Collabora Online server is configured and can be reached.
42+
/** @var \Drupal\collabora_online\Discovery\DiscoveryFetcherInterface $fetcher */
43+
$fetcher = \Drupal::service(DiscoveryFetcherInterface::class);
4344
try {
44-
\Drupal::service(CollaboraDiscoveryFetcherInterface::class)->getDiscoveryXml();
45+
$discovery = $fetcher->getDiscovery();
4546
}
46-
catch (CollaboraNotAvailableException $e) {
47+
catch (CollaboraNotAvailableException) {
4748
$requirements['collabora_online_settings_cool_server'] = [
4849
'title' => t('Collabora Online server'),
4950
'description' => t('The Collabora Online server discovery.xml could not be accessed. Check the logs for more information.'),
@@ -53,8 +54,6 @@ function collabora_online_requirements(string $phase): array {
5354
return $requirements;
5455
}
5556

56-
/** @var \Drupal\collabora_online\Cool\CollaboraDiscoveryInterface $discovery */
57-
$discovery = \Drupal::service(CollaboraDiscoveryInterface::class);
5857
if (
5958
($cool_settings['wopi_proof'] ?? TRUE) === TRUE &&
6059
$discovery->getProofKey() === NULL &&

collabora_online.post_update.php

+9
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,12 @@ function collabora_online_post_update_add_new_file_interval(): void {
3131
->set('cool.new_file_interval', 60)
3232
->save();
3333
}
34+
35+
/**
36+
* Sets an initial value for the new 'discovery_cache_ttl' setting.
37+
*/
38+
function collabora_online_post_update_add_discovery_cache_ttl(): void {
39+
\Drupal::configFactory()->getEditable('collabora_online.settings')
40+
->set('cool.discovery_cache_ttl', 3600)
41+
->save();
42+
}

collabora_online.services.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ services:
55
logger.channel.collabora_online:
66
parent: logger.channel_base
77
arguments: ['cool']
8-
Drupal\collabora_online\Cool\CollaboraDiscoveryFetcherInterface:
9-
class: Drupal\collabora_online\Cool\CollaboraDiscoveryFetcher
10-
Drupal\collabora_online\Cool\CollaboraDiscoveryInterface:
11-
class: Drupal\collabora_online\Cool\CollaboraDiscovery
8+
Drupal\collabora_online\Discovery\DiscoveryFetcherInterface:
9+
class: Drupal\collabora_online\Discovery\DiscoveryFetcher
1210
Drupal\collabora_online\Jwt\JwtTranscoderInterface:
1311
class: Drupal\collabora_online\Jwt\JwtTranscoder
1412
Drupal\collabora_online\MediaHelperInterface:

config/install/collabora_online.settings.yml

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
cool:
22
# The address of the COOL server.
33
server: https://localhost:9980/
4+
# Cache the discovery.xml for 1h by default.
5+
# This assumes that a new proof key is generated once per hour or less.
6+
discovery_cache_ttl: 3600
47
# The WOPI base
58
wopi_base: https://localhost/
69
# The JWT key id.

config/schema/collabora_online.schema.yml

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ collabora_online.settings:
99
server:
1010
type: uri
1111
label: 'The address of the COOL server.'
12+
discovery_cache_ttl:
13+
type: integer
14+
label: 'Discovery cache TTL'
15+
constraints:
16+
Range:
17+
min: 0
1218
wopi_base:
1319
type: uri
1420
label: 'The WOPI base'

src/Access/WopiProofAccessCheck.php

+19-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
namespace Drupal\collabora_online\Access;
1616

17-
use Drupal\collabora_online\Cool\CollaboraDiscoveryInterface;
17+
use Drupal\collabora_online\Discovery\DiscoveryFetcherInterface;
18+
use Drupal\collabora_online\Exception\CollaboraNotAvailableException;
1819
use Drupal\collabora_online\Util\DotNetTime;
1920
use Drupal\Component\Datetime\TimeInterface;
2021
use Drupal\Core\Access\AccessResult;
@@ -40,7 +41,7 @@
4041
class WopiProofAccessCheck implements AccessInterface {
4142

4243
public function __construct(
43-
protected readonly CollaboraDiscoveryInterface $discovery,
44+
protected readonly DiscoveryFetcherInterface $discoveryFetcher,
4445
#[Autowire(service: 'logger.channel.collabora_online')]
4546
protected readonly LoggerInterface $logger,
4647
protected readonly ConfigFactoryInterface $configFactory,
@@ -127,7 +128,16 @@ protected function checkTimeout(Request $request): AccessResult {
127128
* An access result without cache metadata.
128129
*/
129130
protected function checkProof(Request $request): AccessResult {
130-
$keys = $this->getKeys();
131+
try {
132+
$keys = $this->getKeys();
133+
}
134+
catch (CollaboraNotAvailableException $e) {
135+
$log_message = "Failure in WOPI proof check:<br>\n"
136+
. Error::DEFAULT_ERROR_MESSAGE;
137+
$log_args = Error::decodeException($e);
138+
$this->logger->error($log_message, $log_args);
139+
return AccessResult::forbidden('Cannot get discovery for proof keys.');
140+
}
131141
if (!isset($keys['current'])) {
132142
return AccessResult::forbidden('Missing or incomplete WOPI proof keys.');
133143
}
@@ -189,14 +199,18 @@ protected function getSubject(Request $request): string {
189199
* @return array<'current'|'old', \phpseclib3\Crypt\RSA\PublicKey>
190200
* Current and old public key, or just the current if they are the same, or
191201
* empty array if none found.
202+
*
203+
* @throws \Drupal\collabora_online\Exception\CollaboraNotAvailableException
204+
* The discovery cannot be loaded.
192205
*/
193206
protected function getKeys(): array {
207+
$discovery = $this->discoveryFetcher->getDiscovery();
194208
// Get current and old key.
195209
// Remove empty values.
196210
// If both are the same, keep only the current one.
197211
$public_keys = array_unique(array_filter([
198-
'current' => $this->discovery->getProofKey(),
199-
'old' => $this->discovery->getProofKeyOld(),
212+
'current' => $discovery->getProofKey(),
213+
'old' => $discovery->getProofKeyOld(),
200214
]));
201215
$key_objects = [];
202216
foreach ($public_keys as $key_name => $key_str) {

0 commit comments

Comments
 (0)