Files
ocis/services/graph/pkg/service/v0/spacetemplates.go
T
Roman PerekhodandMartin 39e3d33820 [full-ci] feat: ocisdev-533 graph (#12108)
* feat: Implemet the vault-storage

feat: Separate the storage-users and graph to handle

feat: move the space create cache

configurate the vault srorage Postprocessing

hide the assignment of the MountID to VaultStorageProviderID behind a flag to avoid the ID mismatch

configurate the proxy to create the vault home space

update the filter

Make the graph able to handle vault prefix. no extra service needed

apply the vault filter to sharedbyme and sharedwithme

added vault-storage docker

use squashed reva

fix the finishUpload event

restict webdav copy/move from the vault

feat: provide the mfa to webdav and grpc

feat: refactoring: provide the mfa to webdav and grpc

mfa collaboration

fix GetRootDriveChildren and more

fix: send the MFA header in HTTP clients from the collaboration service

provide the default storage user vault configuration

update create_home middleware

Update deployments/examples/ocis_full/vault-storage.yml

Co-authored-by: Martin <github@diemattels.at>

Update services/gateway/pkg/config/config.go

Co-authored-by: Martin <github@diemattels.at>

Update services/graph/pkg/config/config.go

Co-authored-by: Martin <github@diemattels.at>

Update services/graph/pkg/config/config.go

Co-authored-by: Martin <github@diemattels.at>

Update services/storage-users/pkg/config/config.go

Co-authored-by: Martin <github@diemattels.at>

Update services/proxy/pkg/config/config.go

Co-authored-by: Martin <github@diemattels.at>

Update services/storage-users/pkg/config/config.go

Co-authored-by: Martin <github@diemattels.at>

Update deployments/examples/ocis_full/vault-storage.yml

Co-authored-by: Martin <github@diemattels.at>

bump reva

deduplicate the requireMFA middeware on vault routes. fix AppendPlainToOpaque.

added the changlog and comments

* feat: add the vault mode search

* Update changelog/unreleased/enhancement-vault-storage.md

Co-authored-by: Martin <github@diemattels.at>

* update the readme. the reva vault storage provider configuration disabled by default

* feat: [OCISDEV-531] add vault capabilities to the OCS capabilities endpoint

* the port range allocated. the configuration updated.

---------

Co-authored-by: Martin <github@diemattels.at>
2026-05-15 16:53:05 +02:00

130 lines
3.7 KiB
Go

package svc
import (
"context"
"embed"
"fmt"
"io/fs"
"path/filepath"
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
v1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/owncloud/ocis/v2/ocis-pkg/l10n"
l10n_pkg "github.com/owncloud/ocis/v2/services/graph/pkg/l10n"
"github.com/owncloud/ocis/v2/services/graph/pkg/middleware"
"github.com/owncloud/reva/v2/pkg/storage/utils/metadata"
"github.com/owncloud/reva/v2/pkg/storagespace"
"github.com/owncloud/reva/v2/pkg/utils"
)
var (
//go:embed spacetemplate/*
_spaceTemplateFS embed.FS
// name of the secret space folder
_spaceFolderName = ".space"
// path to the image file
_imagepath = "spacetemplate/image.png"
// default description for new spaces
_readmeText = l10n.Template("Here you can add a description for this Space.")
// name of the readme.md file
_readmeName = "readme.md"
// HeaderAcceptLanguage is the header key for the accept-language header
HeaderAcceptLanguage = "Accept-Language"
// TemplateParameter is the key for the template parameter in the request
TemplateParameter = "template"
)
func (g Graph) applySpaceTemplate(ctx context.Context, gwc gateway.GatewayAPIClient, root *storageprovider.ResourceId, template string, locale string) error {
switch template {
default:
fallthrough
case "none":
return nil
case "default":
return g.applyDefaultTemplate(ctx, gwc, root, locale)
}
}
func (g Graph) applyDefaultTemplate(ctx context.Context, gwc gateway.GatewayAPIClient, root *storageprovider.ResourceId, locale string) error {
storageUsersAddress := g.config.Spaces.StorageUsersAddress
if g.config.EnableVaultMode && middleware.IsVaultMode(ctx) {
storageUsersAddress = g.config.Spaces.StorageUsersVaultAddress
}
mdc := metadata.NewCS3(g.config.Reva.Address, storageUsersAddress)
mdc.SpaceRoot = root
var opaque *v1beta1.Opaque
// create .space folder
if err := mdc.MakeDirIfNotExist(ctx, _spaceFolderName); err != nil {
return err
}
// upload space image
iid, err := imageUpload(ctx, mdc)
if err != nil {
return err
}
opaque = utils.AppendPlainToOpaque(opaque, SpaceImageSpecialFolderName, iid)
// upload readme.md
rid, err := readmeUpload(ctx, mdc, locale, g.config.Spaces.DefaultLanguage, g.config.Spaces.TranslationPath)
if err != nil {
return err
}
opaque = utils.AppendPlainToOpaque(opaque, ReadmeSpecialFolderName, rid)
// update space
resp, err := gwc.UpdateStorageSpace(ctx, &storageprovider.UpdateStorageSpaceRequest{
StorageSpace: &storageprovider.StorageSpace{
Id: &storageprovider.StorageSpaceId{
OpaqueId: storagespace.FormatResourceID(root),
},
Root: root,
Opaque: opaque,
},
})
switch {
case err != nil:
return err
case resp.GetStatus().GetCode() != rpc.Code_CODE_OK:
return fmt.Errorf("could not update storage space: %s", resp.GetStatus().GetMessage())
default:
return nil
}
}
func imageUpload(ctx context.Context, mdc *metadata.CS3) (string, error) {
b, err := fs.ReadFile(_spaceTemplateFS, _imagepath)
if err != nil {
return "", err
}
res, err := mdc.Upload(ctx, metadata.UploadRequest{
Path: filepath.Join(_spaceFolderName, filepath.Base(_imagepath)),
Content: b,
})
if err != nil {
return "", err
}
return res.FileID, nil
}
func readmeUpload(ctx context.Context, mdc *metadata.CS3, locale string, defaultLocale string, translationPath string) (string, error) {
res, err := mdc.Upload(ctx, metadata.UploadRequest{
Path: filepath.Join(_spaceFolderName, _readmeName),
Content: []byte(l10n_pkg.Translate(_readmeText, locale, defaultLocale, translationPath)),
})
if err != nil {
return "", err
}
return res.FileID, nil
}