Skip to content

[ext storage] Rely on numeric_id, store config in DB, improve config format #11261

Closed

Description

@PVince81

Code like this is just unreadable and difficult to extend: https://github.com/owncloud/core/blob/master/apps/files_external/lib/config.php#L503

The external storage mount points are stored with multi-dimensional arrays:

$mounts[$mountType][$applicableUsers][$mountPointName][$extraField]

This needs a lot of code gymnastics to get to the right information and it also increases the risk of misunderstanding and introducing bugs this way.

I suggest to provide a new class to contain that data, like:

class MountPoint {
    private $type; // personal or system
    private $applicable; // array of users/groups to which the mount point applies
    private $mountPath; // path to the mount point in the user's file system
    private $priority;
    // ...
}

Hopefully in OC8...

@icewind1991 @Xenopathic

Activity

  1. PVince81 commented on Sep 23, 2014

    @PVince81
    ContributorAuthor

    This is especially important if external storage is going to play a more important role in the future.

    @MTRichards @craigpg @karlitschek

    CC @fernandoruiz @jmaciasportela

  2. PVince81 commented on Sep 23, 2014

    @PVince81
    ContributorAuthor

    This is just half of the pain.
    The other half is the way how the config is stored in mount.json.
    If you create a SFTP storage for two users, the config looks like this:

        "user": {
            "user1": {
                "\/$user\/files\/sftp": {
                    "class": "\\OC\\Files\\Storage\\SFTP",
                    "options": {
                        "host": "localhost",
                        "user": "vincent",
                        "password": "",
                        "root": "\/home\/vincent\/temp\/sftpmount",
                        "password_encrypted": "MTAxMmZiYmMxNGRmYjM3ZH8hV2NliG6z0wi7lCxy+tY="
                    },
                    "priority": 100
                }
            },
            "root": {
                "\/$user\/files\/sftp": {
                    "class": "\\OC\\Files\\Storage\\SFTP",
                    "options": {
                        "host": "localhost",
                        "user": "vincent",
                        "password": "",
                        "root": "\/home\/vincent\/temp\/sftpmount",
                        "password_encrypted": "Y2JmMTU3ZWJmNjczZWQzZRvQv08Iz9oXgGVQPaowiRo="
                    },
                    "priority": 100
                }
            }
        }
    

    The config is stored multiple times for every user/group.
    There is logic to magically merge the config to show as a single row in the UI... it merges the configs if all the parameters (including password) are the same. Else they will appear as separate entries.

  3. karlitschek commented on Sep 23, 2014

    @karlitschek
    Contributor

    yes. agreed

  4. added this to the backlog milestone on Sep 23, 2014
  5. RobinMcCorkell commented on Sep 23, 2014

    @RobinMcCorkell
    Contributor

    The multi-stacked arrays are very difficult to handle, I agree. I do have a suggestion for the JSON output though - instead of storing it as 'applicable type -> applicable -> storage -> class/options...', store it as 'storage -> class/options/applicable...'. For example:

      "\/$user\/files\/sftp": {
          "class": "\\OC\\Files\\Storage\\SFTP",
          "options": {
              "host": "localhost",
              "user": "vincent",
              "password": "",
              "root": "\/home\/vincent\/temp\/sftpmount",
              "password_encrypted": "MTAxMmZiYmMxNGRmYjM3ZH8hV2NliG6z0wi7lCxy+tY="
          },
          "priority": 100,
          "applicable": {
              "user": [
                  "user1",
                  "root"
              ]
          }
      }
    

    The only drawback is that finding applicable mount points becomes harder - the code needs to iterate through every storage and check if it is applicable.

    Alternatively, what about storing this in the database? oc_files_external_storages to define the storages, oc_files_external_params to define parameters of each storage, and oc_files_external_map to map the storages to their applicable users/groups:

    oc_files_external_storages
    ==========================
    id | class
    -------------------------------
    0  | \\OC\\Files\\Storage\\SFTP
    
    
    oc_files_external_params
    ========================
    id | storage_id | name               | value
    ---------------------------------------------------------------------------------
    0  | 0          | host               | localhost
    1  | 0          | user               | vincent
    2  | 0          | password           | NULL
    3  | 0          | root               | \/home\/vincent\/temp\/sftpmount
    4  | 0          | password_encrypted | MTAxMmZiYmMxNGRmYjM3ZH8hV2NliG6z0wi7lCxy+tY=
    
    oc_files_external_map
    =====================
    id | storage_id | type   | value
    ---------------------------------------
    0  | 0          | user   | user1
    1  | 0          | user   | root
    

    Or something to that effect

  6. PVince81 commented on Sep 23, 2014

    @PVince81
    ContributorAuthor

    Storing in the database might make more sense, yes. It was already mentioned several times in discussions. I also like that you added the storage column which can be mapped to the matching oc_storages table instead of doing the usual "generate the storage id by concatenning settings" magic to find the matching entry.

  7. modified the milestones: , backlog on Oct 28, 2014
  8. PVince81 commented on Oct 31, 2014

    @PVince81
    ContributorAuthor

    Related: #11830 about the unstable storage string id.

  9. PVince81 commented on Oct 31, 2014

    @PVince81
    ContributorAuthor

    I think oc_files_external_storage could simply be the existing oc_storages table, but extended with a type column.

    We'd simply use the numeric_id from oc_storages to map to the configs.

  10. PVince81 commented on Oct 31, 2014

    @PVince81
    ContributorAuthor

    Updated proposal:

    oc_storages

    id storage_type scope
    0 external system
    1 external user
    2 home user

    oc_files_external_params

    id storage_id name value
    0 0 type sftp
    1 0 host localhost
    2 0 user vincent
    3 0 password NULL
    4 0 root /home/vincent/temp/sftpmount
    5 0 password_encrypted MTAxMmZiYmMxNGRmYjM3ZH8hV2NliG6z0wi7lCxy+tY=
    6 1 type smb
    7 1 host localhost
    8 1 user vincent
    9 1 password NULL
    10 1 root /home/vincent/temp/sftpmount
    11 1 password_encrypted MTAxMmZiYmMxNGRmYjM3ZH8hV2NliG6z0wi7lCxy+tY=

    oc_files_external_applicable

    id storage_id type value
    0 0 user user1
    1 0 user root
    2 0 group group1
    3 1 user user2
  11. 30 remaining items

  12. PVince81 commented on Aug 10, 2015

    @PVince81
    ContributorAuthor

    This is the ticket for moving mount.json to the DB. As discussed with @DeepDiver1975, moving to 8.2.

    From what I heard @Xenopathic will work on it soon, so assigning him.

  13. PVince81 commented on Aug 10, 2015

    @PVince81
    ContributorAuthor

    I hope we can totally get rid of the storage id string in the process as it will solve many issues.

  14. PVince81 commented on Aug 10, 2015

    @PVince81
    ContributorAuthor

    @icewind1991 do you think it's possible in any way to make mounting the storages depend on the numeric id instead of storage string id ? How complex would the change be ?

  15. icewind1991 commented on Aug 10, 2015

    @icewind1991
    Contributor

    I think the main usage of the string id atm is the storage<-> cache mapping, currently a storage calculates it's string id, looks up the numeric id and uses that for cache operations.

    We would need to adjust every point a where a mount is created and inject the numeric storage id (non trivial for non-files_external since we dont keep track of numeric storage id's for things like home storages)

  16. RobinMcCorkell commented on Aug 10, 2015

    @RobinMcCorkell
    Contributor

    We should try and get rid of getId() on the storage implementation itself, it's awkward to have to construct the storage to get its ID. That leads to easy-to-break code such as https://github.com/owncloud/core/blob/master/apps/files_external/lib/config.php#L971-L980. Especially with session-based credentials, some storages will reject being constructed entirely, so we can never correctly get the ID of such storages.

  17. modified the milestones: , on Sep 10, 2015
  18. PVince81 commented on Nov 6, 2015

    @PVince81
    ContributorAuthor

    Moving the the database as a first step (independent from old storage ids, for now): #20354

  19. PVince81 commented on Dec 18, 2015

    @PVince81
    ContributorAuthor

    Also the new oc_mounts table will make it possible to do reverse lookups: #15166

  20. PVince81 commented on Feb 12, 2016

    @PVince81
    ContributorAuthor

    9.0 code has the storages in the database and a mounts table, yay!
    This is done.

  21. lock commented on Aug 6, 2019

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  22. locked as resolved and limited conversation to collaborators on Aug 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions