Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit fbe83f2

Browse files
author
Jamie Snape
committed
Add missing googleappengine module
1 parent 88f6bed commit fbe83f2

File tree

8 files changed

+375
-0
lines changed

8 files changed

+375
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/*=========================================================================
3+
Midas Server
4+
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
5+
All rights reserved.
6+
For more information visit http://www.kitware.com/.
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** App controller for the googleappengine module */
22+
class Googleappengine_AppController extends MIDAS_GlobalModule
23+
{
24+
/** @var string */
25+
public $moduleName = 'googleappengine';
26+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/*=========================================================================
3+
Midas Server
4+
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
5+
All rights reserved.
6+
For more information visit http://www.kitware.com/.
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** Bootstrap for the googleappengine module. */
22+
class Googleappengine_Bootstrap extends Zend_Application_Module_Bootstrap
23+
{
24+
/** @var string */
25+
public $moduleName = 'googleappengine';
26+
27+
/** Initialize a stream context for the gs stream wrapper. */
28+
protected function _initStreamContext()
29+
{
30+
$options = array('gs' => array('connection_timeout_seconds' => 60));
31+
stream_context_set_default($options);
32+
}
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/*=========================================================================
3+
Midas Server
4+
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
5+
All rights reserved.
6+
For more information visit http://www.kitware.com/.
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
require_once BASE_PATH.'/modules/api/library/APIEnabledNotification.php';
22+
23+
/** Notification manager for the googleappengine module. */
24+
class Googleappengine_Notification extends ApiEnabled_Notification
25+
{
26+
/** @var string */
27+
public $moduleName = 'googleappengine';
28+
29+
/** Initialize the notification process. */
30+
public function init()
31+
{
32+
$this->enableWebAPI($this->moduleName);
33+
}
34+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; Midas Server. Copyright Kitware SAS. Licensed under the Apache License 2.0.
2+
3+
[global]
4+
fullname = "Google App Engine"
5+
description = "Enables support for Google App Engine"
6+
category = "Core"
7+
dependencies = api
8+
uuid = "eab90641-693c-44df-9be2-e3f306d3ae2c"
9+
version = "1.0.0"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/*=========================================================================
3+
Midas Server
4+
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
5+
All rights reserved.
6+
For more information visit http://www.kitware.com/.
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** API upload controller for the googleappengine module. */
22+
class Apigoogleappengine_UploadController extends ApiController
23+
{
24+
/** @var string */
25+
public $moduleName = 'googleappengine';
26+
27+
/** Handle HTTP POST requests. */
28+
public function postAction()
29+
{
30+
$apiFunctions = array('callback' => 'callback', 'uploadtoken' => 'uploadToken');
31+
$this->_genericAction($this->_request->getParams(), $this->_request->getControllerName(), 'post', $apiFunctions, $this->moduleName);
32+
}
33+
34+
/** Handle HTTP OPTIONS requests. */
35+
public function optionsAction()
36+
{
37+
$this->_response->setHeader('Allow', 'OPTIONS, POST');
38+
}
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/*=========================================================================
3+
Midas Server
4+
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
5+
All rights reserved.
6+
For more information visit http://www.kitware.com/.
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** API component for the googleappengine module. */
22+
class Googleappengine_ApiComponent extends AppComponent
23+
{
24+
/** @var string */
25+
public $moduleName = 'googleappengine';
26+
27+
/**
28+
* Generate an upload token and upload URL.
29+
*
30+
* @param array $args
31+
* @return array
32+
*/
33+
public function uploadGeneratetoken($args)
34+
{
35+
/** @var Googleappengine_ApiuploadComponent $apiuploadComponent */
36+
$apiuploadComponent = MidasLoader::loadComponent('Apiupload', $this->moduleName);
37+
return $apiuploadComponent->uploadToken($args);
38+
}
39+
}
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<?php
2+
/*=========================================================================
3+
Midas Server
4+
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
5+
All rights reserved.
6+
For more information visit http://www.kitware.com/.
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
use google\appengine\api\cloud_storage\CloudStorageTools;
22+
23+
/** API upload component for the googleappengine module. */
24+
class Googleappengine_ApiuploadComponent extends AppComponent
25+
{
26+
/**
27+
* Generate an upload token and Google Cloud Storage upload URL.
28+
*
29+
* @param array $args
30+
* @return array
31+
*/
32+
public function uploadToken($args)
33+
{
34+
/** @var ApisystemComponent $apisystemComponent */
35+
$apisystemComponent = MidasLoader::loadComponent('Apisystem');
36+
$data = $apisystemComponent->uploadGeneratetoken($args);
37+
$data['url'] = CloudStorageTools::createUploadUrl('/rest/googleappengine/upload/callback');
38+
39+
return $data;
40+
}
41+
42+
/**
43+
* Google Cloud Storage upload callback.
44+
*
45+
* @param array $args
46+
* @return array
47+
* @throws Exception
48+
*/
49+
public function callback($args)
50+
{
51+
/** @var ApihelperComponent $apihelperComponent */
52+
$apihelperComponent = MidasLoader::loadComponent('Apihelper');
53+
$apihelperComponent->validateParams($args, array('uploadtoken'));
54+
55+
if (!Zend_Controller_Front::getInstance()->getRequest()->isPost()) {
56+
throw new Exception('POST method required', MIDAS_HTTP_ERROR);
57+
}
58+
59+
$uploadToken = $args['uploadtoken'];
60+
$path = UtilityComponent::getTempDirectory().'/'.$uploadToken;
61+
62+
if (!file_exists($path)) {
63+
throw new Exception(
64+
'Invalid upload token '.$uploadToken, MIDAS_INVALID_UPLOAD_TOKEN
65+
);
66+
}
67+
68+
@rmdir($path);
69+
list($userId, $itemId) = explode('/', $uploadToken);
70+
71+
/** @var UserModel $userModel */
72+
$userModel = MidasLoader::loadModel('User');
73+
$userDao = $userModel->load($userId);
74+
75+
if ($userDao === false) {
76+
throw new Exception('Invalid user id from upload token', MIDAS_INVALID_PARAMETER);
77+
}
78+
79+
/** @var ItemModel $itemModel */
80+
$itemModel = MidasLoader::loadModel('Item');
81+
$itemDao = $itemModel->load($itemId);
82+
83+
if ($itemDao === false) {
84+
throw new Exception('Unable to find item', MIDAS_INVALID_PARAMETER);
85+
}
86+
87+
if (!$itemModel->policyCheck($itemDao, $userDao, MIDAS_POLICY_WRITE)) {
88+
throw new Exception('Permission error', MIDAS_INVALID_POLICY);
89+
}
90+
91+
if (array_key_exists('revision', $args)) {
92+
if (strtolower($args['revision']) == 'head') {
93+
$revision = $itemModel->getLastRevision($itemDao);
94+
} else {
95+
$revision = $itemModel->getRevision($itemDao, $args['revision']);
96+
if ($revision == false) {
97+
throw new Exception('Unable to find revision', MIDAS_INVALID_PARAMETER);
98+
}
99+
}
100+
}
101+
102+
if (!array_key_exists('file', $args) || !array_key_exists('file', $_FILES)
103+
) {
104+
throw new Exception('Parameter file is not defined', MIDAS_INVALID_PARAMETER);
105+
}
106+
107+
$file = $_FILES['file'];
108+
$name = $file['name'];
109+
$tmpName = $file['tmp_name'];
110+
$size = filesize($tmpName);
111+
112+
$folderDaos = $itemDao->getFolders();
113+
114+
/** @var FolderDao $folderDao */
115+
$folderDao = $folderDaos[0];
116+
117+
$validations = Zend_Registry::get('notifier')->callback(
118+
'CALLBACK_CORE_VALIDATE_UPLOAD',
119+
array(
120+
'filename' => $name,
121+
'size' => $size,
122+
'path' => $tmpName,
123+
'folderId' => $folderDao->getFolderId(),
124+
)
125+
);
126+
127+
foreach ($validations as $validation) {
128+
if (!$validation['status']) {
129+
throw new Exception($validation['message'], MIDAS_INVALID_POLICY);
130+
}
131+
}
132+
133+
$license = isset($args['license']) ? $args['license'] : null;
134+
$checksum = md5_file($tmpName);
135+
$revisionNumber = null;
136+
137+
if (isset($revision) && $revision !== false) {
138+
$revisionNumber = $revision->getRevision();
139+
}
140+
141+
if (isset($args['changes'])) {
142+
$changes = $args['changes'];
143+
} elseif ($revisionNumber === 1) {
144+
$changes = 'Initial revision';
145+
} else {
146+
$changes = '';
147+
}
148+
149+
move_uploaded_file($tmpName, $path);
150+
151+
/** @var UploadComponent $uploadComponent */
152+
$uploadComponent = MidasLoader::loadComponent('Upload');
153+
$itemDao = $uploadComponent->createNewRevision(
154+
$userDao,
155+
$name,
156+
$path,
157+
$changes,
158+
$itemDao->getKey(),
159+
$revisionNumber,
160+
$license,
161+
$checksum,
162+
false,
163+
$size
164+
);
165+
166+
if ($itemDao === false) {
167+
throw new Exception('Upload failed', MIDAS_INTERNAL_ERROR);
168+
}
169+
170+
return $itemDao->toArray();
171+
}
172+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#=============================================================================
2+
# Midas Server
3+
# Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
4+
# All rights reserved.
5+
# For more information visit http://www.kitware.com/.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0.txt
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#=============================================================================
19+
20+
set(module_name googleappengine)
21+
to_titlecase(${module_name} module_name_titlecase)
22+
23+
add_midas_style_test(Style${module_name_titlecase} ${CMAKE_SOURCE_DIR}/modules/${module_name})

0 commit comments

Comments
 (0)