Skip to content

Commit

Permalink
Merge pull request #3283 from owncloud/drive-alias
Browse files Browse the repository at this point in the history
[full-ci] add driveAlias to the graphAPI
  • Loading branch information
micbar committed Mar 16, 2022
2 parents 439c203 + 7a0e28a commit cc825d5
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 44 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/space-aliases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Add space aliases

Space aliases can be used to resolve spaceIDs in a client.

https://github.com/owncloud/ocis/pull/3283
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/blevesearch/bleve/v2 v2.3.1
github.com/coreos/go-oidc/v3 v3.1.0
github.com/cs3org/go-cs3apis v0.0.0-20220126114148-64c025ccdd19
github.com/cs3org/reva/v2 v2.0.0-20220314085001-8e5b22a20a3f
github.com/cs3org/reva/v2 v2.0.0-20220316045927-99115670eb33
github.com/disintegration/imaging v1.6.2
github.com/glauth/glauth/v2 v2.0.0-20211021011345-ef3151c28733
github.com/go-chi/chi/v5 v5.0.7
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ github.com/crewjam/saml v0.4.6/go.mod h1:ZBOXnNPFzB3CgOkRm7Nd6IVdkG+l/wF+0ZXLqD9
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
github.com/cs3org/go-cs3apis v0.0.0-20220126114148-64c025ccdd19 h1:1jqPH58jCxvbaJ9WLIJ7W2/m622bWS6ChptzljSG6IQ=
github.com/cs3org/go-cs3apis v0.0.0-20220126114148-64c025ccdd19/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/reva/v2 v2.0.0-20220314085001-8e5b22a20a3f h1:tv7v6OjbFoDFNB2ikGC+LLaWEOIAJnrZjyO5LRTDL0g=
github.com/cs3org/reva/v2 v2.0.0-20220314085001-8e5b22a20a3f/go.mod h1:XNtK1HEClNzmz5vyQa2DUw4KH3oqBjQoEsV1LhAGlV0=
github.com/cs3org/reva/v2 v2.0.0-20220316045927-99115670eb33 h1:XK88Fs9FteY9a+iKXqPhUK38zNQbP1jj60zy+Tx7SPI=
github.com/cs3org/reva/v2 v2.0.0-20220316045927-99115670eb33/go.mod h1:XNtK1HEClNzmz5vyQa2DUw4KH3oqBjQoEsV1LhAGlV0=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
Expand Down
25 changes: 14 additions & 11 deletions graph/pkg/service/v0/drives.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ func (g Graph) CreateDrive(w http.ResponseWriter, r *http.Request) {
csr.Opaque = utils.AppendPlainToOpaque(csr.Opaque, "description", *drive.Description)
}

if drive.DriveAlias != nil {
csr.Opaque = utils.AppendPlainToOpaque(csr.Opaque, "spaceAlias", *drive.DriveAlias)
}

resp, err := client.CreateStorageSpace(r.Context(), &csr)
if err != nil {
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
Expand Down Expand Up @@ -303,24 +307,19 @@ func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) {
}
}

// Note: this is the Opaque prop of the space itself
opaque := make(map[string]*types.OpaqueEntry)
if drive.Description != nil {
opaque["description"] = &types.OpaqueEntry{
Decoder: "plain",
Value: []byte(*drive.Description),
}
updateSpaceRequest.StorageSpace.Opaque = utils.AppendPlainToOpaque(updateSpaceRequest.StorageSpace.Opaque, "description", *drive.Description)
}

if drive.DriveAlias != nil {
updateSpaceRequest.StorageSpace.Opaque = utils.AppendPlainToOpaque(updateSpaceRequest.StorageSpace.Opaque, "spaceAlias", *drive.DriveAlias)
}

for _, special := range drive.Special {
if special.Id != nil {
opaque[*special.SpecialFolder.Name] = &types.OpaqueEntry{
Decoder: "plain",
Value: []byte(*special.Id),
}
updateSpaceRequest.StorageSpace.Opaque = utils.AppendPlainToOpaque(updateSpaceRequest.StorageSpace.Opaque, *special.SpecialFolder.Name, *special.Id)
}
}
updateSpaceRequest.StorageSpace.Opaque = &types.Opaque{Map: opaque}

if drive.Name != nil {
updateSpaceRequest.StorageSpace.Name = *drive.Name
Expand Down Expand Up @@ -508,6 +507,10 @@ func (g Graph) cs3StorageSpaceToDrive(baseURL *url.URL, space *storageprovider.S
drive.Description = libregraph.PtrString(string(description.Value))
}

if alias, ok := space.Opaque.Map["spaceAlias"]; ok {
drive.DriveAlias = libregraph.PtrString(string(alias.Value))
}

if v, ok := space.Opaque.Map["trashed"]; ok {
deleted := &libregraph.Deleted{}
deleted.SetState(string(v.Value))
Expand Down
17 changes: 17 additions & 0 deletions graph/pkg/service/v0/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/v2/pkg/rgrpc/status"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -116,6 +117,12 @@ var _ = Describe("Graph", func() {
OpaqueId: "bopaqueid",
},
Name: "bspacename",
Opaque: &typesv1beta1.Opaque{
Map: map[string]*typesv1beta1.OpaqueEntry{
"spaceAlias": {Decoder: "plain", Value: []byte("bspacetype/bspacename")},
"etag": {Decoder: "plain", Value: []byte("123456789")},
},
},
},
{
Id: &provider.StorageSpaceId{OpaqueId: "aspaceid"},
Expand All @@ -125,6 +132,12 @@ var _ = Describe("Graph", func() {
OpaqueId: "anopaqueid",
},
Name: "aspacename",
Opaque: &typesv1beta1.Opaque{
Map: map[string]*typesv1beta1.OpaqueEntry{
"spaceAlias": {Decoder: "plain", Value: []byte("aspacetype/aspacename")},
"etag": {Decoder: "plain", Value: []byte("101112131415")},
},
},
},
},
}, nil)
Expand All @@ -146,19 +159,23 @@ var _ = Describe("Graph", func() {
{
"value":[
{
"driveAlias":"aspacetype/aspacename",
"driveType":"aspacetype",
"id":"aspaceid",
"name":"aspacename",
"root":{
"eTag":"101112131415",
"id":"aspaceid!anopaqueid",
"webDavUrl":"https://localhost:9200/dav/spaces/aspaceid"
}
},
{
"driveAlias":"bspacetype/bspacename",
"driveType":"bspacetype",
"id":"bspaceid",
"name":"bspacename",
"root":{
"eTag":"123456789",
"id":"bspaceid!bopaqueid",
"webDavUrl":"https://localhost:9200/dav/spaces/bspaceid"
}
Expand Down
38 changes: 21 additions & 17 deletions storage/pkg/command/storagedrivers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@ func UserDrivers(cfg *config.Config) map[string]interface{} {
"userprovidersvc": cfg.Reva.Users.Endpoint,
},
"ocis": map[string]interface{}{
"root": cfg.Reva.UserStorage.OCIS.Root,
"user_layout": cfg.Reva.UserStorage.OCIS.UserLayout,
"share_folder": cfg.Reva.UserStorage.OCIS.ShareFolder,
"treetime_accounting": true,
"treesize_accounting": true,
"permissionssvc": cfg.Reva.Permissions.Endpoint,
"root": cfg.Reva.UserStorage.OCIS.Root,
"user_layout": cfg.Reva.UserStorage.OCIS.UserLayout,
"share_folder": cfg.Reva.UserStorage.OCIS.ShareFolder,
"personalspacealias_template": cfg.Reva.UserStorage.OCIS.PersonalSpaceAliasTemplate,
"generalspacealias_template": cfg.Reva.UserStorage.OCIS.GeneralSpaceAliasTemplate,
"treetime_accounting": true,
"treesize_accounting": true,
"permissionssvc": cfg.Reva.Permissions.Endpoint,
},
"s3": map[string]interface{}{
"enable_home": false,
Expand All @@ -106,17 +108,19 @@ func UserDrivers(cfg *config.Config) map[string]interface{} {
"prefix": cfg.Reva.UserStorage.S3.Root,
},
"s3ng": map[string]interface{}{
"root": cfg.Reva.UserStorage.S3NG.Root,
"user_layout": cfg.Reva.UserStorage.S3NG.UserLayout,
"share_folder": cfg.Reva.UserStorage.S3NG.ShareFolder,
"treetime_accounting": true,
"treesize_accounting": true,
"permissionssvc": cfg.Reva.Permissions.Endpoint,
"s3.region": cfg.Reva.UserStorage.S3NG.Region,
"s3.access_key": cfg.Reva.UserStorage.S3NG.AccessKey,
"s3.secret_key": cfg.Reva.UserStorage.S3NG.SecretKey,
"s3.endpoint": cfg.Reva.UserStorage.S3NG.Endpoint,
"s3.bucket": cfg.Reva.UserStorage.S3NG.Bucket,
"root": cfg.Reva.UserStorage.S3NG.Root,
"user_layout": cfg.Reva.UserStorage.S3NG.UserLayout,
"share_folder": cfg.Reva.UserStorage.S3NG.ShareFolder,
"personalspacealias_template": cfg.Reva.UserStorage.S3NG.PersonalSpaceAliasTemplate,
"generalspacealias_template": cfg.Reva.UserStorage.S3NG.GeneralSpaceAliasTemplate,
"treetime_accounting": true,
"treesize_accounting": true,
"permissionssvc": cfg.Reva.Permissions.Endpoint,
"s3.region": cfg.Reva.UserStorage.S3NG.Region,
"s3.access_key": cfg.Reva.UserStorage.S3NG.AccessKey,
"s3.secret_key": cfg.Reva.UserStorage.S3NG.SecretKey,
"s3.endpoint": cfg.Reva.UserStorage.S3NG.Endpoint,
"s3.bucket": cfg.Reva.UserStorage.S3NG.Bucket,
},
}
}
22 changes: 22 additions & 0 deletions storage/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ type DriverCommon struct {
UserLayout string `ocisConfig:"user_layout"`
// EnableHome enables the creation of home directories.
EnableHome bool `ocisConfig:"enable_home"`
// PersonalSpaceAliasTemplate contains the template used to construct
// the personal space alias, eg: `"{{.SpaceType}}/{{.User.Username | lower}}"`
PersonalSpaceAliasTemplate string `ocisConfig:"personalspacealias_template"`
// GeneralSpaceAliasTemplate contains the template used to construct
// the general space alias, eg: `{{.SpaceType}}/{{.SpaceName | replace " " "-" | lower}}`
GeneralSpaceAliasTemplate string `ocisConfig:"generalspacealias_template"`
}

// DriverEOS defines the available EOS driver configuration.
Expand Down Expand Up @@ -1528,6 +1534,14 @@ func structMappings(cfg *Config) []shared.EnvBinding {
EnvVars: []string{"STORAGE_USERS_DRIVER_OCIS_SHARE_FOLDER"},
Destination: &cfg.Reva.UserStorage.OCIS.ShareFolder,
},
{
EnvVars: []string{"STORAGE_USERS_DRIVER_OCIS_PERSONAL_SPACE_ALIAS_TEMPLATE"},
Destination: &cfg.Reva.UserStorage.OCIS.PersonalSpaceAliasTemplate,
},
{
EnvVars: []string{"STORAGE_USERS_DRIVER_OCIS_GENERAL_SPACE_ALIAS_TEMPLATE"},
Destination: &cfg.Reva.UserStorage.OCIS.GeneralSpaceAliasTemplate,
},
// driver owncloud sql
{
EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUDSQL_DATADIR"},
Expand Down Expand Up @@ -1601,6 +1615,14 @@ func structMappings(cfg *Config) []shared.EnvBinding {
EnvVars: []string{"STORAGE_USERS_DRIVER_S3NG_SHARE_FOLDER"},
Destination: &cfg.Reva.UserStorage.S3NG.ShareFolder,
},
{
EnvVars: []string{"STORAGE_USERS_DRIVER_S3NG_PERSONAL_SPACE_ALIAS_TEMPLATE"},
Destination: &cfg.Reva.UserStorage.S3NG.PersonalSpaceAliasTemplate,
},
{
EnvVars: []string{"STORAGE_USERS_DRIVER_S3NG_GENERAL_SPACE_ALIAS_TEMPLATE"},
Destination: &cfg.Reva.UserStorage.S3NG.GeneralSpaceAliasTemplate,
},
{
EnvVars: []string{"STORAGE_USERS_DRIVER_S3NG_REGION"},
Destination: &cfg.Reva.UserStorage.S3NG.Region,
Expand Down
30 changes: 18 additions & 12 deletions storage/pkg/config/defaults/defaultconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (
)

const (
defaultPublicURL = "https://localhost:9200"
defaultShareFolder = "/Shares"
defaultStorageNamespace = "/users/{{.Id.OpaqueId}}"
defaultGatewayAddr = "127.0.0.1:9142"
defaultUserLayout = "{{.Id.OpaqueId}}"
defaultPublicURL = "https://localhost:9200"
defaultShareFolder = "/Shares"
defaultStorageNamespace = "/users/{{.Id.OpaqueId}}"
defaultGatewayAddr = "127.0.0.1:9142"
defaultUserLayout = "{{.Id.OpaqueId}}"
defaultPersonalSpaceAliasTemplate = "{{.SpaceType}}/{{.User.Username | lower}}"
defaultGeneralSpaceAliasTemplate = "{{.SpaceType}}/{{.SpaceName | replace \" \" \"-\" | lower}}"
)

func FullDefaultConfig() *config.Config {
Expand Down Expand Up @@ -145,10 +147,12 @@ func DefaultConfig() *config.Config {
},
S3NG: config.DriverS3NG{
DriverCommon: config.DriverCommon{
Root: path.Join(defaults.BaseDataPath(), "storage", "users"),
ShareFolder: defaultShareFolder,
UserLayout: defaultUserLayout,
EnableHome: false,
Root: path.Join(defaults.BaseDataPath(), "storage", "users"),
ShareFolder: defaultShareFolder,
UserLayout: defaultUserLayout,
PersonalSpaceAliasTemplate: defaultPersonalSpaceAliasTemplate,
GeneralSpaceAliasTemplate: defaultGeneralSpaceAliasTemplate,
EnableHome: false,
},
Region: "default",
AccessKey: "",
Expand All @@ -158,9 +162,11 @@ func DefaultConfig() *config.Config {
},
OCIS: config.DriverOCIS{
DriverCommon: config.DriverCommon{
Root: path.Join(defaults.BaseDataPath(), "storage", "users"),
ShareFolder: defaultShareFolder,
UserLayout: defaultUserLayout,
Root: path.Join(defaults.BaseDataPath(), "storage", "users"),
ShareFolder: defaultShareFolder,
UserLayout: defaultUserLayout,
PersonalSpaceAliasTemplate: defaultPersonalSpaceAliasTemplate,
GeneralSpaceAliasTemplate: defaultGeneralSpaceAliasTemplate,
},
},
},
Expand Down
1 change: 0 additions & 1 deletion tests/acceptance/expected-failures-API-on-OCIS-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -1859,7 +1859,6 @@ Not everything needs to be implemented for ocis. While the oc10 testsuite covers
#### [status does not have new product data item](https://github.com/owncloud/ocis/issues/3317)

- [apiCapabilities/capabilities.feature:959](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiCapabilities/capabilities.feature#L959)
- [apiMain/status.feature:5](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiMain/status.feature#L5)

Note: always have an empty line at the end of this file.
The bash script that processes this file requires that the last line has a newline on the end.
4 changes: 4 additions & 0 deletions tests/acceptance/features/apiSpaces/listSpaces.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Feature: List and create spaces
And the json responded should contain a space "Alice Hansen" with these key and value pairs:
| key | value |
| driveType | personal |
| driveAlias | personal/alice |
| id | %space_id% |
| name | Alice Hansen |
| quota@@@state | normal |
Expand Down Expand Up @@ -61,6 +62,7 @@ Feature: List and create spaces
And the json responded should contain a space "Project Mars" with these key and value pairs:
| key | value |
| driveType | project |
| driveAlias | project/project-mars |
| name | Project Mars |
| quota@@@total | 1000000000 |
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
Expand Down Expand Up @@ -98,13 +100,15 @@ Feature: List and create spaces
And the json responded should contain a space "Project Venus" with these key and value pairs:
| key | value |
| driveType | project |
| driveAlias | project/project-venus |
| name | Project Venus |
| quota@@@total | 2000 |
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
When user "Alice" looks up the single space "Project Venus" via the GraphApi by using its id
Then the json responded should contain a space "Project Venus" with these key and value pairs:
| key | value |
| driveType | project |
| driveAlias | project/project-venus |
| name | Project Venus |
| quota@@@total | 2000 |
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |

0 comments on commit cc825d5

Please sign in to comment.