mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-21 12:00:33 -06:00
Merge pull request #8558 from kobergj/ServerSideSpaceDefaults
Default Space Images
This commit is contained in:
@@ -45,6 +45,7 @@ type Spaces struct {
|
||||
ExtendedSpacePropertiesCacheTTL int `yaml:"extended_space_properties_cache_ttl" env:"GRAPH_SPACES_EXTENDED_SPACE_PROPERTIES_CACHE_TTL" desc:"Max TTL in seconds for the spaces property cache." introductionVersion:"pre5.0"`
|
||||
UsersCacheTTL int `yaml:"users_cache_ttl" env:"GRAPH_SPACES_USERS_CACHE_TTL" desc:"Max TTL in seconds for the spaces users cache." introductionVersion:"pre5.0"`
|
||||
GroupsCacheTTL int `yaml:"groups_cache_ttl" env:"GRAPH_SPACES_GROUPS_CACHE_TTL" desc:"Max TTL in seconds for the spaces groups cache." introductionVersion:"pre5.0"`
|
||||
StorageUsersAddress string `yaml:"storage_users_address" env:"GRAPH_SPACES_STORAGE_USERS_ADDRESS" desc:"The address of the storage-users service." introductionVersion:"5.0"`
|
||||
}
|
||||
|
||||
type LDAP struct {
|
||||
|
||||
@@ -51,9 +51,10 @@ func DefaultConfig() *config.Config {
|
||||
},
|
||||
Reva: shared.DefaultRevaConfig(),
|
||||
Spaces: config.Spaces{
|
||||
WebDavBase: "https://localhost:9200",
|
||||
WebDavPath: "/dav/spaces/",
|
||||
DefaultQuota: "1000000000",
|
||||
StorageUsersAddress: "com.owncloud.api.storage-users",
|
||||
WebDavBase: "https://localhost:9200",
|
||||
WebDavPath: "/dav/spaces/",
|
||||
DefaultQuota: "1000000000",
|
||||
// 1 minute
|
||||
ExtendedSpacePropertiesCacheTTL: 60,
|
||||
// 1 minute
|
||||
|
||||
@@ -482,12 +482,25 @@ func (g Graph) CreateDrive(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
newDrive, err := g.cs3StorageSpaceToDrive(r.Context(), webDavBaseURL, resp.StorageSpace)
|
||||
if driveType == _spaceTypeProject {
|
||||
opaque, err := g.applySpaceTemplate(gatewayClient, resp.GetStorageSpace().GetRoot(), r.URL.Query().Get("template"))
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msg("could not apply template to space")
|
||||
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp.StorageSpace.Opaque = utils.MergeOpaques(resp.GetStorageSpace().GetOpaque(), opaque)
|
||||
}
|
||||
|
||||
newDrive, err := g.cs3StorageSpaceToDrive(r.Context(), webDavBaseURL, resp.GetStorageSpace())
|
||||
if err != nil {
|
||||
logger.Debug().Err(err).Msg("could not create drive: error parsing drive")
|
||||
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
newDrive.Special = g.getSpecialDriveItems(r.Context(), webDavBaseURL, resp.GetStorageSpace())
|
||||
|
||||
render.Status(r, http.StatusCreated)
|
||||
render.JSON(w, r, newDrive)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package svc
|
||||
import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"embed"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -35,6 +36,11 @@ const (
|
||||
displayNameAttr = "displayName"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed spacetemplate/*
|
||||
_spaceTemplateFS embed.FS
|
||||
)
|
||||
|
||||
// Service defines the service handlers.
|
||||
type Service interface {
|
||||
ServeHTTP(http.ResponseWriter, *http.Request)
|
||||
|
||||
BIN
services/graph/pkg/service/v0/spacetemplate/.space/image.png
Normal file
BIN
services/graph/pkg/service/v0/spacetemplate/.space/image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
@@ -0,0 +1 @@
|
||||
Here you can add a description for this Space.
|
||||
@@ -3,14 +3,22 @@ package svc
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||
cs3User "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
||||
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
|
||||
storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
v1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
|
||||
"github.com/cs3org/reva/v2/pkg/storage/utils/metadata"
|
||||
"github.com/cs3org/reva/v2/pkg/storagespace"
|
||||
"github.com/cs3org/reva/v2/pkg/utils"
|
||||
"golang.org/x/sync/errgroup"
|
||||
@@ -425,3 +433,104 @@ func cs3ReceivedShareToLibreGraphPermissions(ctx context.Context, logger *log.Lo
|
||||
|
||||
return permission, nil
|
||||
}
|
||||
|
||||
func (g Graph) applySpaceTemplate(gwc gateway.GatewayAPIClient, root *storageprovider.ResourceId, template string) (*v1beta1.Opaque, error) {
|
||||
var fsys fs.ReadDirFS
|
||||
|
||||
switch template {
|
||||
default:
|
||||
fallthrough
|
||||
case "none":
|
||||
return &v1beta1.Opaque{}, nil
|
||||
case "default":
|
||||
f, err := fs.Sub(_spaceTemplateFS, "spacetemplate")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fsys = f.(fs.ReadDirFS)
|
||||
}
|
||||
|
||||
mdc := metadata.NewCS3(g.config.Reva.Address, g.config.Spaces.StorageUsersAddress)
|
||||
mdc.SpaceRoot = root
|
||||
|
||||
ctx, err := utils.GetServiceUserContext(g.config.ServiceAccount.ServiceAccountID, gwc, g.config.ServiceAccount.ServiceAccountSecret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
opaque, err := uploadFolder(ctx, mdc, ".", "", nil, fsys)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
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 nil, err
|
||||
case resp.GetStatus().GetCode() != rpc.Code_CODE_OK:
|
||||
return nil, fmt.Errorf("could not update storage space: %s", resp.GetStatus().GetMessage())
|
||||
default:
|
||||
return opaque, nil
|
||||
}
|
||||
}
|
||||
|
||||
func uploadFolder(ctx context.Context, mdc *metadata.CS3, pathOnDisc, pathOnSpace string, opaque *v1beta1.Opaque, fsys fs.ReadDirFS) (*v1beta1.Opaque, error) {
|
||||
entries, err := fsys.ReadDir(pathOnDisc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, entry := range entries {
|
||||
opaque, err = uploadEntry(ctx, mdc, pathOnDisc, pathOnSpace, opaque, fsys, entry)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return opaque, nil
|
||||
}
|
||||
|
||||
func uploadEntry(ctx context.Context, mdc *metadata.CS3, pathOnDisc, pathOnSpace string, opaque *v1beta1.Opaque, fsys fs.ReadDirFS, entry os.DirEntry) (*v1beta1.Opaque, error) {
|
||||
spacePath := filepath.Join(pathOnSpace, entry.Name())
|
||||
discPath := filepath.Join(pathOnDisc, entry.Name())
|
||||
|
||||
switch {
|
||||
case entry.IsDir():
|
||||
err := mdc.MakeDirIfNotExist(ctx, spacePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return uploadFolder(ctx, mdc, discPath, spacePath, opaque, fsys)
|
||||
default:
|
||||
b, err := fs.ReadFile(fsys, discPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res, err := mdc.Upload(ctx, metadata.UploadRequest{
|
||||
Path: spacePath,
|
||||
Content: b,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
identifier := strings.TrimSuffix(entry.Name(), filepath.Ext(entry.Name()))
|
||||
for _, special := range []string{ReadmeSpecialFolderName, SpaceImageSpecialFolderName} {
|
||||
if special == identifier {
|
||||
opaque = utils.AppendPlainToOpaque(opaque, identifier, res.FileID)
|
||||
break
|
||||
}
|
||||
}
|
||||
return opaque, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user