Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[full-ci] add driveAlias to the graphAPI #3283

Merged
merged 4 commits into from
Mar 16, 2022
Merged

[full-ci] add driveAlias to the graphAPI #3283

merged 4 commits into from
Mar 16, 2022

Conversation

micbar
Copy link
Contributor

@micbar micbar commented Mar 7, 2022

Description

Implements owncloud/libre-graph-api#6
Needs cs3org/reva#2623

The concept is described in the ADR https://owncloud.dev/ocis/adr/0011-global-url-format/#mixed-global-urls in the section mixed global urls.

Related Issue

Motivation and Context

Space identifier

The primary identifier for a space is always the UUID. A unique logical ID is the only stable indentifier that works under all circumstances

A technical URL with a stable identifier

https://cloud.owncloud.com/files/spaces/95b4c6f6-d8f2-4976-b0a3-1b016bdfcb7e/relative/path/to/file.txt.

Make it more user friendly

To make the URL human-readable we replace the UUID with an alias.
https://cloud.owncloud.com/files/spaces/personal/einstein/relative/path/to/file.txt

The WebUI discovers the spaces using the /drives Endpoint. It should return a space with the alias personal/einstein and the id:95b4c6f6-d8f2-4976-b0a3-1b016bdfcb7e. This aliasing allows the WebUI to use human-readable URLs and translate the alias back into a UUID which is then used to make the actual WebDAV Requests.

The problem with aliases is, that they are not unique, can be customized and might clash. Therefore the UUID is always appended as an URL Parameter ?id=95b4c6f6-d8f2-4976-b0a3-1b016bdfcb7e

Stable and user friendlyURL

https://cloud.owncloud.com/files/spaces/personal/einstein/relative/path/to/file.txt?id=95b4c6f6-d8f2-4976-b0a3-1b016bdfcb7e

New Config Options

ENV default value Description
STORAGE_USERS_DRIVER_S3NG_PERSONAL_SPACE_ALIAS_TEMPLATE {{.SpaceType}}/{{.User.Username | lower}} contains the template used to construct the personal space alias
STORAGE_USERS_DRIVER_S3NG_GENERAL_SPACE_ALIAS_TEMPLATE {{.SpaceType}}/{{.SpaceName | replace " " "-" | lower}} contains the template used to construct the general space alias
STORAGE_USERS_DRIVER_OCIS_PERSONAL_SPACE_ALIAS_TEMPLATE {{.SpaceType}}/{{.User.Username | lower}} contains the template used to construct the personal space alias
STORAGE_USERS_DRIVER_OCIS_GENERAL_SPACE_ALIAS_TEMPLATE {{.SpaceType}}/{{.SpaceName | replace " " "-" | lower}} contains the template used to construct the general space alias

How Has This Been Tested?

  • manually
  • needs tests

Example responses (if appropriate):

List personal space

curl -L -k -X GET "https://localhost:9200/graph/v1.0/me/drives/" \
-H "Authorization: Basic ZWluc3RlaW46cmVsYXRpdml0eQ=="

Response

{
    "value": [
        {
            "driveAlias": "personal/einstein",
            "driveType": "personal",
            "id": "4c510ada-c86b-4815-8820-42cdf82c3d51",
            "lastModifiedDateTime": "2022-03-07T21:00:11.840287231+01:00",
            "name": "Albert Einstein",
            "owner": {
                "user": {
                    "id": "4c510ada-c86b-4815-8820-42cdf82c3d51"
                }
            },
            "quota": {
                "remaining": 19638898688,
                "state": "normal",
                "total": 19638898688,
                "used": 0
            },
            "root": {
                "eTag": "\"f9adeb482f7dc3ad12a009e851341d02\"",
                "id": "4c510ada-c86b-4815-8820-42cdf82c3d51!4c510ada-c86b-4815-8820-42cdf82c3d51",
                "webDavUrl": "https://localhost:9200/dav/spaces/4c510ada-c86b-4815-8820-42cdf82c3d51"
            }
        }
    ]
}

Create a space

curl -L -k -X POST "https://localhost:9200/graph/v1.0/drives/" \
-H "Authorization: Basic YWRtaW46YWRtaW4=" \
-H "Content-Type: application/json" \
--data-raw "{
    \"Name\": \"Project Mars\",
    \"driveAlias\": \"project/mars\",
    \"description\": \"Elon Musk wants to fly to mars\"
}"

Response

{
    "description": "Elon Musk wants to fly to mars",
    "driveAlias": "project/mars",
    "driveType": "project",
    "id": "016c23cc-5a72-4b35-b73e-648315c21bc0",
    "lastModifiedDateTime": "2022-03-07T21:03:08.735607295+01:00",
    "name": "Project Mars",
    "owner": {
        "user": {
            "id": "ddc2004c-0977-11eb-9d3f-a793888cd0f8"
        }
    },
    "quota": {
        "total": 1000000000
    },
    "root": {
        "eTag": "\"d2fce34e28284ab262668deb5dfd937a\"",
        "id": "016c23cc-5a72-4b35-b73e-648315c21bc0!016c23cc-5a72-4b35-b73e-648315c21bc0",
        "permissions": [
            {
                "grantedTo": [
                    {
                        "user": {
                            "id": "ddc2004c-0977-11eb-9d3f-a793888cd0f8"
                        }
                    }
                ],
                "roles": [
                    "manager"
                ]
            }
        ],
        "webDavUrl": "https://localhost:9200/dav/spaces/016c23cc-5a72-4b35-b73e-648315c21bc0"
    }
}

Modify a Space

curl -L -k -X PATCH "https://localhost:9200/graph/v1.0/drives/016c23cc-5a72-4b35-b73e-648315c21bc0" \
-H "Authorization: Basic YWRtaW46YWRtaW4=" \
-H "Content-Type: application/json" \
--data-raw "{
    \"Name\": \"Project Mars\",
    \"driveAlias\": \"project/mars(1)\",
    \"description\": \"Elon Musk wants to fly to mars\"
}"

Response

{
    "description": "Elon Musk wants to fly to mars",
    "driveAlias": "project/mars(1)",
    "driveType": "project",
    "id": "016c23cc-5a72-4b35-b73e-648315c21bc0",
    "lastModifiedDateTime": "2022-03-07T21:03:08.735607295+01:00",
    "name": "Project Mars",
    "owner": {
        "user": {
            "id": "ddc2004c-0977-11eb-9d3f-a793888cd0f8"
        }
    },
    "quota": {
        "remaining": 1000000000,
        "state": "normal",
        "total": 1000000000,
        "used": 0
    },
    "root": {
        "eTag": "\"d2fce34e28284ab262668deb5dfd937a\"",
        "id": "016c23cc-5a72-4b35-b73e-648315c21bc0!016c23cc-5a72-4b35-b73e-648315c21bc0",
        "permissions": [
            {
                "grantedTo": [
                    {
                        "user": {
                            "id": "ddc2004c-0977-11eb-9d3f-a793888cd0f8"
                        }
                    }
                ],
                "roles": [
                    "manager"
                ]
            }
        ],
        "webDavUrl": "https://localhost:9200/dav/spaces/016c23cc-5a72-4b35-b73e-648315c21bc0"
    }
}

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:

@update-docs
Copy link

update-docs bot commented Mar 7, 2022

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes.

@micbar micbar mentioned this pull request Mar 7, 2022
@micbar micbar changed the title add driveAlias to the graphAPI [full-ci] add driveAlias to the graphAPI Mar 15, 2022
@micbar micbar force-pushed the drive-alias branch 3 times, most recently from 72691d2 to 0688064 Compare March 16, 2022 14:02
@micbar micbar marked this pull request as ready for review March 16, 2022 14:02
@micbar micbar self-assigned this Mar 16, 2022
@micbar micbar force-pushed the drive-alias branch 8 times, most recently from 6a46da7 to be2e75d Compare March 16, 2022 15:36
@sonarcloud
Copy link

sonarcloud bot commented Mar 16, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

25.0% 25.0% Coverage
0.0% 0.0% Duplication

@micbar micbar merged commit cc825d5 into master Mar 16, 2022
@delete-merged-branch delete-merged-branch bot deleted the drive-alias branch March 16, 2022 20:36
ownclouders pushed a commit that referenced this pull request Mar 16, 2022
Merge: 439c203 7a0e28a
Author: Michael Barz <mbarz@owncloud.com>
Date:   Wed Mar 16 21:36:39 2022 +0100

    Merge pull request #3283 from owncloud/drive-alias

    [full-ci] add driveAlias to the graphAPI
@micbar micbar mentioned this pull request Mar 29, 2022
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants