Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
5e2316d0
Unverified
Commit
5e2316d0
authored
8 years ago
by
Roeland Jago Douma
Browse files
Options
Downloads
Patches
Plain Diff
Allow multibucket in objectstore
parent
aa56d42f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/private/Files/Mount/ObjectHomeMountProvider.php
+55
-2
55 additions, 2 deletions
lib/private/Files/Mount/ObjectHomeMountProvider.php
lib/private/Files/ObjectStore/Mapper.php
+52
-0
52 additions, 0 deletions
lib/private/Files/ObjectStore/Mapper.php
with
107 additions
and
2 deletions
lib/private/Files/Mount/ObjectHomeMountProvider.php
+
55
−
2
View file @
5e2316d0
...
@@ -52,9 +52,27 @@ class ObjectHomeMountProvider implements IHomeMountProvider {
...
@@ -52,9 +52,27 @@ class ObjectHomeMountProvider implements IHomeMountProvider {
* @return \OCP\Files\Mount\IMountPoint[]
* @return \OCP\Files\Mount\IMountPoint[]
*/
*/
public
function
getHomeMountForUser
(
IUser
$user
,
IStorageFactory
$loader
)
{
public
function
getHomeMountForUser
(
IUser
$user
,
IStorageFactory
$loader
)
{
$config
=
$this
->
multiBucketObjectStore
(
$user
);
if
(
$config
===
null
)
{
$config
=
$this
->
singleBucketObjectStore
(
$user
);
}
if
(
$config
===
null
)
{
return
null
;
}
return
new
MountPoint
(
'\OC\Files\ObjectStore\HomeObjectStoreStorage'
,
'/'
.
$user
->
getUID
(),
$config
[
'arguments'
],
$loader
);
}
/**
* @param IUser $user
* @return array|null
*/
private
function
singleBucketObjectStore
(
IUser
$user
)
{
$config
=
$this
->
config
->
getSystemValue
(
'objectstore'
);
$config
=
$this
->
config
->
getSystemValue
(
'objectstore'
);
if
(
!
is_array
(
$config
))
{
if
(
!
is_array
(
$config
))
{
return
null
;
//fall back to local home provider
return
null
;
}
}
// sanity checks
// sanity checks
...
@@ -68,6 +86,41 @@ class ObjectHomeMountProvider implements IHomeMountProvider {
...
@@ -68,6 +86,41 @@ class ObjectHomeMountProvider implements IHomeMountProvider {
// instantiate object store implementation
// instantiate object store implementation
$config
[
'arguments'
][
'objectstore'
]
=
new
$config
[
'class'
](
$config
[
'arguments'
]);
$config
[
'arguments'
][
'objectstore'
]
=
new
$config
[
'class'
](
$config
[
'arguments'
]);
return
new
MountPoint
(
'\OC\Files\ObjectStore\HomeObjectStoreStorage'
,
'/'
.
$user
->
getUID
(),
$config
[
'arguments'
],
$loader
);
return
$config
;
}
/**
* @param IUser $user
* @return array|null
*/
private
function
multiBucketObjectStore
(
IUser
$user
)
{
$config
=
$this
->
config
->
getSystemValue
(
'objectstore_multibucket'
);
if
(
!
is_array
(
$config
))
{
return
null
;
}
// sanity checks
if
(
empty
(
$config
[
'class'
]))
{
\OCP\Util
::
writeLog
(
'files'
,
'No class given for objectstore'
,
\OCP\Util
::
ERROR
);
}
if
(
!
isset
(
$config
[
'arguments'
]))
{
$config
[
'arguments'
]
=
[];
}
$config
[
'arguments'
][
'user'
]
=
$user
;
/*
* Use any provided bucket argument as prefix
* and add the mapping from username => bucket
*/
if
(
!
isset
(
$config
[
'arguments'
][
'bucket'
]))
{
$config
[
'arguments'
][
'bucket'
]
=
''
;
}
$mapper
=
new
\OC\Files\ObjectStore\Mapper
(
$user
);
$config
[
'arguments'
][
'bucket'
]
.
=
$mapper
->
getBucket
();
// instantiate object store implementation
$config
[
'arguments'
][
'objectstore'
]
=
new
$config
[
'class'
](
$config
[
'arguments'
]);
return
$config
;
}
}
}
}
This diff is collapsed.
Click to expand it.
lib/private/Files/ObjectStore/Mapper.php
0 → 100644
+
52
−
0
View file @
5e2316d0
<?php
/**
* @author Roeland Jago Douma <rullzer@owncloud.com>
*
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace
OC\Files\ObjectStore
;
use
OCP\IUser
;
/**
* Class Mapper
*
* @package OC\Files\ObjectStore
*
* Map a user to a bucket.
*/
class
Mapper
{
/** @var IUser */
private
$user
;
/**
* Mapper constructor.
*
* @param IUser $user
*/
public
function
__construct
(
IUser
$user
)
{
$this
->
user
=
$user
;
}
/**
* @return string
*/
public
function
getBucket
()
{
$hash
=
md5
(
$this
->
user
->
getUID
());
return
substr
(
$hash
,
0
,
3
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment