Compare commits
21
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed520de3e4 | ||
|
|
d4709c541e | ||
|
|
a1a168efa6 | ||
|
|
9dd7e6cbb7 | ||
|
|
0023265c7b | ||
|
|
ff235b9dc6 | ||
|
|
73b8e92a28 | ||
|
|
5c60816955 | ||
|
|
01fe5ac0a3 | ||
|
|
c472e3fe26 | ||
|
|
dd146fe775 | ||
|
|
e78afada30 | ||
|
|
584360d4fa | ||
|
|
c755e4c483 | ||
|
|
196d7324c6 | ||
|
|
e2ae85165a | ||
|
|
198ce92825 | ||
|
|
5ebc86012a | ||
|
|
22b7d229d6 | ||
|
|
27f982fc20 | ||
|
|
60ad26390b |
No files matched your search
@@ -54,6 +54,7 @@ OCIS_MODULES = \
|
||||
services/settings \
|
||||
services/sharing \
|
||||
services/sse \
|
||||
services/storage-kiteworks \
|
||||
services/storage-system \
|
||||
services/storage-publiclink \
|
||||
services/storage-shares \
|
||||
|
||||
@@ -68,7 +68,7 @@ We also suggest using the last port in your extensions' range as a debug/metrics
|
||||
| 9270-9274 | [eventhistory]({{< ref "../eventhistory/_index.md" >}}) |
|
||||
| 9275-9279 | [webfinger]({{< ref "../webfinger/_index.md" >}}) |
|
||||
| 9280-9284 | [ocm]({{< ref "../ocm/_index.md" >}}) |
|
||||
| 9285-9289 | FREE |
|
||||
| 9285-9289 | [storage-kiteworks]({{< ref "../storage-kiteworks/_index.md" >}}) |
|
||||
| 9290-9294 | FREE |
|
||||
| 9295-9299 | FREE |
|
||||
| 9300-9304 | [collaboration]({{< ref "../collaboration/_index.md" >}}) |
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,229 @@
|
||||
# Kiteworks Storage Provider for oCIS — Design Spec
|
||||
|
||||
**Date:** 2026-05-10
|
||||
**Author:** Thomas Müller
|
||||
**Status:** Approved
|
||||
|
||||
## Overview
|
||||
|
||||
A new oCIS service (`storage-kiteworks`) that exposes a Kiteworks server as a CS3 storage provider. It implements the reva `storage.FS` interface, translating CS3 operations into Kiteworks REST API calls. Each Kiteworks top-level folder becomes a CS3 `StorageSpace`. Authentication is pure OIDC token passthrough — no separate credentials.
|
||||
|
||||
## Goals
|
||||
|
||||
- Allow oCIS clients (desktop sync, web, mobile) to access files stored on a Kiteworks server.
|
||||
- Each Kiteworks top-level folder appears as a distinct storage space.
|
||||
- Owned folders map to `project` spaces; received shares map to `mountpoint` spaces.
|
||||
- Implement all Kiteworks-supported operations; stub unsupported ones with `errtypes.NotSupported`.
|
||||
|
||||
## Non-Goals
|
||||
|
||||
- Resumable upload recovery (re-attach after failure).
|
||||
- NATS event bus emission (deferred to a later iteration).
|
||||
- Search (`ListFolder` with search query).
|
||||
- Creating or deleting top-level Kiteworks folders from oCIS (admin-managed lifecycle).
|
||||
|
||||
---
|
||||
|
||||
## Section 1: Service Structure
|
||||
|
||||
### `services/storage-kiteworks/` — oCIS service layer
|
||||
|
||||
```
|
||||
cmd/storage-kiteworks/main.go # signal context, DefaultConfig, Execute
|
||||
pkg/command/root.go # GetCommands() → Server, Health, Version
|
||||
pkg/command/server.go # wires reva runtime with kiteworks driver
|
||||
pkg/config/config.go # Config struct
|
||||
pkg/config/defaults.go # DefaultConfig()
|
||||
pkg/revaconfig/config.go # StorageKiteworksConfigFromStruct()
|
||||
pkg/server/debug/server.go # debug HTTP server
|
||||
pkg/logging/logging.go # zerolog wrapper
|
||||
```
|
||||
|
||||
### `vendor/github.com/owncloud/reva/v2/pkg/storage/fs/kiteworks/` — reva storage driver
|
||||
|
||||
```
|
||||
kiteworks.go # storage.FS implementation; init() registers "kiteworks" driver
|
||||
client.go # Kiteworks REST API client (adapted from github.com/owncloud/kwdav pkg/kwlib)
|
||||
types.go # Kiteworks data model (FileInfo, DirectoryInfo, UploadResult, etc.)
|
||||
upload.go # chunked upload logic
|
||||
```
|
||||
|
||||
The driver is registered via `init()` into reva's `fs/registry` and imported with a blank import in:
|
||||
```
|
||||
vendor/github.com/owncloud/reva/v2/pkg/storage/fs/loader/loader.go
|
||||
```
|
||||
|
||||
The service binary is registered in the main oCIS multi-service runtime (same pattern as `storage-users`, `storage-system`). It is opt-in: the service only starts if `STORAGE_KITEWORKS_ENDPOINT` is configured, so existing deployments are unaffected.
|
||||
|
||||
---
|
||||
|
||||
## Section 2: CS3 → Kiteworks Operation Mapping
|
||||
|
||||
### Storage Spaces
|
||||
|
||||
| CS3 operation | Kiteworks REST | Notes |
|
||||
|---|---|---|
|
||||
| `ListStorageSpaces` | `GET /rest/folders/top` | Each folder → one `StorageSpace`. See space type mapping below. |
|
||||
| `CreateStorageSpace` | — | `errtypes.NotSupported` |
|
||||
| `UpdateStorageSpace` | — | `errtypes.NotSupported` |
|
||||
| `DeleteStorageSpace` | — | `errtypes.NotSupported` |
|
||||
| `CreateHome` | — | `errtypes.NotSupported` (deprecated) |
|
||||
| `GetHome` | — | `errtypes.NotSupported` (deprecated) |
|
||||
|
||||
**Space type mapping** (from `FileInfo.IsSharedWithUser()`):
|
||||
|
||||
- `IsSharedWithUser() == true` (i.e. `IsShared == true` and `ParentID == nil || "0"`) → `SpaceType = "mountpoint"` (received share)
|
||||
- `IsSharedWithUser() == false` → `SpaceType = "project"` (owned folder)
|
||||
|
||||
The `StorageSpace.Id.OpaqueId` is set to the Kiteworks folder ID. No extra API calls are needed to determine ownership — `GET /rest/folders/top` provides all required fields.
|
||||
|
||||
### File & Folder CRUD
|
||||
|
||||
| CS3 operation | Kiteworks REST | Notes |
|
||||
|---|---|---|
|
||||
| `GetMD` (by ID) | `GET /rest/folders/{id}` or `GET /rest/files/{id}` | Try folders endpoint first; on 404 fall back to files endpoint. CS3 `ResourceId` does not carry a type discriminator. |
|
||||
| `GetMD` (by path) | `GET /rest/query` (search by path) | Fall back to path-based search |
|
||||
| `ListFolder` | `GET /rest/folders/{id}/children` | |
|
||||
| `CreateDir` | `POST /rest/folders/{id}/folders` | |
|
||||
| `Delete` | `DELETE /rest/folders/{id}` or `DELETE /rest/files/{id}` | |
|
||||
| `Move` | `POST /rest/files/actions/move` | Works for files and folders |
|
||||
| `TouchFile` | Initiate upload + single empty chunk | See upload section |
|
||||
| `GetPathByID` | `GET /rest/files/{id}` or `/rest/folders/{id}` | Return `path` field |
|
||||
| `CreateReference` | — | `errtypes.NotSupported` |
|
||||
|
||||
### Upload & Download
|
||||
|
||||
| CS3 operation | Kiteworks REST | Notes |
|
||||
|---|---|---|
|
||||
| `InitiateUpload` | `POST /rest/folders/{id}/actions/initiateUpload` | Returns `uploadID` + `uploadURI` in map |
|
||||
| `Upload` | `UploadChunk` per chunk | Chunks of `ChunkSize` bytes (default 5 MB); last chunk sets `isLastChunk=true` |
|
||||
| `Download` | `GET /rest/files/{id}/content` | `Range` header passed through for partial reads |
|
||||
|
||||
TUS (`ComposableFS`) is not implemented — the Kiteworks chunked protocol is not TUS-compatible. oCIS falls back to the direct `Upload` path.
|
||||
|
||||
### Revisions
|
||||
|
||||
Stubbed with `errtypes.NotSupported` initially. Promote to real implementation if the Kiteworks REST API exposes version history (to be confirmed against the OpenAPI spec at implementation time).
|
||||
|
||||
### Recycle Bin
|
||||
|
||||
Stubbed with `errtypes.NotSupported` initially. Promote to real implementation if the Kiteworks REST API exposes trash operations.
|
||||
|
||||
### Grants
|
||||
|
||||
| CS3 operation | Kiteworks REST | Notes |
|
||||
|---|---|---|
|
||||
| `ListGrants` | File/folder metadata `Permission` array | Map Kiteworks `Permission` → CS3 `Grant` |
|
||||
| `AddGrant` | Kiteworks permissions endpoint | Map CS3 role → Kiteworks permission ID |
|
||||
| `UpdateGrant` | Kiteworks permissions endpoint | |
|
||||
| `RemoveGrant` | Kiteworks permissions endpoint | |
|
||||
| `DenyGrant` | — | `errtypes.NotSupported` (no explicit deny ACL in Kiteworks) |
|
||||
|
||||
### Metadata, Quota & Locks
|
||||
|
||||
| CS3 operation | Kiteworks REST | Notes |
|
||||
|---|---|---|
|
||||
| `GetQuota` | `GET /rest/users/me` | Returns `QuotaInfo.Allowed` / `QuotaInfo.Used` |
|
||||
| `SetArbitraryMetadata` | — | `errtypes.NotSupported` |
|
||||
| `UnsetArbitraryMetadata` | — | `errtypes.NotSupported` |
|
||||
| `GetLock` | — | `errtypes.NotSupported` |
|
||||
| `SetLock` | — | `errtypes.NotSupported` |
|
||||
| `RefreshLock` | — | `errtypes.NotSupported` |
|
||||
| `Unlock` | — | `errtypes.NotSupported` |
|
||||
|
||||
---
|
||||
|
||||
## Section 3: Configuration & Authentication
|
||||
|
||||
### Config struct (`pkg/config/config.go`)
|
||||
|
||||
```go
|
||||
type KiteworksDriver struct {
|
||||
Endpoint string `yaml:"endpoint" env:"STORAGE_KITEWORKS_ENDPOINT" desc:"Base URL of the Kiteworks server, e.g. https://kiteworks.example.com"`
|
||||
Insecure bool `yaml:"insecure" env:"STORAGE_KITEWORKS_INSECURE" desc:"Skip TLS certificate verification."`
|
||||
MountID string `yaml:"mount_id" env:"STORAGE_KITEWORKS_MOUNT_ID" desc:"Mount ID of this storage provider."`
|
||||
ChunkSize int64 `yaml:"chunk_size" env:"STORAGE_KITEWORKS_CHUNK_SIZE" desc:"Upload chunk size in bytes. Default 5242880 (5 MB)."`
|
||||
}
|
||||
```
|
||||
|
||||
No credentials in config. Authentication is token passthrough only.
|
||||
|
||||
### Authentication flow
|
||||
|
||||
1. Every CS3 gRPC request carries the user's OIDC token in the context (extracted by reva's auth middleware).
|
||||
2. The driver extracts it via `ctxpkg.ContextGetToken(ctx)`.
|
||||
3. Each outbound Kiteworks REST request includes `Authorization: Bearer <token>`.
|
||||
4. An `APIClient` is constructed per-request with the token — no shared client state across users.
|
||||
|
||||
**Deployment requirement:** The Kiteworks server must accept the OIDC tokens issued by oCIS's IDP (or they share a common token issuer). This is the expected topology when oCIS delegates identity to Kiteworks' own IDP.
|
||||
|
||||
### Reva driver config mapping (`pkg/revaconfig/config.go`)
|
||||
|
||||
```go
|
||||
func Kiteworks(cfg *config.Config) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"endpoint": cfg.Driver.Endpoint,
|
||||
"insecure": cfg.Driver.Insecure,
|
||||
"chunk_size": cfg.Driver.ChunkSize,
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Section 4: Upload Flow
|
||||
|
||||
### `InitiateUpload`
|
||||
|
||||
Calls `POST /rest/folders/{parentID}/actions/initiateUpload` with:
|
||||
- `filename` from `metadata["filename"]`
|
||||
- `totalSize = uploadLength`
|
||||
- `numberOfChunks = ceil(uploadLength / ChunkSize)` (minimum 1)
|
||||
|
||||
Returns a map:
|
||||
```go
|
||||
map[string]string{
|
||||
"uploadID": result.ID,
|
||||
"uploadURI": result.URI,
|
||||
}
|
||||
```
|
||||
|
||||
### `Upload`
|
||||
|
||||
1. Reads `req.Body` in `ChunkSize` slices.
|
||||
2. For each slice, calls `UploadChunk(uploadURI, filename, body, chunkIndex, chunkData, isLastChunk)`.
|
||||
3. The response from the final chunk is the committed `FileInfo`, which is converted to `*provider.ResourceInfo`.
|
||||
|
||||
### `TouchFile`
|
||||
|
||||
Equivalent to uploading a zero-byte file:
|
||||
1. `InitiateUpload` with `totalSize=0, numberOfChunks=1`.
|
||||
2. Single `UploadChunk` call with an empty body and `isLastChunk=true`.
|
||||
|
||||
### Chunk size default
|
||||
|
||||
`5 * 1024 * 1024` bytes (5 MB). Configurable via `STORAGE_KITEWORKS_CHUNK_SIZE`.
|
||||
|
||||
---
|
||||
|
||||
## Section 5: Integration & Testing
|
||||
|
||||
### Integration into oCIS binary
|
||||
|
||||
- Add blank import in `vendor/.../reva/v2/pkg/storage/fs/loader/loader.go`.
|
||||
- Register the service in the oCIS multi-service runtime (same as `storage-users`).
|
||||
- Service is opt-in: starts only when `STORAGE_KITEWORKS_ENDPOINT` is set.
|
||||
|
||||
### Testing
|
||||
|
||||
- **Unit tests** for the client layer using `httptest.NewServer` mock (pattern: `nextcloud_server_mock.go`).
|
||||
- **Unit tests** for each `storage.FS` method verifying correct REST endpoint is called and correct CS3 response is returned.
|
||||
- **Ginkgo v2 test suite** bootstrap: `TestKiteworks(t *testing.T)` with `RegisterFailHandler(Fail)` / `RunSpecs`.
|
||||
- No acceptance tests in v1 (require live Kiteworks instance).
|
||||
|
||||
### Out of scope for v1
|
||||
|
||||
- Resumable upload recovery (re-attach to an existing Kiteworks upload session after failure)
|
||||
- NATS event bus emission
|
||||
- Search support in `ListFolder`
|
||||
- Versioning and recycle bin (stubbed; implement if API supports them)
|
||||
@@ -64,7 +64,7 @@ require (
|
||||
github.com/open-policy-agent/opa v1.12.3
|
||||
github.com/orcaman/concurrent-map v1.0.0
|
||||
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245
|
||||
github.com/owncloud/reva/v2 v2.0.0-20260424082219-c88989902d1a
|
||||
github.com/owncloud/reva/v2 v2.0.0-20260511130900-472978d4d56c
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/pkg/xattr v0.4.12
|
||||
github.com/prometheus/client_golang v1.23.2
|
||||
|
||||
@@ -744,6 +744,8 @@ github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245 h1:J
|
||||
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245/go.mod h1:z61VMGAJRtR1nbgXWiNoCkxUXP1B3Je9rMuJbnGd+Og=
|
||||
github.com/owncloud/reva/v2 v2.0.0-20260424082219-c88989902d1a h1:Td4vu7/+VJcah08Fei+gaFw6x3gkGtqcXoeirSHYhZ0=
|
||||
github.com/owncloud/reva/v2 v2.0.0-20260424082219-c88989902d1a/go.mod h1:PIquCu54dUEqq2El2bvmkXuyve/WSlgS5Q7V8TluSNo=
|
||||
github.com/owncloud/reva/v2 v2.0.0-20260511130900-472978d4d56c h1:CWnUIIElvdeWfiOScwGaWltl4lETIx4Qmbf9HArjXaE=
|
||||
github.com/owncloud/reva/v2 v2.0.0-20260511130900-472978d4d56c/go.mod h1:PIquCu54dUEqq2El2bvmkXuyve/WSlgS5Q7V8TluSNo=
|
||||
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
|
||||
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
|
||||
github.com/pablodz/inotifywaitgo v0.0.9 h1:njquRbBU7fuwIe5rEvtaniVBjwWzcpdUVptSgzFqZsw=
|
||||
|
||||
@@ -34,6 +34,7 @@ import (
|
||||
settings "github.com/owncloud/ocis/v2/services/settings/pkg/config"
|
||||
sharing "github.com/owncloud/ocis/v2/services/sharing/pkg/config"
|
||||
sse "github.com/owncloud/ocis/v2/services/sse/pkg/config"
|
||||
storagekiteworks "github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/config"
|
||||
storagepublic "github.com/owncloud/ocis/v2/services/storage-publiclink/pkg/config"
|
||||
storageshares "github.com/owncloud/ocis/v2/services/storage-shares/pkg/config"
|
||||
storagesystem "github.com/owncloud/ocis/v2/services/storage-system/pkg/config"
|
||||
@@ -113,10 +114,11 @@ type Config struct {
|
||||
Settings *settings.Config `yaml:"settings"`
|
||||
Sharing *sharing.Config `yaml:"sharing"`
|
||||
SSE *sse.Config `yaml:"sse"`
|
||||
StorageSystem *storagesystem.Config `yaml:"storage_system"`
|
||||
StoragePublicLink *storagepublic.Config `yaml:"storage_public"`
|
||||
StorageShares *storageshares.Config `yaml:"storage_shares"`
|
||||
StorageUsers *storageusers.Config `yaml:"storage_users"`
|
||||
StorageKiteworks *storagekiteworks.Config `yaml:"storage_kiteworks"`
|
||||
StorageSystem *storagesystem.Config `yaml:"storage_system"`
|
||||
StoragePublicLink *storagepublic.Config `yaml:"storage_public"`
|
||||
StorageShares *storageshares.Config `yaml:"storage_shares"`
|
||||
StorageUsers *storageusers.Config `yaml:"storage_users"`
|
||||
Thumbnails *thumbnails.Config `yaml:"thumbnails"`
|
||||
Userlog *userlog.Config `yaml:"userlog"`
|
||||
Users *users.Config `yaml:"users"`
|
||||
|
||||
@@ -34,6 +34,7 @@ import (
|
||||
settings "github.com/owncloud/ocis/v2/services/settings/pkg/config/defaults"
|
||||
sharing "github.com/owncloud/ocis/v2/services/sharing/pkg/config/defaults"
|
||||
sse "github.com/owncloud/ocis/v2/services/sse/pkg/config/defaults"
|
||||
storagekiteworks "github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/config/defaults"
|
||||
storagepublic "github.com/owncloud/ocis/v2/services/storage-publiclink/pkg/config/defaults"
|
||||
storageshares "github.com/owncloud/ocis/v2/services/storage-shares/pkg/config/defaults"
|
||||
storageSystem "github.com/owncloud/ocis/v2/services/storage-system/pkg/config/defaults"
|
||||
@@ -89,6 +90,7 @@ func DefaultConfig() *Config {
|
||||
Settings: settings.DefaultConfig(),
|
||||
Sharing: sharing.DefaultConfig(),
|
||||
SSE: sse.DefaultConfig(),
|
||||
StorageKiteworks: storagekiteworks.DefaultConfig(),
|
||||
StoragePublicLink: storagepublic.DefaultConfig(),
|
||||
StorageShares: storageshares.DefaultConfig(),
|
||||
StorageSystem: storageSystem.DefaultConfig(),
|
||||
|
||||
@@ -40,6 +40,7 @@ import (
|
||||
settings "github.com/owncloud/ocis/v2/services/settings/pkg/command"
|
||||
sharing "github.com/owncloud/ocis/v2/services/sharing/pkg/command"
|
||||
sse "github.com/owncloud/ocis/v2/services/sse/pkg/command"
|
||||
storagekiteworks "github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/command"
|
||||
storagepubliclink "github.com/owncloud/ocis/v2/services/storage-publiclink/pkg/command"
|
||||
storageshares "github.com/owncloud/ocis/v2/services/storage-shares/pkg/command"
|
||||
storagesystem "github.com/owncloud/ocis/v2/services/storage-system/pkg/command"
|
||||
@@ -233,6 +234,11 @@ var svccmds = []register.Command{
|
||||
cfg.StorageUsers.Commons = cfg.Commons
|
||||
})
|
||||
},
|
||||
func(cfg *config.Config) *cli.Command {
|
||||
return ServiceCommand(cfg, cfg.StorageKiteworks.Service.Name, storagekiteworks.GetCommands(cfg.StorageKiteworks), func(c *config.Config) {
|
||||
cfg.StorageKiteworks.Commons = cfg.Commons
|
||||
})
|
||||
},
|
||||
func(cfg *config.Config) *cli.Command {
|
||||
return ServiceCommand(cfg, cfg.Thumbnails.Service.Name, thumbnails.GetCommands(cfg.Thumbnails), func(c *config.Config) {
|
||||
cfg.Thumbnails.Commons = cfg.Commons
|
||||
|
||||
@@ -59,6 +59,7 @@ import (
|
||||
settings "github.com/owncloud/ocis/v2/services/settings/pkg/command"
|
||||
sharing "github.com/owncloud/ocis/v2/services/sharing/pkg/command"
|
||||
sse "github.com/owncloud/ocis/v2/services/sse/pkg/command"
|
||||
storagekiteworks "github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/command"
|
||||
storagepublic "github.com/owncloud/ocis/v2/services/storage-publiclink/pkg/command"
|
||||
storageshares "github.com/owncloud/ocis/v2/services/storage-shares/pkg/command"
|
||||
storageSystem "github.com/owncloud/ocis/v2/services/storage-system/pkg/command"
|
||||
@@ -355,6 +356,11 @@ func NewService(ctx context.Context, options ...Option) (*Service, error) {
|
||||
cfg.Notifications.Commons = cfg.Commons
|
||||
return runServerCommand(ctx, notifications.Server(cfg.Notifications))
|
||||
})
|
||||
areg(opts.Config.StorageKiteworks.Service.Name, func(ctx context.Context, cfg *ociscfg.Config) error {
|
||||
cfg.StorageKiteworks.Context = ctx
|
||||
cfg.StorageKiteworks.Commons = cfg.Commons
|
||||
return runServerCommand(ctx, storagekiteworks.Server(cfg.StorageKiteworks))
|
||||
})
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
# Storage-Kiteworks
|
||||
|
||||
The `storage-kiteworks` service exposes a [Kiteworks](https://kiteworks.com/) server as a CS3 storage provider within oCIS.
|
||||
|
||||
Each Kiteworks top-level folder becomes a distinct CS3 `StorageSpace`:
|
||||
|
||||
- Folders owned by the authenticated user → space type `"project"`
|
||||
- Folders received as shares from other users → space type `"mountpoint"`
|
||||
|
||||
Authentication uses pure OIDC token passthrough — no separate Kiteworks credentials are required.
|
||||
|
||||
## Service Startup
|
||||
|
||||
The service is **opt-in** and does not start automatically. To enable it, add it to `OCIS_ADD_RUN_SERVICES`:
|
||||
|
||||
```bash
|
||||
OCIS_ADD_RUN_SERVICES=storage-kiteworks \
|
||||
STORAGE_KITEWORKS_ENDPOINT=https://kiteworks.example.com \
|
||||
STORAGE_KITEWORKS_MOUNT_ID=<uuid> \
|
||||
./ocis server
|
||||
```
|
||||
|
||||
Existing deployments are unaffected when `storage-kiteworks` is omitted from `OCIS_ADD_RUN_SERVICES`.
|
||||
|
||||
## Configuration
|
||||
|
||||
### Required Environment Variables
|
||||
|
||||
| Variable | Description |
|
||||
|---|---|
|
||||
| `STORAGE_KITEWORKS_ENDPOINT` | Base URL of the Kiteworks server, e.g. `https://kiteworks.example.com` |
|
||||
| `STORAGE_KITEWORKS_MOUNT_ID` | Mount ID for this storage provider (must be a stable UUID) |
|
||||
|
||||
### Optional Environment Variables
|
||||
|
||||
| Variable | Default | Description |
|
||||
|---|---|---|
|
||||
| `STORAGE_KITEWORKS_CHUNK_SIZE` | `5242880` | Upload chunk size in bytes (default 5 MB) |
|
||||
| `STORAGE_KITEWORKS_INSECURE` | `false` | Skip TLS certificate verification. Development only — never use in production |
|
||||
| `STORAGE_KITEWORKS_GRPC_ADDR` | `127.0.0.1:9285` | Bind address of the gRPC service |
|
||||
| `STORAGE_KITEWORKS_DEBUG_ADDR` | `127.0.0.1:9289` | Bind address of the debug/metrics server |
|
||||
|
||||
For the full list of environment variables see the generated documentation.
|
||||
|
||||
## Ports
|
||||
|
||||
The service uses port range **9285-9289**:
|
||||
|
||||
| Port | Usage |
|
||||
|---|---|
|
||||
| 9285 | gRPC storage provider endpoint |
|
||||
| 9289 | Debug server (metrics, health, pprof, zpages) |
|
||||
|
||||
## Health
|
||||
|
||||
The service responds to `ocis storage-kiteworks health` and exposes `/healthz` and `/readyz` on the debug port.
|
||||
|
||||
## Metrics
|
||||
|
||||
Prometheus metrics are exposed at `http://<STORAGE_KITEWORKS_DEBUG_ADDR>/metrics` under the `ocis_storage_kiteworks` namespace.
|
||||
|
||||
## Dependency
|
||||
|
||||
The Kiteworks storage driver lives in [owncloud/reva](https://github.com/owncloud/reva) at `pkg/storage/fs/kiteworks/`. This service requires a reva build that includes that driver.
|
||||
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/command"
|
||||
"github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/config/defaults"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg := defaults.DefaultConfig()
|
||||
cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP)
|
||||
if err := command.Execute(cfg); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
||||
"github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/config"
|
||||
"github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/config/parser"
|
||||
"github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/logging"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Health is the entrypoint for the health command.
|
||||
func Health(cfg *config.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "health",
|
||||
Usage: "check health status",
|
||||
Category: "info",
|
||||
Before: func(c *cli.Context) error {
|
||||
return configlog.ReturnError(parser.ParseConfig(cfg))
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
|
||||
resp, err := http.Get(
|
||||
fmt.Sprintf(
|
||||
"http://%s/healthz",
|
||||
cfg.Debug.Addr,
|
||||
),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
logger.Fatal().
|
||||
Err(err).
|
||||
Msg("Failed to request health check")
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
logger.Fatal().
|
||||
Int("code", resp.StatusCode).
|
||||
Msg("Health seems to be in bad state")
|
||||
}
|
||||
|
||||
logger.Debug().
|
||||
Int("code", resp.StatusCode).
|
||||
Msg("Health got a good state")
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/clihelper"
|
||||
"github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// GetCommands provides all commands for this service
|
||||
func GetCommands(cfg *config.Config) cli.Commands {
|
||||
return []*cli.Command{
|
||||
// start this service
|
||||
Server(cfg),
|
||||
|
||||
// infos about this service
|
||||
Health(cfg),
|
||||
Version(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
// Execute is the entry point for the ocis-storage-kiteworks command.
|
||||
func Execute(cfg *config.Config) error {
|
||||
app := clihelper.DefaultApp(&cli.App{
|
||||
Name: "storage-kiteworks",
|
||||
Usage: "Provide storage backed by Kiteworks in oCIS",
|
||||
Commands: GetCommands(cfg),
|
||||
})
|
||||
|
||||
return app.RunContext(cfg.Context, os.Args)
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os/signal"
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/registry"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/runner"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||
"github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/config"
|
||||
"github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/config/parser"
|
||||
"github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/logging"
|
||||
"github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/revaconfig"
|
||||
"github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/server/debug"
|
||||
"github.com/owncloud/reva/v2/cmd/revad/runtime"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Server is the entry point for the server command.
|
||||
func Server(cfg *config.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "server",
|
||||
Usage: fmt.Sprintf("start the %s service without runtime (unsupervised mode)", cfg.Service.Name),
|
||||
Category: "server",
|
||||
Before: func(c *cli.Context) error {
|
||||
return configlog.ReturnFatal(parser.ParseConfig(cfg))
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
traceProvider, err := tracing.GetServiceTraceProvider(cfg.Tracing, cfg.Service.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var cancel context.CancelFunc
|
||||
if cfg.Context == nil {
|
||||
cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...)
|
||||
defer cancel()
|
||||
}
|
||||
ctx := cfg.Context
|
||||
|
||||
gr := runner.NewGroup()
|
||||
|
||||
{
|
||||
// run the reva gRPC server
|
||||
rCfg := revaconfig.StorageKiteworksConfigFromStruct(cfg)
|
||||
if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg,
|
||||
runtime.WithLogger(&logger.Logger),
|
||||
runtime.WithRegistry(registry.GetRegistry()),
|
||||
runtime.WithTraceProvider(traceProvider),
|
||||
); rServer != nil {
|
||||
gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer))
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
debugServer, err := debug.Server(
|
||||
debug.Logger(logger),
|
||||
debug.Context(ctx),
|
||||
debug.Config(cfg),
|
||||
)
|
||||
if err != nil {
|
||||
logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server")
|
||||
return err
|
||||
}
|
||||
|
||||
gr.Add(runner.NewGolangHttpServerRunner("storage-kiteworks_debug", debugServer))
|
||||
}
|
||||
|
||||
grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString())
|
||||
if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil {
|
||||
logger.Fatal().Err(err).Msg("failed to register the grpc service")
|
||||
}
|
||||
|
||||
logger.Warn().Msgf("starting service %s", cfg.Service.Name)
|
||||
grResults := gr.Run(ctx)
|
||||
|
||||
if err := runner.ProcessResults(grResults); err != nil {
|
||||
logger.Error().Err(err).Msgf("service %s stopped with error", cfg.Service.Name)
|
||||
return err
|
||||
}
|
||||
logger.Warn().Msgf("service %s stopped without error", cfg.Service.Name)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/registry"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||
|
||||
"github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Version prints the service versions of all running instances.
|
||||
func Version(cfg *config.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "version",
|
||||
Usage: "print the version of this binary and the running service instances",
|
||||
Category: "info",
|
||||
Action: func(c *cli.Context) error {
|
||||
fmt.Println("Version: " + version.GetString())
|
||||
fmt.Printf("Compiled: %s\n", version.Compiled())
|
||||
fmt.Println("")
|
||||
|
||||
reg := registry.GetRegistry()
|
||||
services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Service.Name)
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err))
|
||||
return err
|
||||
}
|
||||
|
||||
if len(services) == 0 {
|
||||
fmt.Println("No running " + cfg.Service.Name + " service found.")
|
||||
return nil
|
||||
}
|
||||
|
||||
table := tablewriter.NewTable(os.Stdout)
|
||||
table.Header("Version", "Address", "Id")
|
||||
for _, s := range services {
|
||||
for _, n := range s.Nodes {
|
||||
table.Append([]string{s.Version, n.Address, n.Id})
|
||||
}
|
||||
}
|
||||
table.Render()
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
|
||||
)
|
||||
|
||||
// Config is the configuration for the storage-kiteworks service
|
||||
type Config struct {
|
||||
Commons *shared.Commons `yaml:"-"` // don't use this directly as configuration for a service
|
||||
Service Service `yaml:"-"`
|
||||
Tracing *Tracing `yaml:"tracing"`
|
||||
Log *Log `yaml:"log"`
|
||||
Debug Debug `yaml:"debug"`
|
||||
|
||||
GRPC GRPCConfig `yaml:"grpc"`
|
||||
|
||||
TokenManager *TokenManager `yaml:"token_manager"`
|
||||
Reva *shared.Reva `yaml:"reva"`
|
||||
|
||||
GracefulShutdownTimeout int `yaml:"graceful_shutdown_timeout" env:"STORAGE_KITEWORKS_GRACEFUL_SHUTDOWN_TIMEOUT" desc:"The number of seconds to wait for the 'storage-kiteworks' service to shutdown cleanly before exiting with an error that gets logged." introductionVersion:"1.0.0"`
|
||||
|
||||
Driver KiteworksDriver `yaml:"driver"`
|
||||
MountID string `yaml:"mount_id" env:"STORAGE_KITEWORKS_MOUNT_ID" desc:"Mount ID of this storage provider." introductionVersion:"1.0.0"`
|
||||
|
||||
Context context.Context `yaml:"-"`
|
||||
}
|
||||
|
||||
// Log configures the logging
|
||||
type Log struct {
|
||||
Level string `yaml:"level" env:"OCIS_LOG_LEVEL;STORAGE_KITEWORKS_LOG_LEVEL" desc:"The log level. Valid values are: 'panic', 'fatal', 'error', 'warn', 'info', 'debug', 'trace'." introductionVersion:"1.0.0"`
|
||||
Pretty bool `yaml:"pretty" env:"OCIS_LOG_PRETTY;STORAGE_KITEWORKS_LOG_PRETTY" desc:"Activates pretty log output." introductionVersion:"1.0.0"`
|
||||
Color bool `yaml:"color" env:"OCIS_LOG_COLOR;STORAGE_KITEWORKS_LOG_COLOR" desc:"Activates colorized log output." introductionVersion:"1.0.0"`
|
||||
File string `yaml:"file" env:"OCIS_LOG_FILE;STORAGE_KITEWORKS_LOG_FILE" desc:"The path to the log file. Activates logging to this file if set." introductionVersion:"1.0.0"`
|
||||
}
|
||||
|
||||
// Service holds general service configuration
|
||||
type Service struct {
|
||||
Name string `yaml:"-" env:"STORAGE_KITEWORKS_SERVICE_NAME" desc:"Service name to use. Change this when starting an additional storage provider with a custom configuration to prevent it from colliding with the default 'storage-kiteworks' service." introductionVersion:"1.0.0"`
|
||||
}
|
||||
|
||||
// Debug is the configuration for the debug server
|
||||
type Debug struct {
|
||||
Addr string `yaml:"addr" env:"STORAGE_KITEWORKS_DEBUG_ADDR" desc:"Bind address of the debug server, where metrics, health, config and debug endpoints will be exposed." introductionVersion:"1.0.0"`
|
||||
Token string `yaml:"token" env:"STORAGE_KITEWORKS_DEBUG_TOKEN" desc:"Token to secure the metrics endpoint." introductionVersion:"1.0.0"`
|
||||
Pprof bool `yaml:"pprof" env:"STORAGE_KITEWORKS_DEBUG_PPROF" desc:"Enables pprof, which can be used for profiling." introductionVersion:"1.0.0"`
|
||||
Zpages bool `yaml:"zpages" env:"STORAGE_KITEWORKS_DEBUG_ZPAGES" desc:"Enables zpages, which can be used for collecting and viewing in-memory traces." introductionVersion:"1.0.0"`
|
||||
}
|
||||
|
||||
// GRPCConfig is the configuration for the grpc server
|
||||
type GRPCConfig struct {
|
||||
Addr string `yaml:"addr" env:"STORAGE_KITEWORKS_GRPC_ADDR" desc:"The bind address of the GRPC service." introductionVersion:"1.0.0"`
|
||||
TLS *shared.GRPCServiceTLS `yaml:"tls"`
|
||||
Namespace string `yaml:"-"`
|
||||
Protocol string `yaml:"protocol" env:"OCIS_GRPC_PROTOCOL;STORAGE_KITEWORKS_GRPC_PROTOCOL" desc:"The transport protocol of the GPRC service." introductionVersion:"1.0.0"`
|
||||
}
|
||||
|
||||
// KiteworksDriver holds the Kiteworks-specific driver configuration
|
||||
type KiteworksDriver struct {
|
||||
Endpoint string `yaml:"endpoint" env:"STORAGE_KITEWORKS_ENDPOINT" desc:"Base URL of the Kiteworks server, e.g. https://kiteworks.example.com." introductionVersion:"1.0.0"`
|
||||
Insecure bool `yaml:"insecure" env:"STORAGE_KITEWORKS_INSECURE" desc:"Skip TLS certificate verification (development only)." introductionVersion:"1.0.0"`
|
||||
ChunkSize int64 `yaml:"chunk_size" env:"STORAGE_KITEWORKS_CHUNK_SIZE" desc:"Upload chunk size in bytes. Default 5242880 (5 MB)." introductionVersion:"1.0.0"`
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package defaults
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/structs"
|
||||
"github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/config"
|
||||
)
|
||||
|
||||
// FullDefaultConfig returns a fully initialized default configuration
|
||||
func FullDefaultConfig() *config.Config {
|
||||
cfg := DefaultConfig()
|
||||
EnsureDefaults(cfg)
|
||||
Sanitize(cfg)
|
||||
return cfg
|
||||
}
|
||||
|
||||
// DefaultConfig returns a basic default configuration
|
||||
func DefaultConfig() *config.Config {
|
||||
return &config.Config{
|
||||
Debug: config.Debug{
|
||||
Addr: "127.0.0.1:9289",
|
||||
Token: "",
|
||||
Pprof: false,
|
||||
Zpages: false,
|
||||
},
|
||||
GRPC: config.GRPCConfig{
|
||||
Addr: "127.0.0.1:9285",
|
||||
Namespace: "com.owncloud.api",
|
||||
Protocol: "tcp",
|
||||
},
|
||||
Service: config.Service{
|
||||
Name: "storage-kiteworks",
|
||||
},
|
||||
Reva: shared.DefaultRevaConfig(),
|
||||
GracefulShutdownTimeout: 30,
|
||||
Driver: config.KiteworksDriver{
|
||||
ChunkSize: 5 * 1024 * 1024,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// EnsureDefaults adds default values to the configuration if they are not set yet
|
||||
func EnsureDefaults(cfg *config.Config) {
|
||||
// provide with defaults for shared logging, since we need a valid destination address for "envdecode".
|
||||
if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
|
||||
cfg.Log = &config.Log{
|
||||
Level: cfg.Commons.Log.Level,
|
||||
Pretty: cfg.Commons.Log.Pretty,
|
||||
Color: cfg.Commons.Log.Color,
|
||||
File: cfg.Commons.Log.File,
|
||||
}
|
||||
} else if cfg.Log == nil {
|
||||
cfg.Log = &config.Log{}
|
||||
}
|
||||
// provide with defaults for shared tracing, since we need a valid destination address for "envdecode".
|
||||
if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil {
|
||||
cfg.Tracing = &config.Tracing{
|
||||
Enabled: cfg.Commons.Tracing.Enabled,
|
||||
Type: cfg.Commons.Tracing.Type,
|
||||
Endpoint: cfg.Commons.Tracing.Endpoint,
|
||||
Collector: cfg.Commons.Tracing.Collector,
|
||||
}
|
||||
} else if cfg.Tracing == nil {
|
||||
cfg.Tracing = &config.Tracing{}
|
||||
}
|
||||
|
||||
if cfg.Reva == nil && cfg.Commons != nil {
|
||||
cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva)
|
||||
}
|
||||
|
||||
if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil {
|
||||
cfg.TokenManager = &config.TokenManager{
|
||||
JWTSecret: cfg.Commons.TokenManager.JWTSecret,
|
||||
}
|
||||
} else if cfg.TokenManager == nil {
|
||||
cfg.TokenManager = &config.TokenManager{}
|
||||
}
|
||||
|
||||
if cfg.GRPC.TLS == nil && cfg.Commons != nil {
|
||||
cfg.GRPC.TLS = structs.CopyOrZeroValue(cfg.Commons.GRPCServiceTLS)
|
||||
}
|
||||
}
|
||||
|
||||
// Sanitize sanitizes the configuration
|
||||
func Sanitize(cfg *config.Config) {
|
||||
// nothing to sanitize here atm
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package parser
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
ociscfg "github.com/owncloud/ocis/v2/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/envdecode"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
|
||||
"github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/config"
|
||||
"github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/config/defaults"
|
||||
)
|
||||
|
||||
// ParseConfig loads configuration from known paths.
|
||||
func ParseConfig(cfg *config.Config) error {
|
||||
err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defaults.EnsureDefaults(cfg)
|
||||
|
||||
// load all env variables relevant to the config in the current context.
|
||||
if err := envdecode.Decode(cfg); err != nil {
|
||||
// no environment variable set for this config is an expected "error"
|
||||
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
defaults.Sanitize(cfg)
|
||||
|
||||
return Validate(cfg)
|
||||
}
|
||||
|
||||
// Validate validates the configuration
|
||||
func Validate(cfg *config.Config) error {
|
||||
if cfg.TokenManager.JWTSecret == "" {
|
||||
return shared.MissingJWTTokenError(cfg.Service.Name)
|
||||
}
|
||||
|
||||
if cfg.MountID == "" {
|
||||
return fmt.Errorf("the storage-kiteworks mount ID has not been configured for %s. "+
|
||||
"Make sure to set the STORAGE_KITEWORKS_MOUNT_ID environment variable or configure it in the config file.",
|
||||
cfg.Service.Name)
|
||||
}
|
||||
|
||||
if cfg.Driver.Endpoint == "" {
|
||||
return fmt.Errorf("the Kiteworks endpoint has not been configured for %s. "+
|
||||
"Make sure to set the STORAGE_KITEWORKS_ENDPOINT environment variable or configure it in the config file.",
|
||||
cfg.Service.Name)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package config
|
||||
|
||||
// TokenManager is the config for using the reva token manager
|
||||
type TokenManager struct {
|
||||
JWTSecret string `yaml:"jwt_secret" env:"OCIS_JWT_SECRET;STORAGE_KITEWORKS_JWT_SECRET" desc:"The secret to mint and validate jwt tokens." introductionVersion:"1.0.0"`
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package config
|
||||
|
||||
import "github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
||||
|
||||
// Tracing configures the tracing
|
||||
type Tracing struct {
|
||||
Enabled bool `yaml:"enabled" env:"OCIS_TRACING_ENABLED;STORAGE_KITEWORKS_TRACING_ENABLED" desc:"Activates tracing." introductionVersion:"1.0.0"`
|
||||
Type string `yaml:"type" env:"OCIS_TRACING_TYPE;STORAGE_KITEWORKS_TRACING_TYPE" desc:"The type of tracing. Defaults to '', which is the same as 'jaeger'. Allowed tracing types are 'jaeger', 'otlp' and '' as of now." introductionVersion:"1.0.0"`
|
||||
Endpoint string `yaml:"endpoint" env:"OCIS_TRACING_ENDPOINT;STORAGE_KITEWORKS_TRACING_ENDPOINT" desc:"The endpoint of the tracing agent." introductionVersion:"1.0.0"`
|
||||
Collector string `yaml:"collector" env:"OCIS_TRACING_COLLECTOR;STORAGE_KITEWORKS_TRACING_COLLECTOR" desc:"The HTTP endpoint for sending spans directly to a collector, i.e. http://jaeger-collector:14268/api/traces. Only used if the tracing endpoint is unset." introductionVersion:"1.0.0"`
|
||||
}
|
||||
|
||||
// Convert converts Tracing to the tracing package's Config struct.
|
||||
func (t Tracing) Convert() tracing.Config {
|
||||
return tracing.Config{
|
||||
Enabled: t.Enabled,
|
||||
Type: t.Type,
|
||||
Endpoint: t.Endpoint,
|
||||
Collector: t.Collector,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/config"
|
||||
)
|
||||
|
||||
// Configure initializes a service-specific logger instance.
|
||||
func Configure(name string, cfg *config.Log) log.Logger {
|
||||
return log.NewLogger(
|
||||
log.Name(name),
|
||||
log.Level(cfg.Level),
|
||||
log.Pretty(cfg.Pretty),
|
||||
log.Color(cfg.Color),
|
||||
log.File(cfg.File),
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// Package revaconfig contains the config for the reva service
|
||||
package revaconfig
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/config"
|
||||
)
|
||||
|
||||
// StorageKiteworksConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
|
||||
func StorageKiteworksConfigFromStruct(cfg *config.Config) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"core": map[string]interface{}{
|
||||
"graceful_shutdown_timeout": cfg.GracefulShutdownTimeout,
|
||||
},
|
||||
"shared": map[string]interface{}{
|
||||
"jwt_secret": cfg.TokenManager.JWTSecret,
|
||||
"gatewaysvc": cfg.Reva.Address,
|
||||
"grpc_client_options": cfg.Reva.GetGRPCClientConfig(),
|
||||
},
|
||||
"grpc": map[string]interface{}{
|
||||
"network": cfg.GRPC.Protocol,
|
||||
"address": cfg.GRPC.Addr,
|
||||
"tls_settings": map[string]interface{}{
|
||||
"enabled": cfg.GRPC.TLS.Enabled,
|
||||
"certificate": cfg.GRPC.TLS.Cert,
|
||||
"key": cfg.GRPC.TLS.Key,
|
||||
},
|
||||
"interceptors": map[string]interface{}{
|
||||
"prometheus": map[string]interface{}{
|
||||
"namespace": "ocis",
|
||||
"subsystem": "storage_kiteworks",
|
||||
},
|
||||
},
|
||||
"services": map[string]interface{}{
|
||||
"storageprovider": map[string]interface{}{
|
||||
"driver": "kiteworks",
|
||||
"drivers": map[string]interface{}{
|
||||
"kiteworks": map[string]interface{}{
|
||||
"endpoint": cfg.Driver.Endpoint,
|
||||
"insecure": cfg.Driver.Insecure,
|
||||
"chunk_size": cfg.Driver.ChunkSize,
|
||||
},
|
||||
},
|
||||
"mount_id": cfg.MountID,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package debug
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/v2/services/storage-kiteworks/pkg/config"
|
||||
)
|
||||
|
||||
// Option defines a single option function.
|
||||
type Option func(o *Options)
|
||||
|
||||
// Options defines the available options for this package.
|
||||
type Options struct {
|
||||
Logger log.Logger
|
||||
Context context.Context
|
||||
Config *config.Config
|
||||
}
|
||||
|
||||
// newOptions initializes the available default options.
|
||||
func newOptions(opts ...Option) Options {
|
||||
opt := Options{}
|
||||
|
||||
for _, o := range opts {
|
||||
o(&opt)
|
||||
}
|
||||
|
||||
return opt
|
||||
}
|
||||
|
||||
// Logger provides a function to set the logger option.
|
||||
func Logger(val log.Logger) Option {
|
||||
return func(o *Options) {
|
||||
o.Logger = val
|
||||
}
|
||||
}
|
||||
|
||||
// Context provides a function to set the context option.
|
||||
func Context(val context.Context) Option {
|
||||
return func(o *Options) {
|
||||
o.Context = val
|
||||
}
|
||||
}
|
||||
|
||||
// Config provides a function to set the config option.
|
||||
func Config(val *config.Config) Option {
|
||||
return func(o *Options) {
|
||||
o.Config = val
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package debug
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/checks"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/debug"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||
)
|
||||
|
||||
// Server initializes the debug service and server.
|
||||
func Server(opts ...Option) (*http.Server, error) {
|
||||
options := newOptions(opts...)
|
||||
|
||||
readyHandler := handlers.NewCheckHandler(handlers.NewCheckHandlerConfiguration().
|
||||
WithLogger(options.Logger).
|
||||
WithCheck("grpc reachability", checks.NewGRPCCheck(options.Config.GRPC.Addr)),
|
||||
)
|
||||
|
||||
return debug.NewService(
|
||||
debug.Logger(options.Logger),
|
||||
debug.Context(options.Context),
|
||||
debug.Name(options.Config.Service.Name),
|
||||
debug.Version(version.GetString()),
|
||||
debug.Address(options.Config.Debug.Addr),
|
||||
debug.Token(options.Config.Debug.Token),
|
||||
debug.Pprof(options.Config.Debug.Pprof),
|
||||
debug.Zpages(options.Config.Debug.Zpages),
|
||||
debug.Ready(readyHandler),
|
||||
), nil
|
||||
}
|
||||
+277
@@ -0,0 +1,277 @@
|
||||
// vendor/github.com/owncloud/reva/v2/pkg/storage/fs/kiteworks/client.go
|
||||
package kiteworks
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const kiteworksAPIVersion = "28"
|
||||
|
||||
// ClientError wraps an unexpected HTTP status
|
||||
type ClientError struct {
|
||||
StatusCode int
|
||||
Body []byte
|
||||
}
|
||||
|
||||
func (e *ClientError) Error() string {
|
||||
return fmt.Sprintf("kiteworks: unexpected status %d: %s", e.StatusCode, e.Body)
|
||||
}
|
||||
|
||||
// Client is a Kiteworks REST API client scoped to a single user token
|
||||
type Client struct {
|
||||
endpoint string
|
||||
token string
|
||||
httpClient *http.Client
|
||||
}
|
||||
|
||||
// NewClient creates a Client. Set insecure=true only for development/testing.
|
||||
func NewClient(endpoint, token string, insecure bool) *Client {
|
||||
transport := http.DefaultTransport
|
||||
if insecure {
|
||||
transport = &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //nolint:gosec
|
||||
}
|
||||
}
|
||||
return &Client{
|
||||
endpoint: endpoint,
|
||||
token: token,
|
||||
httpClient: &http.Client{Transport: transport},
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) newRequest(method, path string, body io.Reader) (*http.Request, error) {
|
||||
req, err := http.NewRequest(method, c.endpoint+path, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Authorization", "Bearer "+c.token)
|
||||
req.Header.Set("X-Accellion-Version", kiteworksAPIVersion)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func (c *Client) do(req *http.Request) (*http.Response, error) {
|
||||
return c.httpClient.Do(req)
|
||||
}
|
||||
|
||||
func (c *Client) doJSON(method, path string, body interface{}, out interface{}) error {
|
||||
var bodyReader io.Reader
|
||||
if body != nil {
|
||||
data, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bodyReader = bytes.NewReader(data)
|
||||
}
|
||||
req, err := c.newRequest(method, path, bodyReader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp, err := c.do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
respBody, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp.StatusCode >= 300 {
|
||||
return &ClientError{StatusCode: resp.StatusCode, Body: respBody}
|
||||
}
|
||||
if out != nil {
|
||||
return json.Unmarshal(respBody, out)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetTopFolders returns the user's top-level folders
|
||||
func (c *Client) GetTopFolders() ([]FileInfo, error) {
|
||||
var result struct {
|
||||
Data []FileInfo `json:"data"`
|
||||
}
|
||||
err := c.doJSON(http.MethodGet, "/rest/folders/top", nil, &result)
|
||||
return result.Data, err
|
||||
}
|
||||
|
||||
// GetFolder returns folder metadata by ID
|
||||
func (c *Client) GetFolder(id string) (*FileInfo, error) {
|
||||
var fi FileInfo
|
||||
err := c.doJSON(http.MethodGet, "/rest/folders/"+id, nil, &fi)
|
||||
return &fi, err
|
||||
}
|
||||
|
||||
// ListFolder returns the children of a folder
|
||||
func (c *Client) ListFolder(id string) (*DirectoryInfo, error) {
|
||||
var result DirectoryInfo
|
||||
err := c.doJSON(http.MethodGet, "/rest/folders/"+id+"/children", nil, &result)
|
||||
return &result, err
|
||||
}
|
||||
|
||||
// CreateFolder creates a subfolder inside parent
|
||||
func (c *Client) CreateFolder(parentID, name string) (*FileInfo, error) {
|
||||
var fi FileInfo
|
||||
err := c.doJSON(http.MethodPost, "/rest/folders/"+parentID+"/folders",
|
||||
&CreateDir{Name: name, Syncable: true}, &fi)
|
||||
return &fi, err
|
||||
}
|
||||
|
||||
// DeleteFolder deletes a folder by ID
|
||||
func (c *Client) DeleteFolder(id string) error {
|
||||
return c.doJSON(http.MethodDelete, "/rest/folders/"+id, nil, nil)
|
||||
}
|
||||
|
||||
// RenameFolder renames a folder
|
||||
func (c *Client) RenameFolder(id, name string) error {
|
||||
return c.doJSON(http.MethodPut, "/rest/folders/"+id,
|
||||
&FolderUpdateRequest{Name: name}, nil)
|
||||
}
|
||||
|
||||
// GetFile returns file metadata by ID
|
||||
func (c *Client) GetFile(id string) (*FileInfo, error) {
|
||||
var fi FileInfo
|
||||
err := c.doJSON(http.MethodGet, "/rest/files/"+id, nil, &fi)
|
||||
return &fi, err
|
||||
}
|
||||
|
||||
// DownloadFile returns a ReadCloser for the file content. The caller must close it.
|
||||
// rangeHeader is optional (e.g. "bytes=0-1023").
|
||||
func (c *Client) DownloadFile(id, rangeHeader string) (*http.Response, error) {
|
||||
req, err := c.newRequest(http.MethodGet, "/rest/files/"+id+"/content", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if rangeHeader != "" {
|
||||
req.Header.Set("Range", rangeHeader)
|
||||
}
|
||||
return c.do(req)
|
||||
}
|
||||
|
||||
// DeleteFile deletes a file by ID
|
||||
func (c *Client) DeleteFile(id string) error {
|
||||
return c.doJSON(http.MethodDelete, "/rest/files/"+id, nil, nil)
|
||||
}
|
||||
|
||||
// RenameFile renames a file
|
||||
func (c *Client) RenameFile(id, name string, replace bool) error {
|
||||
return c.doJSON(http.MethodPut, "/rest/files/"+id,
|
||||
&FileUpdateRequest{Name: name, Replace: replace}, nil)
|
||||
}
|
||||
|
||||
// MoveResource moves a file or folder to a new parent folder
|
||||
func (c *Client) MoveResource(sourceID, destFolderID string, replace bool) error {
|
||||
err := c.doJSON(http.MethodPost, "/rest/files/"+sourceID+"/actions/move",
|
||||
&FileCopyMove{DestFolderID: destFolderID, Replace: replace}, nil)
|
||||
if err != nil {
|
||||
if ce, ok := err.(*ClientError); ok && ce.StatusCode == 404 {
|
||||
return c.doJSON(http.MethodPost, "/rest/folders/"+sourceID+"/actions/move",
|
||||
&FileCopyMove{DestFolderID: destFolderID, Replace: replace}, nil)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CopyResource copies a file or folder to a destination folder
|
||||
func (c *Client) CopyResource(sourceID, destFolderID string, replace bool) error {
|
||||
err := c.doJSON(http.MethodPost, "/rest/files/"+sourceID+"/actions/copy",
|
||||
&FileCopyMove{DestFolderID: destFolderID, Replace: replace}, nil)
|
||||
if err != nil {
|
||||
if ce, ok := err.(*ClientError); ok && ce.StatusCode == 404 {
|
||||
return c.doJSON(http.MethodPost, "/rest/folders/"+sourceID+"/actions/copy",
|
||||
&FileCopyMove{DestFolderID: destFolderID, Replace: replace}, nil)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitiateUpload starts a chunked upload session
|
||||
func (c *Client) InitiateUpload(parentID, filename string, size int64, numChunks int) (*UploadResult, error) {
|
||||
var result UploadResult
|
||||
err := c.doJSON(http.MethodPost, "/rest/folders/"+parentID+"/actions/initiateUpload",
|
||||
&InitializeUpload{
|
||||
Filename: filename,
|
||||
TotalChunks: numChunks,
|
||||
TotalFileSize: size,
|
||||
}, &result)
|
||||
return &result, err
|
||||
}
|
||||
|
||||
// UploadChunk uploads a single chunk. Returns FileInfo only on the last chunk.
|
||||
func (c *Client) UploadChunk(uploadURI, filename string, data []byte, chunkIndex int, isLastChunk bool) (*FileInfo, error) {
|
||||
var b bytes.Buffer
|
||||
w := multipart.NewWriter(&b)
|
||||
|
||||
_ = w.WriteField("index", strconv.Itoa(chunkIndex))
|
||||
_ = w.WriteField("compressionMode", "NORMAL")
|
||||
if isLastChunk {
|
||||
_ = w.WriteField("lastChunk", "1")
|
||||
}
|
||||
part, err := w.CreateFormFile("file", filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := part.Write(data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
w.Close()
|
||||
|
||||
req, err := http.NewRequest(http.MethodPost, c.endpoint+uploadURI, &b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Authorization", "Bearer "+c.token)
|
||||
req.Header.Set("X-Accellion-Version", kiteworksAPIVersion)
|
||||
req.Header.Set("Content-Type", w.FormDataContentType())
|
||||
|
||||
resp, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
respBody, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode >= 300 {
|
||||
return nil, &ClientError{StatusCode: resp.StatusCode, Body: respBody}
|
||||
}
|
||||
if !isLastChunk {
|
||||
return nil, nil
|
||||
}
|
||||
var fi FileInfo
|
||||
if err := json.Unmarshal(respBody, &fi); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &fi, nil
|
||||
}
|
||||
|
||||
// GetMe returns the current user's info including quota
|
||||
func (c *Client) GetMe() (*User, error) {
|
||||
var u User
|
||||
err := c.doJSON(http.MethodGet, "/rest/users/me", nil, &u)
|
||||
return &u, err
|
||||
}
|
||||
|
||||
// Search searches for a file/folder by path
|
||||
func (c *Client) Search(path string) ([]FileInfo, error) {
|
||||
var result struct {
|
||||
Files []FileInfo `json:"files"`
|
||||
Folders []FileInfo `json:"folders"`
|
||||
}
|
||||
err := c.doJSON(http.MethodGet, "/rest/query?query="+url.QueryEscape(path), nil, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items := append(result.Folders, result.Files...)
|
||||
return items, nil
|
||||
}
|
||||
+511
@@ -0,0 +1,511 @@
|
||||
// vendor/github.com/owncloud/reva/v2/pkg/storage/fs/kiteworks/kiteworks.go
|
||||
package kiteworks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"math"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog"
|
||||
|
||||
ctxpkg "github.com/owncloud/reva/v2/pkg/ctx"
|
||||
"github.com/owncloud/reva/v2/pkg/errtypes"
|
||||
"github.com/owncloud/reva/v2/pkg/events"
|
||||
"github.com/owncloud/reva/v2/pkg/storage"
|
||||
"github.com/owncloud/reva/v2/pkg/storage/fs/registry"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registry.Register("kiteworks", New)
|
||||
}
|
||||
|
||||
// Config holds the driver configuration decoded from reva mapstructure
|
||||
type Config struct {
|
||||
Endpoint string `mapstructure:"endpoint"`
|
||||
Insecure bool `mapstructure:"insecure"`
|
||||
ChunkSize int64 `mapstructure:"chunk_size"`
|
||||
}
|
||||
|
||||
// Driver implements storage.FS backed by the Kiteworks REST API
|
||||
type Driver struct {
|
||||
cfg *Config
|
||||
}
|
||||
|
||||
// New creates a new kiteworks storage driver
|
||||
func New(m map[string]interface{}, _ events.Stream, _ *zerolog.Logger) (storage.FS, error) {
|
||||
cfg := &Config{}
|
||||
if err := mapstructure.Decode(m, cfg); err != nil {
|
||||
return nil, errors.Wrap(err, "kiteworks: error decoding config")
|
||||
}
|
||||
if cfg.Endpoint == "" {
|
||||
return nil, errors.New("kiteworks: 'endpoint' must be set")
|
||||
}
|
||||
if cfg.ChunkSize <= 0 {
|
||||
cfg.ChunkSize = defaultChunkSize
|
||||
}
|
||||
return &Driver{cfg: cfg}, nil
|
||||
}
|
||||
|
||||
func (d *Driver) client(ctx context.Context) (*Client, error) {
|
||||
token, ok := ctxpkg.ContextGetToken(ctx)
|
||||
if !ok || token == "" {
|
||||
return nil, errtypes.PermissionDenied("kiteworks: no token in context")
|
||||
}
|
||||
return NewClient(d.cfg.Endpoint, token, d.cfg.Insecure), nil
|
||||
}
|
||||
|
||||
// fileInfoToResourceInfo converts a Kiteworks FileInfo to a CS3 ResourceInfo
|
||||
func fileInfoToResourceInfo(fi *FileInfo) *provider.ResourceInfo {
|
||||
ri := &provider.ResourceInfo{
|
||||
Id: &provider.ResourceId{
|
||||
StorageId: "kiteworks",
|
||||
OpaqueId: fi.ID,
|
||||
},
|
||||
Path: fi.Name,
|
||||
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
|
||||
Size: uint64(fi.Size),
|
||||
}
|
||||
if fi.IsDir() {
|
||||
ri.Type = provider.ResourceType_RESOURCE_TYPE_CONTAINER
|
||||
}
|
||||
if fi.Modified != nil {
|
||||
ri.Mtime = &typespb.Timestamp{
|
||||
Seconds: uint64(fi.Modified.Unix()),
|
||||
}
|
||||
}
|
||||
if fi.FingerPrints != nil {
|
||||
for _, fp := range fi.FingerPrints.FingerPrints {
|
||||
switch fp.Algo {
|
||||
case "sha1":
|
||||
ri.Checksum = &provider.ResourceChecksum{
|
||||
Type: provider.ResourceChecksumType_RESOURCE_CHECKSUM_TYPE_SHA1,
|
||||
Sum: fp.Hash,
|
||||
}
|
||||
case "md5":
|
||||
ri.Checksum = &provider.ResourceChecksum{
|
||||
Type: provider.ResourceChecksumType_RESOURCE_CHECKSUM_TYPE_MD5,
|
||||
Sum: fp.Hash,
|
||||
}
|
||||
case "adler32":
|
||||
ri.Checksum = &provider.ResourceChecksum{
|
||||
Type: provider.ResourceChecksumType_RESOURCE_CHECKSUM_TYPE_ADLER32,
|
||||
Sum: fp.Hash,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ri
|
||||
}
|
||||
|
||||
// spaceFromFileInfo converts a top-level Kiteworks folder to a CS3 StorageSpace
|
||||
func spaceFromFileInfo(fi *FileInfo) *provider.StorageSpace {
|
||||
spaceType := "project"
|
||||
if fi.IsSharedWithUser() {
|
||||
spaceType = "mountpoint"
|
||||
}
|
||||
sp := &provider.StorageSpace{
|
||||
Id: &provider.StorageSpaceId{
|
||||
OpaqueId: fi.ID,
|
||||
},
|
||||
Root: &provider.ResourceId{
|
||||
StorageId: "kiteworks",
|
||||
OpaqueId: fi.ID,
|
||||
},
|
||||
Name: fi.Name,
|
||||
SpaceType: spaceType,
|
||||
}
|
||||
if fi.Modified != nil {
|
||||
sp.Mtime = &typespb.Timestamp{
|
||||
Seconds: uint64(fi.Modified.Unix()),
|
||||
}
|
||||
}
|
||||
return sp
|
||||
}
|
||||
|
||||
// Shutdown implements storage.FS
|
||||
func (d *Driver) Shutdown(_ context.Context) error { return nil }
|
||||
|
||||
// ListStorageSpaces implements storage.FS — returns each top-level Kiteworks folder as a space
|
||||
func (d *Driver) ListStorageSpaces(ctx context.Context, _ []*provider.ListStorageSpacesRequest_Filter, _ bool) ([]*provider.StorageSpace, error) {
|
||||
c, err := d.client(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
folders, err := c.GetTopFolders()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
spaces := make([]*provider.StorageSpace, 0, len(folders))
|
||||
for i := range folders {
|
||||
spaces = append(spaces, spaceFromFileInfo(&folders[i]))
|
||||
}
|
||||
return spaces, nil
|
||||
}
|
||||
|
||||
// GetQuota implements storage.FS
|
||||
func (d *Driver) GetQuota(ctx context.Context, _ *provider.Reference) (uint64, uint64, uint64, error) {
|
||||
c, err := d.client(ctx)
|
||||
if err != nil {
|
||||
return 0, 0, 0, err
|
||||
}
|
||||
u, err := c.GetMe()
|
||||
if err != nil {
|
||||
return 0, 0, 0, err
|
||||
}
|
||||
total := uint64(u.Quota.Allowed)
|
||||
used := uint64(u.Quota.Used)
|
||||
var remaining uint64
|
||||
if total > used {
|
||||
remaining = total - used
|
||||
}
|
||||
return total, used, remaining, nil
|
||||
}
|
||||
|
||||
// GetMD implements storage.FS
|
||||
func (d *Driver) GetMD(ctx context.Context, ref *provider.Reference, _, _ []string) (*provider.ResourceInfo, error) {
|
||||
c, err := d.client(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id := ref.GetResourceId().GetOpaqueId()
|
||||
if id == "" && ref.GetPath() == "" {
|
||||
return nil, errtypes.NotFound("kiteworks: reference has no id or path")
|
||||
}
|
||||
if id == "" && ref.GetPath() != "" {
|
||||
// path-based lookup via search
|
||||
results, err := c.Search(ref.GetPath())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(results) == 0 {
|
||||
return nil, errtypes.NotFound(ref.GetPath())
|
||||
}
|
||||
return fileInfoToResourceInfo(&results[0]), nil
|
||||
}
|
||||
// Try folder first, fall back to file
|
||||
fi, err := c.GetFolder(id)
|
||||
if err != nil {
|
||||
if ce, ok := err.(*ClientError); ok && ce.StatusCode == 404 {
|
||||
fi, err = c.GetFile(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return fileInfoToResourceInfo(fi), nil
|
||||
}
|
||||
|
||||
// ListFolder implements storage.FS
|
||||
func (d *Driver) ListFolder(ctx context.Context, ref *provider.Reference, _, _ []string) ([]*provider.ResourceInfo, error) {
|
||||
c, err := d.client(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id := ref.GetResourceId().GetOpaqueId()
|
||||
if id == "" {
|
||||
return nil, errtypes.NotFound("kiteworks: reference has no id")
|
||||
}
|
||||
dir, err := c.ListFolder(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var infos []*provider.ResourceInfo
|
||||
for i := range dir.Folders {
|
||||
infos = append(infos, fileInfoToResourceInfo(&dir.Folders[i]))
|
||||
}
|
||||
for i := range dir.Files {
|
||||
infos = append(infos, fileInfoToResourceInfo(&dir.Files[i]))
|
||||
}
|
||||
return infos, nil
|
||||
}
|
||||
|
||||
// Download implements storage.FS
|
||||
func (d *Driver) Download(ctx context.Context, ref *provider.Reference, openReaderFunc func(*provider.ResourceInfo) bool) (*provider.ResourceInfo, io.ReadCloser, error) {
|
||||
c, err := d.client(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
id := ref.GetResourceId().GetOpaqueId()
|
||||
if id == "" {
|
||||
return nil, nil, errtypes.NotFound("kiteworks: reference has no id")
|
||||
}
|
||||
fi, err := c.GetFile(id)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
ri := fileInfoToResourceInfo(fi)
|
||||
if openReaderFunc != nil && !openReaderFunc(ri) {
|
||||
return ri, nil, nil
|
||||
}
|
||||
resp, err := c.DownloadFile(id, "")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if resp.StatusCode >= 300 {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
return nil, nil, &ClientError{StatusCode: resp.StatusCode, Body: body}
|
||||
}
|
||||
return ri, resp.Body, nil
|
||||
}
|
||||
|
||||
// GetPathByID implements storage.FS
|
||||
func (d *Driver) GetPathByID(ctx context.Context, id *provider.ResourceId) (string, error) {
|
||||
if id == nil || id.OpaqueId == "" {
|
||||
return "", errtypes.NotFound("kiteworks: missing resource id")
|
||||
}
|
||||
c, err := d.client(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
// Try folder first, fall back to file
|
||||
fi, err := c.GetFolder(id.OpaqueId)
|
||||
if err != nil {
|
||||
if ce, ok := err.(*ClientError); ok && ce.StatusCode == 404 {
|
||||
fi, err = c.GetFile(id.OpaqueId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
} else {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
return fi.Path, nil
|
||||
}
|
||||
|
||||
// --- Stubbed / not-supported operations ---
|
||||
|
||||
func (d *Driver) CreateStorageSpace(_ context.Context, _ *provider.CreateStorageSpaceRequest) (*provider.CreateStorageSpaceResponse, error) {
|
||||
return nil, errtypes.NotSupported("kiteworks: CreateStorageSpace")
|
||||
}
|
||||
func (d *Driver) UpdateStorageSpace(_ context.Context, _ *provider.UpdateStorageSpaceRequest) (*provider.UpdateStorageSpaceResponse, error) {
|
||||
return nil, errtypes.NotSupported("kiteworks: UpdateStorageSpace")
|
||||
}
|
||||
func (d *Driver) DeleteStorageSpace(_ context.Context, _ *provider.DeleteStorageSpaceRequest) error {
|
||||
return errtypes.NotSupported("kiteworks: DeleteStorageSpace")
|
||||
}
|
||||
func (d *Driver) CreateHome(_ context.Context) error {
|
||||
return errtypes.NotSupported("kiteworks: CreateHome")
|
||||
}
|
||||
func (d *Driver) GetHome(_ context.Context) (string, error) {
|
||||
return "", errtypes.NotSupported("kiteworks: GetHome")
|
||||
}
|
||||
func (d *Driver) CreateReference(_ context.Context, _ string, _ *url.URL) error {
|
||||
return errtypes.NotSupported("kiteworks: CreateReference")
|
||||
}
|
||||
func (d *Driver) CreateDir(ctx context.Context, ref *provider.Reference) error {
|
||||
c, err := d.client(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
parentID := ref.GetResourceId().GetOpaqueId()
|
||||
name := ref.GetPath()
|
||||
if parentID == "" || name == "" {
|
||||
return errtypes.NotFound("kiteworks: CreateDir requires a parent ID and name")
|
||||
}
|
||||
_, err = c.CreateFolder(parentID, name)
|
||||
return err
|
||||
}
|
||||
func (d *Driver) TouchFile(ctx context.Context, ref *provider.Reference, _ bool, _ string) error {
|
||||
c, err := d.client(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
parentID := ref.GetResourceId().GetOpaqueId()
|
||||
name := ref.GetPath()
|
||||
if parentID == "" || name == "" {
|
||||
return errtypes.NotFound("kiteworks: TouchFile requires a parent ID and name")
|
||||
}
|
||||
_, err = uploadFile(c, parentID, name, 0, strings.NewReader(""), d.cfg.ChunkSize)
|
||||
return err
|
||||
}
|
||||
func (d *Driver) Delete(ctx context.Context, ref *provider.Reference) error {
|
||||
c, err := d.client(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
id := ref.GetResourceId().GetOpaqueId()
|
||||
if id == "" {
|
||||
return errtypes.NotFound("kiteworks: reference has no id")
|
||||
}
|
||||
err = c.DeleteFolder(id)
|
||||
if err != nil {
|
||||
if ce, ok := err.(*ClientError); ok && ce.StatusCode == 404 {
|
||||
return c.DeleteFile(id)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (d *Driver) Move(ctx context.Context, oldRef, newRef *provider.Reference) error {
|
||||
c, err := d.client(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sourceID := oldRef.GetResourceId().GetOpaqueId()
|
||||
if sourceID == "" {
|
||||
return errtypes.NotFound("kiteworks: source reference has no id")
|
||||
}
|
||||
destFolderID := newRef.GetResourceId().GetOpaqueId()
|
||||
if destFolderID == "" {
|
||||
// rename: try file first, fall back to folder
|
||||
err = c.RenameFile(sourceID, newRef.GetPath(), false)
|
||||
if err != nil {
|
||||
if ce, ok := err.(*ClientError); ok && ce.StatusCode == 404 {
|
||||
return c.RenameFolder(sourceID, newRef.GetPath())
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return c.MoveResource(sourceID, destFolderID, false)
|
||||
}
|
||||
func (d *Driver) InitiateUpload(ctx context.Context, ref *provider.Reference, uploadLength int64, metadata map[string]string) (map[string]string, error) {
|
||||
c, err := d.client(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
parentID := ref.GetResourceId().GetOpaqueId()
|
||||
filename := metadata["filename"]
|
||||
if filename == "" {
|
||||
filename = ref.GetPath()
|
||||
}
|
||||
numChunks := 1
|
||||
if uploadLength > 0 {
|
||||
numChunks = int(math.Ceil(float64(uploadLength) / float64(d.cfg.ChunkSize)))
|
||||
}
|
||||
result, err := c.InitiateUpload(parentID, filename, uploadLength, numChunks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return map[string]string{
|
||||
"uploadID": result.ID,
|
||||
"uploadURI": result.URI,
|
||||
"filename": filename,
|
||||
"parentID": parentID,
|
||||
}, nil
|
||||
}
|
||||
func (d *Driver) Upload(ctx context.Context, req storage.UploadRequest, uploadFunc storage.UploadFinishedFunc) (*provider.ResourceInfo, error) {
|
||||
c, err := d.client(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
parentID := req.Ref.GetResourceId().GetOpaqueId()
|
||||
filename := req.Ref.GetPath()
|
||||
fi, err := uploadFile(c, parentID, filename, req.Length, req.Body, d.cfg.ChunkSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ri := fileInfoToResourceInfo(fi)
|
||||
if uploadFunc != nil {
|
||||
u, ok := ctxpkg.ContextGetUser(ctx)
|
||||
if !ok {
|
||||
return nil, errtypes.PermissionDenied("kiteworks: no user in context")
|
||||
}
|
||||
uploadFunc(u.GetId(), u.GetId(), req.Ref)
|
||||
}
|
||||
return ri, nil
|
||||
}
|
||||
func (d *Driver) ListRevisions(_ context.Context, _ *provider.Reference) ([]*provider.FileVersion, error) {
|
||||
return nil, errtypes.NotSupported("kiteworks: ListRevisions")
|
||||
}
|
||||
func (d *Driver) DownloadRevision(_ context.Context, _ *provider.Reference, _ string, _ func(*provider.ResourceInfo) bool) (*provider.ResourceInfo, io.ReadCloser, error) {
|
||||
return nil, nil, errtypes.NotSupported("kiteworks: DownloadRevision")
|
||||
}
|
||||
func (d *Driver) RestoreRevision(_ context.Context, _ *provider.Reference, _ string) error {
|
||||
return errtypes.NotSupported("kiteworks: RestoreRevision")
|
||||
}
|
||||
func (d *Driver) ListRecycle(_ context.Context, _ *provider.Reference, _, _ string) ([]*provider.RecycleItem, error) {
|
||||
return nil, errtypes.NotSupported("kiteworks: ListRecycle")
|
||||
}
|
||||
func (d *Driver) RestoreRecycleItem(_ context.Context, _ *provider.Reference, _, _ string, _ *provider.Reference) error {
|
||||
return errtypes.NotSupported("kiteworks: RestoreRecycleItem")
|
||||
}
|
||||
func (d *Driver) PurgeRecycleItem(_ context.Context, _ *provider.Reference, _, _ string) error {
|
||||
return errtypes.NotSupported("kiteworks: PurgeRecycleItem")
|
||||
}
|
||||
func (d *Driver) EmptyRecycle(_ context.Context, _ *provider.Reference) error {
|
||||
return errtypes.NotSupported("kiteworks: EmptyRecycle")
|
||||
}
|
||||
func (d *Driver) AddGrant(_ context.Context, _ *provider.Reference, _ *provider.Grant) error {
|
||||
return errtypes.NotSupported("kiteworks: AddGrant — permission mapping not yet implemented")
|
||||
}
|
||||
func (d *Driver) DenyGrant(_ context.Context, _ *provider.Reference, _ *provider.Grantee) error {
|
||||
return errtypes.NotSupported("kiteworks: DenyGrant")
|
||||
}
|
||||
func (d *Driver) RemoveGrant(_ context.Context, _ *provider.Reference, _ *provider.Grant) error {
|
||||
return errtypes.NotSupported("kiteworks: RemoveGrant — permission mapping not yet implemented")
|
||||
}
|
||||
func (d *Driver) UpdateGrant(_ context.Context, _ *provider.Reference, _ *provider.Grant) error {
|
||||
return errtypes.NotSupported("kiteworks: UpdateGrant — permission mapping not yet implemented")
|
||||
}
|
||||
func (d *Driver) ListGrants(ctx context.Context, ref *provider.Reference) ([]*provider.Grant, error) {
|
||||
c, err := d.client(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id := ref.GetResourceId().GetOpaqueId()
|
||||
if id == "" {
|
||||
return nil, errtypes.NotFound("kiteworks: reference has no id")
|
||||
}
|
||||
fi, err := c.GetFolder(id)
|
||||
if err != nil {
|
||||
if ce, ok := err.(*ClientError); ok && ce.StatusCode == 404 {
|
||||
fi, err = c.GetFile(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
var grants []*provider.Grant
|
||||
for _, perm := range fi.Permissions {
|
||||
if !perm.Allowed {
|
||||
continue
|
||||
}
|
||||
grants = append(grants, &provider.Grant{
|
||||
Grantee: &provider.Grantee{
|
||||
Type: provider.GranteeType_GRANTEE_TYPE_USER,
|
||||
Id: &provider.Grantee_UserId{
|
||||
UserId: &userpb.UserId{OpaqueId: perm.Name},
|
||||
},
|
||||
},
|
||||
Permissions: &provider.ResourcePermissions{
|
||||
GetPath: true,
|
||||
InitiateFileDownload: true,
|
||||
InitiateFileUpload: true,
|
||||
ListContainer: true,
|
||||
Stat: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
return grants, nil
|
||||
}
|
||||
func (d *Driver) SetArbitraryMetadata(_ context.Context, _ *provider.Reference, _ *provider.ArbitraryMetadata) error {
|
||||
return errtypes.NotSupported("kiteworks: SetArbitraryMetadata")
|
||||
}
|
||||
func (d *Driver) UnsetArbitraryMetadata(_ context.Context, _ *provider.Reference, _ []string) error {
|
||||
return errtypes.NotSupported("kiteworks: UnsetArbitraryMetadata")
|
||||
}
|
||||
func (d *Driver) GetLock(_ context.Context, _ *provider.Reference) (*provider.Lock, error) {
|
||||
return nil, errtypes.NotSupported("kiteworks: GetLock")
|
||||
}
|
||||
func (d *Driver) SetLock(_ context.Context, _ *provider.Reference, _ *provider.Lock) error {
|
||||
return errtypes.NotSupported("kiteworks: SetLock")
|
||||
}
|
||||
func (d *Driver) RefreshLock(_ context.Context, _ *provider.Reference, _ *provider.Lock, _ string) error {
|
||||
return errtypes.NotSupported("kiteworks: RefreshLock")
|
||||
}
|
||||
func (d *Driver) Unlock(_ context.Context, _ *provider.Reference, _ *provider.Lock) error {
|
||||
return errtypes.NotSupported("kiteworks: Unlock")
|
||||
}
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
// vendor/github.com/owncloud/reva/v2/pkg/storage/fs/kiteworks/types.go
|
||||
package kiteworks
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Time is a custom time type that handles Kiteworks date format
|
||||
type Time struct {
|
||||
time.Time
|
||||
}
|
||||
|
||||
func (t *Time) UnmarshalJSON(data []byte) error {
|
||||
s := strings.Trim(string(data), `"`)
|
||||
if s == "null" || s == "" {
|
||||
return nil
|
||||
}
|
||||
parsed, err := time.Parse("2006-01-02T15:04:05+0000", s)
|
||||
if err != nil {
|
||||
parsed, err = time.Parse(time.RFC3339, s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
t.Time = parsed
|
||||
return nil
|
||||
}
|
||||
|
||||
// FileFingerPrint holds a single hash entry
|
||||
type FileFingerPrint struct {
|
||||
Algo string `json:"algo"`
|
||||
Hash string `json:"hash"`
|
||||
}
|
||||
|
||||
// FileFingerPrints holds all checksums for a file
|
||||
type FileFingerPrints struct {
|
||||
FingerPrints []FileFingerPrint `json:"fingerprints"`
|
||||
}
|
||||
|
||||
// Permission represents a Kiteworks permission entry
|
||||
type Permission struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Allowed bool `json:"allowed"`
|
||||
}
|
||||
|
||||
// FileInfo is the metadata for a Kiteworks file or folder
|
||||
type FileInfo struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
Type string `json:"type"` // "d" = directory, "f" = file
|
||||
Size int64 `json:"size"`
|
||||
Modified *Time `json:"modified"`
|
||||
Created *Time `json:"created"`
|
||||
ParentID *string `json:"parentId"`
|
||||
IsShared *bool `json:"shared"`
|
||||
Permissions []Permission `json:"currentUserPermissions"`
|
||||
FingerPrints *FileFingerPrints `json:"fileFingerprints"`
|
||||
}
|
||||
|
||||
// IsDir returns true if the FileInfo represents a directory
|
||||
func (fi *FileInfo) IsDir() bool {
|
||||
return fi.Type == "d"
|
||||
}
|
||||
|
||||
// IsSharedWithUser returns true when this top-level folder is a received share
|
||||
func (fi *FileInfo) IsSharedWithUser() bool {
|
||||
if fi == nil || fi.IsShared == nil || !*fi.IsShared {
|
||||
return false
|
||||
}
|
||||
if fi.ParentID == nil {
|
||||
return true
|
||||
}
|
||||
return *fi.ParentID == "0"
|
||||
}
|
||||
|
||||
// DirectoryInfo wraps a listing of files and folders
|
||||
type DirectoryInfo struct {
|
||||
Files []FileInfo `json:"files"`
|
||||
Folders []FileInfo `json:"folders"`
|
||||
}
|
||||
|
||||
// CreateDir is the request body for creating a folder
|
||||
type CreateDir struct {
|
||||
Name string `json:"name"`
|
||||
Syncable bool `json:"syncable"`
|
||||
}
|
||||
|
||||
// InitializeUpload is the request body for initiating a chunked upload
|
||||
type InitializeUpload struct {
|
||||
Filename string `json:"filename"`
|
||||
TotalChunks int `json:"totalChunks"`
|
||||
TotalFileSize int64 `json:"totalFileSize"`
|
||||
}
|
||||
|
||||
// UploadResult is the response from initiating an upload
|
||||
type UploadResult struct {
|
||||
ID string `json:"id"`
|
||||
URI string `json:"uri"`
|
||||
}
|
||||
|
||||
// FileCopyMove is the request body for move/copy operations
|
||||
type FileCopyMove struct {
|
||||
DestFolderID string `json:"destFolderId"`
|
||||
Replace bool `json:"replace"`
|
||||
}
|
||||
|
||||
// FileUpdateRequest is the request body for renaming a file
|
||||
type FileUpdateRequest struct {
|
||||
Name string `json:"name"`
|
||||
Replace bool `json:"replace"`
|
||||
}
|
||||
|
||||
// FolderUpdateRequest is the request body for renaming a folder
|
||||
type FolderUpdateRequest struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// QuotaInfo holds user storage quota information
|
||||
type QuotaInfo struct {
|
||||
Allowed int64 `json:"storageQuota"`
|
||||
Used int64 `json:"storageUsed"`
|
||||
}
|
||||
|
||||
// User holds Kiteworks user information
|
||||
type User struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Quota QuotaInfo `json:"quota"`
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
// vendor/github.com/owncloud/reva/v2/pkg/storage/fs/kiteworks/upload.go
|
||||
package kiteworks
|
||||
|
||||
import (
|
||||
"io"
|
||||
"math"
|
||||
)
|
||||
|
||||
const defaultChunkSize = 5 * 1024 * 1024 // 5 MB
|
||||
|
||||
// uploadFile performs a chunked upload of r into parentFolderID.
|
||||
// chunkSize of 0 uses defaultChunkSize.
|
||||
func uploadFile(c *Client, parentFolderID, filename string, size int64, r io.Reader, chunkSize int64) (*FileInfo, error) {
|
||||
if chunkSize <= 0 {
|
||||
chunkSize = defaultChunkSize
|
||||
}
|
||||
|
||||
numChunks := 1
|
||||
if size > 0 {
|
||||
numChunks = int(math.Ceil(float64(size) / float64(chunkSize)))
|
||||
}
|
||||
|
||||
result, err := c.InitiateUpload(parentFolderID, filename, size, numChunks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
buf := make([]byte, chunkSize)
|
||||
var fi *FileInfo
|
||||
for i := 0; i < numChunks; i++ {
|
||||
n, err := io.ReadFull(r, buf)
|
||||
if err != nil && err != io.ErrUnexpectedEOF && err != io.EOF {
|
||||
return nil, err
|
||||
}
|
||||
isLast := i == numChunks-1
|
||||
fi, err = c.UploadChunk(result.URI, filename, buf[:n], i, isLast)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return fi, nil
|
||||
}
|
||||
+1
@@ -29,6 +29,7 @@ import (
|
||||
_ "github.com/owncloud/reva/v2/pkg/storage/fs/hello"
|
||||
_ "github.com/owncloud/reva/v2/pkg/storage/fs/local"
|
||||
_ "github.com/owncloud/reva/v2/pkg/storage/fs/localhome"
|
||||
_ "github.com/owncloud/reva/v2/pkg/storage/fs/kiteworks"
|
||||
_ "github.com/owncloud/reva/v2/pkg/storage/fs/nextcloud"
|
||||
_ "github.com/owncloud/reva/v2/pkg/storage/fs/ocis"
|
||||
_ "github.com/owncloud/reva/v2/pkg/storage/fs/owncloudsql"
|
||||
|
||||
Vendored
+2
-1
@@ -1317,7 +1317,7 @@ github.com/orcaman/concurrent-map
|
||||
# github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245
|
||||
## explicit; go 1.18
|
||||
github.com/owncloud/libre-graph-api-go
|
||||
# github.com/owncloud/reva/v2 v2.0.0-20260424082219-c88989902d1a
|
||||
# github.com/owncloud/reva/v2 v2.0.0-20260511130900-472978d4d56c
|
||||
## explicit; go 1.25.0
|
||||
github.com/owncloud/reva/v2/cmd/revad/internal/grace
|
||||
github.com/owncloud/reva/v2/cmd/revad/runtime
|
||||
@@ -1609,6 +1609,7 @@ github.com/owncloud/reva/v2/pkg/storage/fs/eosgrpc
|
||||
github.com/owncloud/reva/v2/pkg/storage/fs/eosgrpchome
|
||||
github.com/owncloud/reva/v2/pkg/storage/fs/eoshome
|
||||
github.com/owncloud/reva/v2/pkg/storage/fs/hello
|
||||
github.com/owncloud/reva/v2/pkg/storage/fs/kiteworks
|
||||
github.com/owncloud/reva/v2/pkg/storage/fs/loader
|
||||
github.com/owncloud/reva/v2/pkg/storage/fs/local
|
||||
github.com/owncloud/reva/v2/pkg/storage/fs/localhome
|
||||
|
||||
Reference in new issue
Block a user