Skip to content

Commit

Permalink
Remove hooks scripts (#4191)
Browse files Browse the repository at this point in the history
They were not used, and removing them can make the code a bit cleaner.
  • Loading branch information
nono authored Oct 25, 2023
2 parents cdb7ad8 + 83a343c commit 90fb9a1
Show file tree
Hide file tree
Showing 14 changed files with 15 additions and 290 deletions.
3 changes: 0 additions & 3 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,6 @@ func init() {
flags.StringSlice("flagship-apple-app-ids", []string{"3AKXFMV43J.io.cozy.drive.mobile", "3AKXFMV43J.io.cozy.flagship.mobile"}, "App ID of the flagship app on iOS")
checkNoErr(viper.BindPFlag("flagship.apple_app_ids", flags.Lookup("flagship-apple-app-ids")))

flags.String("hooks", ".", "define the directory used for hook scripts")
checkNoErr(viper.BindPFlag("hooks", flags.Lookup("hooks")))

flags.String("geodb", ".", "define the location of the database for IP -> City lookups")
checkNoErr(viper.BindPFlag("geodb", flags.Lookup("geodb")))

Expand Down
3 changes: 0 additions & 3 deletions cozy.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,6 @@ mail:
username: {{.Env.COZY_BETA_MAIL_USERNAME}}
password: {{.Env.COZY_BETA_MAIL_PASSWORD}}

# directory with the hooks scripts - flags: --hooks
hooks: ./scripts/hooks

# location of the database for IP -> City lookups - flags: --geodb
# See https://dev.maxmind.com/geoip/geoip2/geolite2/
geodb: ""
Expand Down
60 changes: 0 additions & 60 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,66 +147,6 @@ couchdb:
2. each instance document will keep the list index of the CouchDB cluster used
for its databases, so don't remove a cluster in the middle of the list!
## Hooks
Cozy-stack can run scripts on some events to customize it. The scripts must be
in the hooks directory defined in the config, have a predefined name, and be
executable. Then, they should be fired automatically. Let's the available hooks.
The `pre-add-instance` hook is run just before creating an instance. It can
prevent the command from running by exiting with non-zero status. It can be used
to check the domain for example. It is called with the following parameter:

1. the domain of the instance that will be created.

The `post-add-instance` hook is run just after an instance has been created.
installed. It can be used to setup DNS for this instance for example. It is
called with the following parameter:

1. the domain of the instance that has been created.

The `pre-remove-instance` hook is run just before destroying an instance. It can
prevent the command from running by exiting with non-zero status. It can be used
to make a backup of the instance before destroying it. It is called with the
following parameter:

1. the domain of the instance that will be destroyed.

The `post-remove-instance` hook is run just after an instance has been
destroyed. It can be used to do some cleanup. It is called with the following
parameter:

1. the domain of the instance that has been destroyed.

The `pre-install-app` hook is run just before installing an application, and can
prevent the command from running by exiting with non-zero status. It is called
with the following parameters:

1. the instance on which the application will be installed
2. the application name that will be installed.

The `post-install-app` hook is run just after an application has been installed.
It can be used for logging, notification, statistics, etc. It's also a good
place to add a vhost for an application in the reverse-proxy configuration, with
a TLS certificate. It is called with the following parameters:

1. the instance on which the application has been installed
2. the application name that has been installed.

The `pre-uninstall-app` hook is run just before uninstalling an application, and
can prevent the command from running by exiting with non-zero status. It is
called with the following parameters:

1. the instance on which the application will be uninstalled
2. the application name that will be uninstalled.

The `post-uninstall-app` hook is run just after an application has been
uninstalled. It can be used for cleaning the configuration of the reverse- proxy
for example. It is called with the following parameters:

1. the instance on which the application has been uninstalled
2. the application name that has been uninstalled.

## OnlyOffice
An integration between Cozy and OnlyOffice has been made. It allows the
Expand Down
37 changes: 15 additions & 22 deletions model/app/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/cozy/cozy-stack/pkg/config/config"
"github.com/cozy/cozy-stack/pkg/consts"
"github.com/cozy/cozy-stack/pkg/couchdb"
"github.com/cozy/cozy-stack/pkg/hooks"
"github.com/cozy/cozy-stack/pkg/logger"
"github.com/cozy/cozy-stack/pkg/prefixer"
"github.com/cozy/cozy-stack/pkg/realtime"
Expand Down Expand Up @@ -309,23 +308,20 @@ func (i *Installer) run() (err error) {
// Note that the fetched manifest is returned even if an error occurred while
// upgrading.
func (i *Installer) install() error {
args := []string{i.db.DomainName(), i.slug}
return hooks.Execute("install-app", args, func() error {
newManifest, err := i.ReadManifest(Installing)
if err != nil {
i.log.Debugf("Could not read manifest")
return err
}
i.man = newManifest
i.sendRealtimeEvent()
i.notifyChannel()
if err := i.fetcher.Fetch(i.src, i.fs, i.man); err != nil {
i.log.Debugf("Could not fetch tarball")
return err
}
i.man.SetState(i.endState)
return i.man.Create(i.db)
})
newManifest, err := i.ReadManifest(Installing)
if err != nil {
i.log.Debugf("Could not read manifest")
return err
}
i.man = newManifest
i.sendRealtimeEvent()
i.notifyChannel()
if err := i.fetcher.Fetch(i.src, i.fs, i.man); err != nil {
i.log.Debugf("Could not fetch tarball")
return err
}
i.man.SetState(i.endState)
return i.man.Create(i.db)
}

// checkSkipPermissions checks if the instance contexts is configured to skip
Expand Down Expand Up @@ -535,10 +531,7 @@ func (i *Installer) delete() error {
if err := i.checkState(i.man); err != nil {
return err
}
args := []string{i.db.DomainName(), i.slug}
return hooks.Execute("uninstall-app", args, func() error {
return i.man.Delete(i.db)
})
return i.man.Delete(i.db)
}

// checkState returns whether or not the manifest is in the right state to
Expand Down
17 changes: 0 additions & 17 deletions model/instance/lifecycle/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/cozy/cozy-stack/pkg/consts"
"github.com/cozy/cozy-stack/pkg/couchdb"
"github.com/cozy/cozy-stack/pkg/crypto"
"github.com/cozy/cozy-stack/pkg/hooks"
"github.com/cozy/cozy-stack/pkg/logger"
"github.com/cozy/cozy-stack/pkg/prefixer"
"github.com/cozy/cozy-stack/pkg/utils"
Expand Down Expand Up @@ -74,22 +73,6 @@ func (opts *Options) trace(name string, do func()) {

// Create builds an instance and initializes it
func Create(opts *Options) (*instance.Instance, error) {
domain, err := validateDomain(opts.Domain)
if err != nil {
return nil, err
}
var inst *instance.Instance
err = hooks.Execute("add-instance", []string{domain}, func() error {
var err2 error
inst, err2 = CreateWithoutHooks(opts)
return err2
})
return inst, err
}

// CreateWithoutHooks builds an instance and initializes it. The difference
// with Create is that script hooks are not executed for this function.
func CreateWithoutHooks(opts *Options) (*instance.Instance, error) {
domain := opts.Domain
var err error
opts.trace("validate domain", func() {
Expand Down
9 changes: 0 additions & 9 deletions model/instance/lifecycle/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/cozy/cozy-stack/pkg/config/config"
"github.com/cozy/cozy-stack/pkg/consts"
"github.com/cozy/cozy-stack/pkg/couchdb"
"github.com/cozy/cozy-stack/pkg/hooks"
"github.com/cozy/cozy-stack/pkg/logger"
"github.com/cozy/cozy-stack/pkg/mail"
"github.com/labstack/echo/v4"
Expand Down Expand Up @@ -56,14 +55,6 @@ func Destroy(domain string) error {
if err != nil {
return err
}
return hooks.Execute("remove-instance", []string{domain}, func() error {
return destroyWithoutHooks(domain)
})
}

// destroyWithoutHooks is used to remove the instance. The difference with
// Destroy is that scripts hooks are not executed for this function.
func destroyWithoutHooks(domain string) error {
inst, err := instance.GetFromCouch(domain)
if err != nil {
return err
Expand Down
2 changes: 0 additions & 2 deletions pkg/config/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ type Config struct {
NoReplyAddr string
NoReplyName string
ReplyTo string
Hooks string
GeoDB string
PasswordResetInterval time.Duration

Expand Down Expand Up @@ -761,7 +760,6 @@ func UseViper(v *viper.Viper) error {
NoReplyAddr: v.GetString("mail.noreply_address"),
NoReplyName: v.GetString("mail.noreply_name"),
ReplyTo: v.GetString("mail.reply_to"),
Hooks: v.GetString("hooks"),
GeoDB: v.GetString("geodb"),
PasswordResetInterval: v.GetDuration("password_reset_interval"),

Expand Down
54 changes: 0 additions & 54 deletions pkg/hooks/hooks.go

This file was deleted.

80 changes: 0 additions & 80 deletions pkg/hooks/hooks_test.go

This file was deleted.

3 changes: 0 additions & 3 deletions pkg/hooks/testdata/post-success

This file was deleted.

2 changes: 0 additions & 2 deletions pkg/hooks/testdata/pre-failure

This file was deleted.

3 changes: 0 additions & 3 deletions pkg/hooks/testdata/pre-success

This file was deleted.

17 changes: 0 additions & 17 deletions scripts/hooks/post-install-app.sample

This file was deleted.

15 changes: 0 additions & 15 deletions scripts/hooks/pre-install-app.sample

This file was deleted.

0 comments on commit 90fb9a1

Please sign in to comment.