Skip to content

Commit

Permalink
Merge pull request #5207 from kobergj/AsyncPostprocessing
Browse files Browse the repository at this point in the history
[full-ci] Async Postprocessing
  • Loading branch information
kobergj authored Dec 16, 2022
2 parents b75e97e + c762d9d commit 341cdc9
Show file tree
Hide file tree
Showing 24 changed files with 657 additions and 35 deletions.
6 changes: 4 additions & 2 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -873,11 +873,13 @@ def wopiValidatorTests(ctx, storage, accounts_hash_difficulty = 4):
"image": OC_CI_ALPINE,
"environment": {},
"commands": [
"curl -k 'https://ocis-server:9200/remote.php/webdav/test.wopitest' --fail --retry-connrefused --retry 7 --retry-all-errors -X PUT -u admin:admin -D headers.txt",
"curl -v -X PUT 'https://ocis-server:9200/remote.php/webdav/test.wopitest' -k --fail --retry-connrefused --retry 7 --retry-all-errors -u admin:admin -D headers.txt",
"cat headers.txt",
"export FILE_ID=$(cat headers.txt | sed -n -e 's/^.*Oc-Fileid: //p')",
"export URL=\"https://ocis-server:9200/app/open?app_name=FakeOffice&file_id=$FILE_ID\"",
"export URL=$(echo $URL | tr -d '[:cntrl:]')",
"curl -k -X POST \"$URL\" -u admin:admin -v > open.json",
"curl -v -X POST \"$URL\" -k --fail --retry-connrefused --retry 7 --retry-all-errors -u admin:admin > open.json",
"cat open.json",
"cat open.json | jq .form_parameters.access_token | tr -d '\"' > accesstoken",
"cat open.json | jq .form_parameters.access_token_ttl | tr -d '\"' > accesstokenttl",
"echo -n 'http://wopiserver:8880/wopi/files/' > wopisrc",
Expand Down
5 changes: 5 additions & 0 deletions changelog/unreleased/async-postprocessing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Async Postprocessing

Provides functionality for async postprocessing. This will allow the system to do the postprocessing (virusscan, copying of bytes to their final destination, ...) asynchronous to the users request. Major change when active.

https://github.com/owncloud/ocis/pull/5207
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/blevesearch/bleve/v2 v2.3.5
github.com/coreos/go-oidc/v3 v3.4.0
github.com/cs3org/go-cs3apis v0.0.0-20221012090518-ef2996678965
github.com/cs3org/reva/v2 v2.12.0
github.com/cs3org/reva/v2 v2.12.1-0.20221214090401-47e0591bb902
github.com/disintegration/imaging v1.6.2
github.com/ggwhite/go-masker v1.0.9
github.com/go-chi/chi/v5 v5.0.7
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ github.com/crewjam/saml v0.4.6 h1:XCUFPkQSJLvzyl4cW9OvpWUbRf0gE7VUpU8ZnilbeM4=
github.com/crewjam/saml v0.4.6/go.mod h1:ZBOXnNPFzB3CgOkRm7Nd6IVdkG+l/wF+0ZXLqD96t1A=
github.com/cs3org/go-cs3apis v0.0.0-20221012090518-ef2996678965 h1:y4n2j68LLnvac+zw/al8MfPgO5aQiIwLmHM/JzYN8AM=
github.com/cs3org/go-cs3apis v0.0.0-20221012090518-ef2996678965/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/reva/v2 v2.12.0 h1:KGQnNje13BbWuQBnxnWKyk+JjYTrETE8Q71KqKpzQQo=
github.com/cs3org/reva/v2 v2.12.0/go.mod h1:+lH5G0UmNjMNj4F0bDhbh+HqL1UihlbL8zPBa57Y2QI=
github.com/cs3org/reva/v2 v2.12.1-0.20221214090401-47e0591bb902 h1:r8K9y0RMFXjQlrbx17iQziWYhNyAYmh70ixaXbQHsHY=
github.com/cs3org/reva/v2 v2.12.1-0.20221214090401-47e0591bb902/go.mod h1:GpocVB1w6yxeSr1VBsO9jztmt1SyNC4lCwudLwDzxHQ=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
Expand Down
60 changes: 31 additions & 29 deletions ocis-pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
notifications "github.com/owncloud/ocis/v2/services/notifications/pkg/config"
ocdav "github.com/owncloud/ocis/v2/services/ocdav/pkg/config"
ocs "github.com/owncloud/ocis/v2/services/ocs/pkg/config"
postprocessing "github.com/owncloud/ocis/v2/services/postprocessing/pkg/config"
proxy "github.com/owncloud/ocis/v2/services/proxy/pkg/config"
search "github.com/owncloud/ocis/v2/services/search/pkg/config"
settings "github.com/owncloud/ocis/v2/services/settings/pkg/config"
Expand Down Expand Up @@ -76,33 +77,34 @@ type Config struct {
AdminUserID string `yaml:"admin_user_id" env:"OCIS_ADMIN_USER_ID" desc:"ID of a user, that should receive admin privileges."`
Runtime Runtime `yaml:"runtime"`

AppProvider *appProvider.Config `yaml:"app_provider"`
AppRegistry *appRegistry.Config `yaml:"app_registry"`
Audit *audit.Config `yaml:"audit"`
AuthBasic *authbasic.Config `yaml:"auth_basic"`
AuthBearer *authbearer.Config `yaml:"auth_bearer"`
AuthMachine *authmachine.Config `yaml:"auth_machine"`
Frontend *frontend.Config `yaml:"frontend"`
Gateway *gateway.Config `yaml:"gateway"`
Graph *graph.Config `yaml:"graph"`
Groups *groups.Config `yaml:"groups"`
IDM *idm.Config `yaml:"idm"`
IDP *idp.Config `yaml:"idp"`
Nats *nats.Config `yaml:"nats"`
Notifications *notifications.Config `yaml:"notifications"`
OCDav *ocdav.Config `yaml:"ocdav"`
OCS *ocs.Config `yaml:"ocs"`
Proxy *proxy.Config `yaml:"proxy"`
Settings *settings.Config `yaml:"settings"`
Sharing *sharing.Config `yaml:"sharing"`
StorageSystem *storagesystem.Config `yaml:"storage_system"`
StoragePublicLink *storagepublic.Config `yaml:"storage_public"`
StorageShares *storageshares.Config `yaml:"storage_shares"`
StorageUsers *storageusers.Config `yaml:"storage_users"`
Store *store.Config `yaml:"store"`
Thumbnails *thumbnails.Config `yaml:"thumbnails"`
Users *users.Config `yaml:"users"`
Web *web.Config `yaml:"web"`
WebDAV *webdav.Config `yaml:"webdav"`
Search *search.Config `yaml:"search"`
AppProvider *appProvider.Config `yaml:"app_provider"`
AppRegistry *appRegistry.Config `yaml:"app_registry"`
Audit *audit.Config `yaml:"audit"`
AuthBasic *authbasic.Config `yaml:"auth_basic"`
AuthBearer *authbearer.Config `yaml:"auth_bearer"`
AuthMachine *authmachine.Config `yaml:"auth_machine"`
Frontend *frontend.Config `yaml:"frontend"`
Gateway *gateway.Config `yaml:"gateway"`
Graph *graph.Config `yaml:"graph"`
Groups *groups.Config `yaml:"groups"`
IDM *idm.Config `yaml:"idm"`
IDP *idp.Config `yaml:"idp"`
Nats *nats.Config `yaml:"nats"`
Notifications *notifications.Config `yaml:"notifications"`
OCDav *ocdav.Config `yaml:"ocdav"`
OCS *ocs.Config `yaml:"ocs"`
Postprocessing *postprocessing.Config `yaml:"postprocessing"`
Proxy *proxy.Config `yaml:"proxy"`
Settings *settings.Config `yaml:"settings"`
Sharing *sharing.Config `yaml:"sharing"`
StorageSystem *storagesystem.Config `yaml:"storage_system"`
StoragePublicLink *storagepublic.Config `yaml:"storage_public"`
StorageShares *storageshares.Config `yaml:"storage_shares"`
StorageUsers *storageusers.Config `yaml:"storage_users"`
Store *store.Config `yaml:"store"`
Thumbnails *thumbnails.Config `yaml:"thumbnails"`
Users *users.Config `yaml:"users"`
Web *web.Config `yaml:"web"`
WebDAV *webdav.Config `yaml:"webdav"`
Search *search.Config `yaml:"search"`
}
2 changes: 2 additions & 0 deletions ocis-pkg/config/defaultconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
notifications "github.com/owncloud/ocis/v2/services/notifications/pkg/config/defaults"
ocdav "github.com/owncloud/ocis/v2/services/ocdav/pkg/config/defaults"
ocs "github.com/owncloud/ocis/v2/services/ocs/pkg/config/defaults"
postprocessing "github.com/owncloud/ocis/v2/services/postprocessing/pkg/config/defaults"
proxy "github.com/owncloud/ocis/v2/services/proxy/pkg/config/defaults"
search "github.com/owncloud/ocis/v2/services/search/pkg/config/defaults"
settings "github.com/owncloud/ocis/v2/services/settings/pkg/config/defaults"
Expand Down Expand Up @@ -56,6 +57,7 @@ func DefaultConfig() *Config {
Notifications: notifications.DefaultConfig(),
OCDav: ocdav.DefaultConfig(),
OCS: ocs.DefaultConfig(),
Postprocessing: postprocessing.DefaultConfig(),
Proxy: proxy.DefaultConfig(),
Search: search.FullDefaultConfig(),
Settings: settings.DefaultConfig(),
Expand Down
4 changes: 3 additions & 1 deletion ocis/pkg/runtime/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
notifications "github.com/owncloud/ocis/v2/services/notifications/pkg/command"
ocdav "github.com/owncloud/ocis/v2/services/ocdav/pkg/command"
ocs "github.com/owncloud/ocis/v2/services/ocs/pkg/command"
postprocessing "github.com/owncloud/ocis/v2/services/postprocessing/pkg/command"
proxy "github.com/owncloud/ocis/v2/services/proxy/pkg/command"
search "github.com/owncloud/ocis/v2/services/search/pkg/command"
settings "github.com/owncloud/ocis/v2/services/settings/pkg/command"
Expand Down Expand Up @@ -125,6 +126,7 @@ func NewService(options ...Option) (*Service, error) {
s.ServicesRegistry[opts.Config.AppProvider.Service.Name] = appProvider.NewSutureService
s.ServicesRegistry[opts.Config.Notifications.Service.Name] = notifications.NewSutureService
s.ServicesRegistry[opts.Config.Search.Service.Name] = search.NewSutureService
s.ServicesRegistry[opts.Config.Postprocessing.Service.Name] = postprocessing.NewSutureService

// populate delayed services
s.Delayed[opts.Config.Sharing.Service.Name] = sharing.NewSutureService
Expand Down Expand Up @@ -262,7 +264,7 @@ func (s *Service) generateRunSet(cfg *ociscfg.Config) {
}

// List running processes for the Service Controller.
func (s *Service) List(args struct{}, reply *string) error {
func (s *Service) List(_ struct{}, reply *string) error {
tableString := &strings.Builder{}
table := tablewriter.NewWriter(tableString)
table.SetHeader([]string{"Service"})
Expand Down
37 changes: 37 additions & 0 deletions services/postprocessing/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
SHELL := bash
NAME := postprocessing

include ../../.make/recursion.mk

############ tooling ############
ifneq (, $(shell command -v go 2> /dev/null)) # suppress `command not found warnings` for non go targets in CI
include ../../.bingo/Variables.mk
endif

############ go tooling ############
include ../../.make/go.mk

############ release ############
include ../../.make/release.mk

############ docs generate ############
include ../../.make/docs.mk

.PHONY: docs-generate
docs-generate: config-docs-generate

############ generate ############
include ../../.make/generate.mk

.PHONY: ci-go-generate
ci-go-generate: # CI runs ci-node-generate automatically before this target

.PHONY: ci-node-generate
ci-node-generate:

############ licenses ############
.PHONY: ci-node-check-licenses
ci-node-check-licenses:

.PHONY: ci-node-save-licenses
ci-node-save-licenses:
14 changes: 14 additions & 0 deletions services/postprocessing/cmd/postprocessing/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"os"

"github.com/owncloud/ocis/v2/services/postprocessing/pkg/command"
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config/defaults"
)

func main() {
if err := command.Execute(defaults.DefaultConfig()); err != nil {
os.Exit(1)
}
}
18 changes: 18 additions & 0 deletions services/postprocessing/pkg/command/health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package command

import (
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config"
"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",
Action: func(c *cli.Context) error {
// Not implemented
return nil
},
}
}
56 changes: 56 additions & 0 deletions services/postprocessing/pkg/command/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package command

import (
"context"
"os"

"github.com/owncloud/ocis/v2/ocis-pkg/clihelper"
ociscfg "github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config"
"github.com/thejerf/suture/v4"
"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),

// interaction with this service

// infos about this service
Health(cfg),
Version(cfg),
}
}

// Execute is the entry point for the postprocessing command.
func Execute(cfg *config.Config) error {
app := clihelper.DefaultApp(&cli.App{
Name: "postprocessing",
Usage: "starts postprocessing service",
Commands: GetCommands(cfg),
})

return app.Run(os.Args)
}

// SutureService allows for the postprocessing command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
cfg *config.Config
}

// NewSutureService creates a new postprocessing.SutureService
func NewSutureService(cfg *ociscfg.Config) suture.Service {
cfg.Postprocessing.Commons = cfg.Commons
return SutureService{
cfg: cfg.Postprocessing,
}
}

// Serve to implement Server interface
func (s SutureService) Serve(ctx context.Context) error {
s.cfg.Context = ctx
return Execute(s.cfg)
}
75 changes: 75 additions & 0 deletions services/postprocessing/pkg/command/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package command

import (
"crypto/tls"
"crypto/x509"
"fmt"
"os"

"github.com/cs3org/reva/v2/pkg/events/server"
"github.com/go-micro/plugins/v4/events/natsjs"
ociscrypto "github.com/owncloud/ocis/v2/ocis-pkg/crypto"
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config"
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config/parser"
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/logging"
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/service"
"github.com/urfave/cli/v2"
)

// Server is the entrypoint for the server command.
func Server(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "server",
Usage: fmt.Sprintf("start %s service without runtime (unsupervised mode)", cfg.Service.Name),
Category: "server",
Before: func(c *cli.Context) error {
err := parser.ParseConfig(cfg)
if err != nil {
fmt.Printf("%v", err)
os.Exit(1)
}
return err
},
Action: func(c *cli.Context) error {
logger := logging.Configure(cfg.Service.Name, cfg.Log)

evtsCfg := cfg.Postprocessing.Events
var tlsConf *tls.Config

if !evtsCfg.TLSInsecure {
var rootCAPool *x509.CertPool
if evtsCfg.TLSRootCACertificate != "" {
rootCrtFile, err := os.Open(evtsCfg.TLSRootCACertificate)
if err != nil {
return err
}

rootCAPool, err = ociscrypto.NewCertPoolFromPEM(rootCrtFile)
if err != nil {
return err
}
evtsCfg.TLSInsecure = false
}

tlsConf = &tls.Config{
RootCAs: rootCAPool,
}
}

bus, err := server.NewNatsStream(
natsjs.TLSConfig(tlsConf),
natsjs.Address(evtsCfg.Endpoint),
natsjs.ClusterID(evtsCfg.Cluster),
)
if err != nil {
return err
}

svc, err := service.NewPostprocessingService(bus, logger, cfg.Postprocessing)
if err != nil {
return err
}
return svc.Run()
},
}
}
19 changes: 19 additions & 0 deletions services/postprocessing/pkg/command/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package command

import (
"github.com/owncloud/ocis/v2/services/postprocessing/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 extension instances",
Category: "info",
Action: func(c *cli.Context) error {
// not implemented
return nil
},
}
}
Loading

0 comments on commit 341cdc9

Please sign in to comment.